Browse files

Merge pull request #574 from zzak/fallback_to_engine_layout

Templates: render should fall back to engine layout sinatra/sinatra#563
  • Loading branch information...
2 parents 49a4154 + d8f1d8e commit 2847673c453ba563c8d2bef31e50bfabed41d066 @rkh rkh committed Sep 13, 2012
Showing with 17 additions and 1 deletion.
  1. +2 −1 lib/sinatra/base.rb
  2. +15 −0 test/templates_test.rb
View
3 lib/sinatra/base.rb
@@ -688,7 +688,8 @@ def render(engine, data, options={}, locals={}, &block)
views = options.delete(:views) || settings.views || "./views"
layout = options.delete(:layout)
eat_errors = layout.nil?
- layout = @default_layout if layout.nil? or layout == true
+ engine_layout = settings.send(engine)[:layout] if settings.respond_to?(engine)
+ layout = engine_layout || @default_layout if layout.nil? or layout == true
content_type = options.delete(:content_type) || options.delete(:default_content_type)
layout_engine = options.delete(:layout_engine) || engine
scope = options.delete(:scope) || self
View
15 test/templates_test.rb
@@ -34,6 +34,21 @@ def with_default_layout
File.unlink(layout) rescue nil
end
+ it 'falls back to engine layout' do
+ mock_app do
+ template(:layout3) { 'Layout 3!<%= yield %>' }
+ set :erb, :layout => :layout3
+
+ get('/') do
+ erb('Hello World!', { :layout => true })
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_equal "Layout 3!Hello World!", body
+ end
+
it 'renders String templates directly' do
render_app { render(:test, 'Hello World') }
assert ok?

0 comments on commit 2847673

Please sign in to comment.