class Stache::Mustache::Layout

This class is for providing layouts in a better way. Your page class should extend this class.

Attributes

layout[W]

Public Instance Methods

layout() click to toggle source
# File lib/stache/mustache/layout.rb, line 8
def layout
  @layout ||= :layout
end
render(data = template, ctx = {}) click to toggle source

template here would be the pages' template, not the layout.

Calls superclass method
# 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