module Roda::RodaPlugins::ViewOptions::InstanceMethods

def _cached_template_method_key(template)

If using a view subdir, prefix the template key with the subdir.
Return nil if using custom view or layout options.
def _cached_template_method_key(template)
  return if @_view_options || @_layout_options
  if subdir = @_view_subdir
    template = [subdir, template]
  end
  super
end

def _cached_template_method_lookup(method_cache, template)

If using a view subdir, prefix the template key with the subdir.
Return nil if using custom view or layout options.
def _cached_template_method_lookup(method_cache, template)
  return if @_view_options || @_layout_options
  if subdir = @_view_subdir
    template = [subdir, template]
  end
  super
end

def append_view_subdir(v)

view subdirectory.
the view subdirectory to a subdirectory of the existing
If there has already been a view subdirectory set, this sets
been a view subdirectory set, this just sets it to the argument.
Append a view subdirectory to use. If there hasn't already
def append_view_subdir(v)
  if subdir = @_view_subdir
    set_view_subdir("#{subdir}/#{v}")
  else
    set_view_subdir(v)
  end
end

def parse_template_opts(template, opts)

and locals into the returned hash.
template isn't a layout template, merge the options
If view options or locals have been set and this
def parse_template_opts(template, opts)
  t_opts = super
  if !t_opts[:_is_layout] && (v_opts = @_view_options)
    t_opts.merge!(v_opts)
  end
  t_opts
end

def render_layout_opts

merge the options and locals into the returned hash.
If layout options or locals have been set,
def render_layout_opts
  opts = super
  if l_opts = @_layout_options
    opts.merge!(l_opts)
  end
  opts
end

def set_layout_options(opts)

Set branch/route options to use when rendering the layout
def set_layout_options(opts)
  if options = @_layout_options
    @_layout_options = options.merge!(opts)
  else
    @_layout_options = opts
  end
end

def set_view_options(opts)

Set branch/route options to use when rendering the view
def set_view_options(opts)
  if options = @_view_options
    @_view_options = options.merge!(opts)
  else
    @_view_options = opts
  end
end

def set_view_subdir(v)

to not use a view subdirectory.
Set the view subdirectory to use. This can be set to nil
def set_view_subdir(v)
  @_view_subdir = v
end

def template_name(opts)

contain a slash.
there is a view subdirectory and the template name does not
Override the template name to use the view subdirectory if the
def template_name(opts)
  name = super
  if (v = @_view_subdir) && name !~ /\//
    "#{v}/#{name}"
  else
    name
  end
end