Class | Tilt::MustacheTemplate |
In: |
lib/sinatra/tilt.rb
|
Parent: | Template |
Mustache is written and maintained by Chris Wanstrath. See: github.com/defunkt/mustache
When a scope argument is provided to MustacheTemplate#render, the instance variables are copied from the scope object to the Mustache view.
engine | [R] |
# File lib/sinatra/tilt.rb, line 452 452: def compile! 453: Mustache.view_namespace = options[:namespace] 454: @engine = options[:view] || Mustache.view_class(name) 455: options.each do |key, value| 456: next if %w[view namespace mustaches].include?(key.to_s) 457: @engine.send("#{key}=", value) if @engine.respond_to? "#{key}=" 458: end 459: end
# File lib/sinatra/tilt.rb, line 461 461: def evaluate(scope=nil, locals={}, &block) 462: instance = @engine.new 463: 464: # copy instance variables from scope to the view 465: scope.instance_variables.each do |name| 466: instance.instance_variable_set(name, scope.instance_variable_get(name)) 467: end 468: 469: # locals get added to the view's context 470: locals.each do |local, value| 471: instance[local] = value 472: end 473: 474: # if we're passed a block it's a subview. Sticking it in yield 475: # lets us use {{yield}} in layout.html to render the actual page. 476: instance[:yield] = block.call if block 477: 478: instance.template = data unless instance.compiled? 479: 480: instance.to_html 481: end