module Sinatra::Templates

def lookup_template(engine, template, views_dir, filename = nil, line = nil)

def lookup_template(engine, template, views_dir, filename = nil, line = nil)
  case template
  when Symbol
    if cached = self.class.templates[template]
      lookup_template(engine, cached[:template], views_dir, cached[:filename], cached[:line])
    else
      path = ::File.join(views_dir, "#{template}.#{engine}")
      [ ::File.read(path), path, 1 ]
    end
  when Proc
    filename, line = self.class.caller_locations.first if filename.nil?
    [ template.call, filename, line.to_i ]
  when String
    filename, line = self.class.caller_locations.first if filename.nil?
    [ template, filename, line.to_i ]
  else
    raise ArgumentError
  end
end