module Roda::RodaPlugins::RenderLocals::InstanceMethods

def _cached_template_method(template)

options will have no locals.
Disable use of cached templates, since it assumes a render/view call with no
def _cached_template_method(template)
  nil
end

def _optimized_view_content(template)

def _optimized_view_content(template)
  nil
end

def layout_locals

def layout_locals
  opts[:layout_locals]
end

def render_locals

def render_locals
  opts[:render_locals]
end

def render_template_opts(template, opts)

If this isn't the layout template, then use the plugin's render locals as the default locals.
def render_template_opts(template, opts)
  opts = super
  return opts if opts[:_is_layout]
  plugin_locals = render_locals
  if locals = opts[:locals]
    plugin_locals = Hash[plugin_locals].merge!(locals)
  end
  opts[:locals] = plugin_locals
  opts
end

def view_layout_opts(opts)

If using a layout, then use the plugin's layout locals as the default locals.
def view_layout_opts(opts)
  if layout_opts = super
    merge_locals = layout_opts.has_key?(:merge_locals) ? layout_opts[:merge_locals] : self.opts[:merge_locals] 
    locals = {}
    locals.merge!(layout_locals)
    if merge_locals && (method_locals = opts[:locals])
      locals.merge!(method_locals)
    end
    if method_layout_locals = layout_opts[:locals]
      locals.merge!(method_layout_locals)
    end
    layout_opts[:locals] = locals
    layout_opts
  end
end