Navigation Menu

Skip to content

Commit

Permalink
Templates: render should fall back to engine layout sinatra#563
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Sep 13, 2012
1 parent 18fc8f9 commit d8f1d8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sinatra/base.rb
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/templates_test.rb
Expand Up @@ -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?
Expand Down

0 comments on commit d8f1d8e

Please sign in to comment.