From f2d1e21f690d3e5f2a13633b5b8ebde833927da4 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Nov 2010 17:33:30 -0600 Subject: [PATCH] Make nested layout usage independed of the outer template's :layout value. Allows using partials in layouts. --- lib/sinatra/base.rb | 2 +- test/templates_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 2209db97da..0f4cacc634 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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 diff --git a/test/templates_test.rb b/test/templates_test.rb index 48f0ec65dc..f5729f36eb 100644 --- a/test/templates_test.rb +++ b/test/templates_test.rb @@ -101,6 +101,15 @@ def with_default_layout assert_equal "

String Layout!

\n

Hello From String

", 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]