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 path = ::File.join(views, "#{data}.#{engine}") Tilt.mappings.each do |ext, klass| break if found = File.exists?(path) next unless klass == template path = ::File.join(views, "#{data}.#{ext}") end throw :layout_missing if eat_errors and !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