Skip to content

Commit

Permalink
Merge pull request padrino#912 from dcu/resolve-layout
Browse files Browse the repository at this point in the history
Attempt to use the default layout if :layout=>true is given to render()
  • Loading branch information
DAddYE committed Aug 19, 2012
2 parents 712c6ee + 9b3b79a commit 5491674
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions padrino-core/lib/padrino-core/application/rendering.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions padrino-core/test/test_rendering.rb
Expand Up @@ -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" }
Expand All @@ -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 }
Expand All @@ -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"
Expand Down

0 comments on commit 5491674

Please sign in to comment.