module Sinatra::Templates

def compile_template(engine, data, options, views)

def compile_template(engine, data, options, views)
  eat_errors = options.delete :eat_errors
  template_cache.fetch engine, data, options do
    template = Tilt[engine]
    raise "Template engine not found: #{engine}" if template.nil?
    case
    when data.is_a?(Symbol)
      body, path, line = self.class.templates[data]
      if body
        body = body.call if body.respond_to?(:call)
        template.new(path, line.to_i, options) { body }
      else
        found = false
        Tilt.mappings.each do |ext, klass|
          next unless klass == template
          path = ::File.join(views, "#{data}.#{ext}")
          break if found = File.exists?(path)
        end
        throw :layout_missing if eat_errors and not found
        template.new(path, 1, options)
      end
    when data.is_a?(Proc) || data.is_a?(String)
      body = data.is_a?(String) ? Proc.new { data } : data
      path, line = self.class.caller_locations.first
      template.new(path, line.to_i, options, &body)
    else
      raise ArgumentError
    end
  end
end