diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 2dbca4ba13..a8cc43fae1 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -672,10 +672,13 @@ def find_view_engine(view, greedy)
if Symbol===view
raise NotImplementedError
else
- engine = Tilt[extract_path(view)]
+ path = extract_path(view)
+ engine = Tilt[path]
raise "Template engine not found: #{view}" if engine.nil?
- engine
+ ext = File.extname(path)[1..-1].to_sym
+ engine = ext if Tilt[ext] == engine
end
+ engine
end
# Infers the location of `view` location as a `[path, line]` pair. `view` is
diff --git a/test/templates_test.rb b/test/templates_test.rb
index c6c1a2082d..526f408d38 100644
--- a/test/templates_test.rb
+++ b/test/templates_test.rb
@@ -7,8 +7,13 @@ def prepare
end
def evaluate(scope, locals={}, &block)
- inner = block ? block.call : ''
- data + inner
+ inner = block ? block.call : ''
+ result = data + inner
+ if p = options[:enclose]
+ p = p.upcase if options[:upcase]
+ result = "<#{p}>#{result}#{p}>"
+ end
+ result
end
Tilt.register 'test', self
@@ -76,6 +81,24 @@ def with_hello_paths
end
end
+ it 'merges global options with local engine options' do
+ render_app(:test => {:enclose => "g"}) {
+ render(:test, "Hello World!\n", :upcase => true)
+ }
+ assert ok?
+ assert_equal "Hello World!\n", body
+ end
+
+ it 'merges global options with local options when an infered engine as well' do
+ with_hello_paths do |path|
+ render_app(:test => {:enclose => "g"}) {
+ render(path, :upcase => true)
+ }
+ assert ok?
+ assert_equal "Hello World!\n", body
+ end
+ end
+
it 'uses the default layout template if not explicitly overridden' do
with_default_layout do
render_app { render(:test, :hello) }