Skip to content

Commit

Permalink
Make sure that options merging occurs in all possible cases.
Browse files Browse the repository at this point in the history
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
blambeau committed Jun 14, 2012
1 parent 1df6fe6 commit 9e4f785
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/sinatra/base.rb
Expand Up @@ -672,10 +672,13 @@ def find_view_engine(view, greedy)
if Symbol===view if Symbol===view
raise NotImplementedError raise NotImplementedError
else else
engine = Tilt[extract_path(view)] path = extract_path(view)
engine = Tilt[path]
raise "Template engine not found: #{view}" if engine.nil? 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 end
engine
end end


# Infers the location of `view` location as a `[path, line]` pair. `view` is # Infers the location of `view` location as a `[path, line]` pair. `view` is
Expand Down
27 changes: 25 additions & 2 deletions test/templates_test.rb
Expand Up @@ -7,8 +7,13 @@ def prepare
end end


def evaluate(scope, locals={}, &block) def evaluate(scope, locals={}, &block)
inner = block ? block.call : '' inner = block ? block.call : ''
data + inner result = data + inner
if p = options[:enclose]
p = p.upcase if options[:upcase]
result = "<#{p}>#{result}</#{p}>"
end
result
end end


Tilt.register 'test', self Tilt.register 'test', self
Expand Down Expand Up @@ -76,6 +81,24 @@ def with_hello_paths
end end
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 it 'uses the default layout template if not explicitly overridden' do
with_default_layout do with_default_layout do
render_app { render(:test, :hello) } render_app { render(:test, :hello) }
Expand Down

0 comments on commit 9e4f785

Please sign in to comment.