Permalink
Browse files

[core] Fix layouts, Sinatra 1.4 interprets a nil layout as a false la…

…yout
  • Loading branch information...
nesquena committed Mar 11, 2013
1 parent 68e58b4 commit ba2cfcdeb1c4428cc19013d09ba05f1383455360
Showing with 9 additions and 7 deletions.
  1. +4 −2 padrino-core/lib/padrino-core/application/rendering.rb
  2. +5 −5 padrino-core/test/test_rendering.rb
@@ -179,7 +179,7 @@ def content_type(type=nil, params={})
# * Use render 'path/to/template', :layout => false, :engine => 'haml'
#
def render(engine, data=nil, options={}, locals={}, &block)
# If engine is nil, ignore engine parameter and shift up all arguments
# render nil, "index", { :layout => true }, { :localvar => "foo" }
engine, data, options = data, options, locals if engine.nil? && data
@@ -197,8 +197,8 @@ def render(engine, data=nil, options={}, locals={}, &block)
root = settings.respond_to?(:root) ? settings.root : ""
# Use @layout if it exists
layout_was = options[:layout]
options[:layout] = @layout if options[:layout].nil? || options[:layout] == true
# Resolve layouts similar to in Rails
if options[:layout].nil? && !settings.templates.has_key?(:layout)
layout_path, layout_engine = *resolved_layout
@@ -208,6 +208,8 @@ def render(engine, data=nil, options={}, locals={}, &block)
elsif options[:layout].present?
options[:layout] = settings.fetch_layout_path(options[:layout] || @layout)
end
# Default to original layout value if none found
options[:layout] ||= layout_was
# Cleanup the template
@current_engine, engine_was = engine, @current_engine
@@ -29,7 +29,7 @@ def teardown
"this is a <%= yield %>"
end
get("/"){ render :erb, "sinatra layout" }
get("/"){ render :erb, "sinatra layout", :layout => true }
end
get "/"
@@ -215,7 +215,7 @@ def teardown
create_view :index, "<%= foo %>"
mock_app do
enable :logging
get("/") { render "index", { :layout => true }, { :foo => "bar" } }
get("/") { render "index", { :layout => nil }, { :foo => "bar" } }
end
get "/"
assert_equal "bar", body
@@ -475,7 +475,7 @@ def is; "IS."; end
render :erb, '<p><%= %q{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>} %></p>', :layout => false
end
get '/with_layout' do
render :erb, '<span>span</span>'
render :erb, '<span>span</span>', :layout => true
end
end
get '/'
@@ -496,7 +496,7 @@ def is; "IS."; end
render :haml, '%p= %s{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>}', :layout => false
end
get '/with_layout' do
render :haml, "%div\n foo"
render :haml, "%div\n foo", :layout => true
end
end
get '/'
@@ -517,7 +517,7 @@ def is; "IS."; end
render :slim, 'p = %q{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>}', :layout => false
end
get "/with_layout" do
render :slim, 'div foo'
render :slim, 'div foo', :layout => true
end
end
get '/'

0 comments on commit ba2cfcd

Please sign in to comment.