class Tilt::MustacheTemplate
view.
instance variables are copied from the scope object to the Mustache
When a scope argument is provided to MustacheTemplate#render, the
Mustache is written and maintained by Chris Wanstrath. See:
def compile!
def compile! Mustache.view_namespace = options[:namespace] Mustache.view_path = options[:view_path] || options[:mustaches] @engine = options[:view] || Mustache.view_class(name) options.each do |key, value| next if %w[view view_path namespace mustaches].include?(key.to_s) @engine.send("#{key}=", value) if @engine.respond_to? "#{key}=" end end
def evaluate(scope=nil, locals={}, &block)
def evaluate(scope=nil, locals={}, &block) instance = @engine.new # copy instance variables from scope to the view scope.instance_variables.each do |name| instance.instance_variable_set(name, scope.instance_variable_get(name)) end # locals get added to the view's context locals.each do |local, value| instance[local] = value end # if we're passed 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 unless instance.compiled? instance.to_html end
def initialize_engine
def initialize_engine require_template_library 'mustache' unless defined? ::Mustache end