module Mustache::Sinatra
def mustache(template, options={}, locals={})
def mustache(template, options={}, locals={}) render :mustache, template, options, locals end
def render_mustache(template, data, options, locals, &block)
This is called by Sinatra's `render` with the proper paths
def render_mustache(template, data, options, locals, &block) name = Mustache.classify(template.to_s) if defined?(Views) && Views.const_defined?(name) instance = Views.const_get(name).new else instance = Mustache.new end locals.each do |local, value| instance[local] = value end # If we're paseed a block it's a subview. Sticking it in yield # lets us use {{yield}} in layout.html to render the actual page. instance[:yield] = block.call if block instance.template = data instance.to_html end