module Roda::RodaPlugins::Render::InstanceMethods

def retrieve_template(opts)

Retrieve the Tilt::Template object for the given template and opts.
def retrieve_template(opts)
  cache = opts[:cache]
  if !opts[:cache_key] || cache == false
    found_template_opts = opts = find_template(opts)
  end
  cached_template(opts) do
    opts = found_template_opts || find_template(opts)
    render_opts = self.class.opts[:render]
    template_opts = render_opts[:template_opts]
    if engine_opts = render_opts[:engine_opts][opts[:engine]]
      template_opts = template_opts.merge(engine_opts)
    end
    if current_template_opts = opts[:template_opts]
      template_opts = template_opts.merge(current_template_opts)
    end
    define_compiled_method = COMPILED_METHOD_SUPPORT &&
       (method_cache_key = opts[:template_method_cache_key]) &&
       (method_cache = render_opts[:template_method_cache]) &&
       (method_cache[method_cache_key] != false) &&
       !opts[:inline]
    if render_opts[:check_template_mtime] && !opts[:template_block] && !cache
      template = TemplateMtimeWrapper.new(self.class, opts, template_opts)
      if define_compiled_method
        method_name = :"_roda_template_#{self.class.object_id}_#{method_cache_key}"
        method_cache[method_cache_key] = template.define_compiled_method(self.class, method_name)
      end
    else
      template = self.class.create_template(opts, template_opts)
      if define_compiled_method && cache != false
        begin
          unbound_method = Render.tilt_template_compiled_method(template, EMPTY_ARRAY, self.class)
        rescue ::NotImplementedError
          method_cache[method_cache_key] = false
        else
          method_name = :"_roda_template_#{self.class.object_id}_#{method_cache_key}"
          self.class::RodaCompiledTemplates.send(:define_method, method_name, unbound_method)
          self.class::RodaCompiledTemplates.send(:private, method_name)
          method_cache[method_cache_key] = method_name
        end
      end
    end
    template
  end
end