Skip to content

Commit

Permalink
Make nested layout usage independed of the outer template's :layout v…
Browse files Browse the repository at this point in the history
…alue. Allows using partials in layouts.
  • Loading branch information
rkh committed Dec 14, 2010
1 parent 9065bb4 commit f2d1e21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Expand Up @@ -467,7 +467,7 @@ def render(engine, data, options={}, locals={}, &block)

# compile and render template
layout_was = @default_layout
@default_layout = false if layout
@default_layout = false
template = compile_template(engine, data, options, views)
output = template.render(self, locals, &block)
@default_layout = layout_was
Expand Down
9 changes: 9 additions & 0 deletions test/templates_test.rb
Expand Up @@ -101,6 +101,15 @@ def with_default_layout
assert_equal "<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>", body
end

it 'is possible to use partials in layouts' do
render_app do
settings.layout { "<%= erb 'foo' %><%= yield %>" }
erb 'bar'
end
assert ok?
assert_equal "foobar", body
end

it 'loads templates from source file' do
mock_app { enable :inline_templates }
assert_equal "this is foo\n\n", @app.templates[:foo][0]
Expand Down

0 comments on commit f2d1e21

Please sign in to comment.