Explicitly set falsy values for :template should not render a template

This commit is contained in:
richo 2013-02-02 22:49:54 +11:00
parent bac3f4f671
commit acf57eb6d1
2 changed files with 19 additions and 2 deletions

View File

@ -580,7 +580,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
@ -714,13 +714,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?