Class: Tilt::MustacheTemplate
Overview
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.
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Attributes inherited from Template
Instance Method Summary collapse
Methods inherited from Template
#basename, #eval_file, #initialize, #name, #render
Constructor Details
This class inherits a constructor from Tilt::Template
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
676 677 678 |
# File 'lib/frank/tilt.rb', line 676 def engine @engine end |
Instance Method Details
#evaluate(scope = nil, locals = {}, &block) ⇒ Object
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/frank/tilt.rb', line 693 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 |
#initialize_engine ⇒ Object
678 679 680 681 |
# File 'lib/frank/tilt.rb', line 678 def initialize_engine return if defined? ::Mustache require_template_library 'mustache' end |
#prepare ⇒ Object
683 684 685 686 687 688 689 690 691 |
# File 'lib/frank/tilt.rb', line 683 def prepare Mustache.view_namespace = [:namespace] Mustache.view_path = [:view_path] || [:mustaches] @engine = [:view] || Mustache.view_class(name) .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 |