make sure we check every alternative extension registered for a template engine, fixes #179.

This commit is contained in:
Konstantin Haase 2011-02-17 15:51:52 +01:00
parent 227c9df27c
commit 5467056237
3 changed files with 9 additions and 3 deletions

View File

@ -508,13 +508,12 @@ module Sinatra
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}")
break if found = File.exists?(path)
end
throw :layout_missing if eat_errors and !found
throw :layout_missing if eat_errors and not found
template.new(path, 1, options)
end
when data.is_a?(Proc) || data.is_a?(String)

View File

@ -223,6 +223,12 @@ class TemplatesTest < Test::Unit::TestCase
end
assert_equal "Hello <%= 'World' %>!", body
end
it "is possible to register another template" do
Tilt.register "html.erb", Tilt[:erb]
render_app { render :erb, :calc }
assert_equal '2', body
end
end
# __END__ : this is not the real end of the script.

1
test/views/calc.html.erb Normal file
View File

@ -0,0 +1 @@
<%= 1 + 1 %>