Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make sure that options merging occurs in all possible cases.

There is an extra cost for infered engines, because we need two calls
to Tilt[] to guarantee that the global engine options will correctly be
found.
  • Loading branch information...
commit 9e4f7854298b5863175e5a0adc5c3d752783dfc4 1 parent 1df6fe6
@blambeau blambeau authored
Showing with 30 additions and 4 deletions.
  1. +5 −2 lib/sinatra/base.rb
  2. +25 −2 test/templates_test.rb
View
7 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
View
27 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 "<G>Hello World!\n</G>", 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 "<G>Hello World!\n</G>", body
+ end
+ end
+
it 'uses the default layout template if not explicitly overridden' do
with_default_layout do
render_app { render(:test, :hello) }
Please sign in to comment.
Something went wrong with that request. Please try again.