1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Merge pull request #628 from richo/bugs/falsy_layouts

Explicitly set falsy values for :template should not render a template
This commit is contained in:
Konstantin Haase 2013-02-25 04:27:55 -08:00
commit 2fc53acf88
2 changed files with 19 additions and 2 deletions

View file

@ -612,7 +612,7 @@ module Sinatra
#
# Possible options are:
# :content_type The content type to use, same arguments as content_type.
# :layout If set to false, no layout is rendered, otherwise
# :layout If set to something falsy, no layout is rendered, otherwise
# the specified layout is used (Ignored for `sass` and `less`)
# :layout_engine Engine to use for rendering the layout.
# :locals A hash with local variables that should be available
@ -746,13 +746,15 @@ module Sinatra
# extract generic options
locals = options.delete(:locals) || locals || {}
views = options.delete(:views) || settings.views || "./views"
layout = options.delete(:layout)
layout = options[:layout]
layout = false if layout.nil? && options.include?(:layout)
eat_errors = layout.nil?
layout = engine_options[:layout] if layout.nil? or layout == true
layout = @default_layout if layout.nil? or layout == true
content_type = options.delete(:content_type) || options.delete(:default_content_type)
layout_engine = options.delete(:layout_engine) || engine
scope = options.delete(:scope) || self
options.delete(:layout)
# set some defaults
options[:outvar] ||= '@_out_buf'

View file

@ -64,6 +64,21 @@ class TemplatesTest < Test::Unit::TestCase
assert_equal "Layout!!! Hello World!", body
end
it 'renders no layout if layout if falsy' do
mock_app do
template(:layout) { 'Layout!!! <%= yield %>' }
set :erb, :layout => true
get('/') do
erb('Hello World!', { :layout => nil })
end
end
get '/'
assert ok?
assert_equal "Hello World!", body
end
it 'renders String templates directly' do
render_app { render(:test, 'Hello World') }
assert ok?