Skip to content
Browse files

Merge branch 'master' of github.com:padrino/padrino-framework

* 'master' of github.com:padrino/padrino-framework:
  Attempt to use the default layout if :layout=>true is given to render()
  • Loading branch information...
2 parents 6d3d7bd + 5491674 commit 06c665b2ac74efbfb927fb82b5b3feaed16a34d1 @DAddYE DAddYE committed Aug 20, 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
View
4 padrino-core/lib/padrino-core/application/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
View
7 padrino-core/test/test_rendering.rb
@@ -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 06c665b

Please sign in to comment.
Something went wrong with that request. Please try again.