module Roda::RodaPlugins::Render

def self.configure(app, opts=OPTS)

Setup default rendering options. See Render for details.
def self.configure(app, opts=OPTS)
  if app.opts[:render]
    orig_cache = app.opts[:render][:cache]
    opts = app.opts[:render][:orig_opts].merge(opts)
  end
  app.opts[:render] = opts.dup
  app.opts[:render][:orig_opts] = opts
  opts = app.opts[:render]
  opts[:engine] = (opts[:engine] || "erb").dup.freeze
  opts[:views] = app.expand_path(opts[:views]||"views").freeze
  opts[:allowed_paths] ||= [opts[:views]].freeze
  opts[:allowed_paths] = opts[:allowed_paths].map{|f| app.expand_path(f, nil)}.uniq.freeze
  opts[:check_paths] = true unless opts.has_key?(:check_paths)
  unless opts.has_key?(:explicit_cache)
    opts[:explicit_cache] = if opts.fetch(:cache, true)
      ENV['RACK_ENV'] == 'development'
    else
      true
    end
  end
  opts[:cache] = orig_cache || (opts[:cache_class] || RodaCache).new
  opts[:layout_opts] = (opts[:layout_opts] || {}).dup
  opts[:layout_opts][:_is_layout] = true
  if opts[:layout_opts][:views]
    opts[:layout_opts][:views] = app.expand_path(opts[:layout_opts][:views]).freeze
  end
  if layout = opts.fetch(:layout, true)
    opts[:layout] = true unless opts.has_key?(:layout)
    case layout
    when Hash
      opts[:layout_opts].merge!(layout)
    when true
      opts[:layout_opts][:template] ||= 'layout'
    else
      opts[:layout_opts][:template] = layout
    end
  end
  opts[:layout_opts].freeze
  template_opts = opts[:template_opts] = (opts[:template_opts] || {}).dup
  template_opts[:outvar] ||= '@_out_buf'
  unless template_opts.has_key?(:default_encoding)
    template_opts[:default_encoding] = Encoding.default_external
  end
  if opts[:escape]
    require 'tilt/erubi'
    template_opts[:escape] = true
  end
  template_opts.freeze
  engine_opts = opts[:engine_opts] = (opts[:engine_opts] || {}).dup
  engine_opts.to_a.each do |k,v|
    engine_opts[k] = v.dup.freeze
  end
  engine_opts.freeze
  opts.freeze
end