Templates: render should fall back to engine layout sinatra/sinatra#563 #574

Merged
merged 1 commit into from Sep 13, 2012
View
@@ -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
@@ -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?