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 683 683: def evaluate(scope=nil, locals={}, &block) 684: instance = @engine.new 685: 686: # copy instance variables from scope to the view 687: scope.instance_variables.each do |name| 688: instance.instance_variable_set(name, scope.instance_variable_get(name)) 689: end 690: 691: # locals get added to the view's context 692: locals.each do |local, value| 693: instance[local] = value 694: end 695: 696: # if we're passed a block it's a subview. Sticking it in yield 697: # lets us use {{yield}} in layout.html to render the actual page. 698: instance[:yield] = block.call if block 699: 700: instance.template = data unless instance.compiled? 701: 702: instance.to_html 703: end
# File lib/sinatra/tilt.rb, line 668 668: def initialize_engine 669: return if defined? ::Mustache 670: require_template_library 'mustache' 671: end
# File lib/sinatra/tilt.rb, line 673 673: def prepare 674: Mustache.view_namespace = options[:namespace] 675: Mustache.view_path = options[:view_path] || options[:mustaches] 676: @engine = options[:view] || Mustache.view_class(name) 677: options.each do |key, value| 678: next if %w[view view_path namespace mustaches].include?(key.to_s) 679: @engine.send("#{key}=", value) if @engine.respond_to? "#{key}=" 680: end 681: end