Skip to content

Commit

Permalink
raise an error if no template engine found for type passed
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Mar 4, 2010
1 parent 2723d7e commit d12ea0e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/sinatra/base.rb
Expand Up @@ -346,20 +346,23 @@ def render(engine, data, options={}, locals={}, &block)

def compile_template(engine, data, options, views)
@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)
Tilt[engine].new(path, line.to_i, options) { body }
template.new(path, line.to_i, options) { body }
else
path = ::File.join(views, "#{data}.#{engine}")
Tilt[engine].new(path, 1, options)
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
Tilt[engine].new(path, line.to_i, options, &body)
template.new(path, line.to_i, options, &body)
else
raise ArgumentError
end
Expand Down

0 comments on commit d12ea0e

Please sign in to comment.