Make neste layout usage independed of the outer template's :layout value. Allows using partials in layouts.
This commit is contained in:
parent
796d62a487
commit
5d15ddf3a1
|
@ -471,7 +471,7 @@ module Sinatra
|
||||||
|
|
||||||
# compile and render template
|
# compile and render template
|
||||||
layout_was = @default_layout
|
layout_was = @default_layout
|
||||||
@default_layout = false if layout
|
@default_layout = false
|
||||||
template = compile_template(engine, data, options, views)
|
template = compile_template(engine, data, options, views)
|
||||||
output = template.render(self, locals, &block)
|
output = template.render(self, locals, &block)
|
||||||
@default_layout = layout_was
|
@default_layout = layout_was
|
||||||
|
|
|
@ -101,6 +101,15 @@ class TemplatesTest < Test::Unit::TestCase
|
||||||
assert_equal "<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>", body
|
assert_equal "<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>", body
|
||||||
end
|
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
|
it 'loads templates from source file' do
|
||||||
mock_app { enable :inline_templates }
|
mock_app { enable :inline_templates }
|
||||||
assert_equal "this is foo\n\n", @app.templates[:foo][0]
|
assert_equal "this is foo\n\n", @app.templates[:foo][0]
|
||||||
|
|
Loading…
Reference in New Issue