Class: Stache::Mustache::Layout
- Defined in:
- lib/stache/mustache/layout.rb
Overview
This class is for providing layouts in a better way. Your page class should extend this class.
Instance Attribute Summary collapse
Attributes inherited from View
Instance Method Summary collapse
-
#render(data = template, ctx = {}) ⇒ Object
template here would be the pages’ template, not the layout.
Methods inherited from View
#context, #h, #helpers, helpers, #method_missing, #partial, #respond_to?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Stache::Mustache::View
Instance Attribute Details
#layout ⇒ Object
8 9 10 |
# File 'lib/stache/mustache/layout.rb', line 8 def layout @layout ||= :layout end |
Instance Method Details
#render(data = template, ctx = {}) ⇒ Object
template here would be the pages’ template, not the layout.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stache/mustache/layout.rb', line 13 def render(data = template, ctx = {}) # Store the current template, we'll need to stuff it inside the layout page_template = data # Grab the layout template, to render it at the end layout_template = partial(layout) # Render the page_template using this class's context # (which will be combined with the layout context) rendered_template = super(page_template, ctx) # stick that rendered template as :yield into the layout template # (which will be combined with the current context) if (!ctx.is_a?(::Mustache::Context)) rendered_template = super(layout_template, yield: rendered_template) end rendered_template end |