Permalink
Browse files

Attempt to use the default layout if :layout=>true is given to render()

A test to ensure the behaviour is provided.
  • Loading branch information...
1 parent 55f54a0 commit 9b3b79a1ce831e86adc43413d4eea15de628976f @dcu dcu committed Aug 19, 2012
Showing with 9 additions and 2 deletions.
  1. +2 −2 padrino-core/lib/padrino-core/application/rendering.rb
  2. +7 −0 padrino-core/test/test_rendering.rb
@@ -175,10 +175,10 @@ def render(engine, data=nil, options={}, locals={}, &block)
root = settings.respond_to?(:root) ? settings.root : ""
# Use @layout if it exists
- options[:layout] = @layout if options[:layout].nil?
+ options[:layout] = @layout if options[:layout].nil? || options[:layout] == true
# Resolve layouts similar to in Rails
- if (options[:layout].nil? || options[:layout] == true) && !settings.templates.has_key?(:layout)
+ if options[:layout].nil? && !settings.templates.has_key?(:layout)
layout_path, layout_engine = *resolved_layout
options[:layout] = layout_path || false # We need to force layout false so sinatra don't try to render it
options[:layout] = false unless layout_engine == engine # TODO allow different layout engine
@@ -137,6 +137,7 @@ def teardown
should 'use correct layout with each controller' do
create_layout :foo, "foo layout at <%= yield %>"
create_layout :bar, "bar layout at <%= yield %>"
+ create_layout :baz, "baz layout at <%= yield %>"
create_layout :application, "default layout at <%= yield %>"
mock_app do
get("/"){ render :erb, "application" }
@@ -148,6 +149,10 @@ def teardown
layout :bar
get("/"){ render :erb, "bar" }
end
+ controller :baz do
+ layout :baz
+ get("/"){ render :erb, "baz", :layout => true }
+ end
controller :none do
get("/") { render :erb, "none" }
get("/with_foo_layout") { render :erb, "none with layout", :layout => :foo }
@@ -157,6 +162,8 @@ def teardown
assert_equal "foo layout at foo", body
get "/bar"
assert_equal "bar layout at bar", body
+ get "/baz"
+ assert_equal "baz layout at baz", body
get "/none"
assert_equal "default layout at none", body
get "/none/with_foo_layout"

0 comments on commit 9b3b79a

Please sign in to comment.