module Roda::RodaPlugins::Render
def self.configure(app, opts=OPTS)
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] || opts[:ext] || "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 if opts.fetch(:cache, true) if orig_cache opts[:cache] = orig_cache elsif cache_class = opts[:cache_class] opts[:cache] = cache_class.new else opts[:cache] = app.thread_safe_cache end end opts[:explicit_cache] = ENV['RACK_ENV'] == 'development' unless opts.has_key?(:explicit_cache) opts[:layout_opts] = (opts[:layout_opts] || {}).dup opts[:layout_opts][:_is_layout] = true if opts[:layout_opts][:merge_locals] && opts[:locals] opts[:layout_opts][:locals] = opts[:locals].merge(opts[:layout_opts][:locals] || {}) 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' if RUBY_VERSION >= "1.9" && !template_opts.has_key?(:default_encoding) template_opts[:default_encoding] = Encoding.default_external end if opts[:escape] == :erubi require 'tilt/erubi' template_opts[:escape] = true elsif opts[:escape] template_opts[:engine_class] = ErubisEscaping::Eruby opts[:escaper] ||= if opts[:escape_safe_classes] ErubisEscaping::UnsafeClassEscaper.new(opts[:escape_safe_classes]) else ::Erubis::XmlHelper end 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
def self.load_dependencies(app, opts=OPTS)
def self.load_dependencies(app, opts=OPTS) if opts[:escape] && opts[:escape] != :erubi app.plugin :_erubis_escaping end end