Skip to content

Commit

Permalink
save and restore layout setting, fixes #1796
Browse files Browse the repository at this point in the history
  • Loading branch information
ujifgc committed Oct 11, 2015
1 parent 4496bca commit eec1d4a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -26,6 +26,7 @@ group :development do
gem "fakeweb", ">= 1.2.8"
gem "webrat", ">= 0.5.1"
gem "haml", ">= 4.0.5"
gem "liquid", ">= 2.1.2"
if ENV['STDLIB_ERB']
puts "=> Using stdlib ERB engine"
else
Expand Down
2 changes: 1 addition & 1 deletion padrino-core/lib/padrino-core/application/routing.rb
Expand Up @@ -407,7 +407,7 @@ def with_new_options(*args)
replace_instance_variable(:@_controller, args)
replace_instance_variable(:@_defaults, options)
replace_instance_variable(:@filters, :before => @filters[:before].dup, :after => @filters[:after].dup)
replace_instance_variable(:@layout, nil)
replace_instance_variable(:@layout, @layout)

yield

Expand Down
2 changes: 1 addition & 1 deletion padrino-helpers/lib/padrino/rendering.rb
Expand Up @@ -202,7 +202,7 @@ def render(engine, data=nil, options={}, locals={}, &block)
# This means that no engine was explicitly defined
data, engine = resolve_template(engine, options) if data.nil?

ensure_rendering_engine(engine) || (options[:layout] ||= false)
ensure_rendering_engine(engine) || (options[:layout] ||= @layout || false)

# Cleanup the template.
@current_engine, engine_was = engine, @current_engine
Expand Down
2 changes: 1 addition & 1 deletion padrino-helpers/test/helper.rb
Expand Up @@ -44,7 +44,7 @@ def create_template(name, content, options={})
path = "/views/#{name}"
path += ".#{options.delete(:locale)}" if options[:locale].present?
path += ".#{options[:format]}" if options[:format].present?
path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom|builder/
path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom|builder|liquid/
path += ".builder" if options[:format].to_s =~ /rss|atom/
file = File.dirname(__FILE__) + path
File.open(file, 'w') { |io| io.write content }
Expand Down
21 changes: 21 additions & 0 deletions padrino-helpers/test/test_rendering.rb
@@ -1,5 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/helper')
require 'slim'
require 'liquid'

describe "Rendering" do
def setup
Expand Down Expand Up @@ -87,6 +88,26 @@ def teardown
assert_equal "js file", body
end

it 'should set and restore layout in controllers' do
create_layout :boo, "boo is a <%= yield %>"
create_layout :moo, "moo is a <%= yield %>"
create_view :foo, "liquid file", :format => :liquid
mock_app do
layout :boo
controller :moo do
layout :moo
get('/liquid') { render :foo }
end
controller :boo do
get('/liquid') { render :foo }
end
end
get "/moo/liquid"
assert_equal "moo is a liquid file", body
get "/boo/liquid"
assert_equal "boo is a liquid file", body
end

it 'should use correct layout for each format' do
create_layout :application, "this is an <%= yield %>"
create_layout :application, "document start <%= yield %> end", :format => :xml
Expand Down

0 comments on commit eec1d4a

Please sign in to comment.