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

allow engine specific layout to be true, too

This commit is contained in:
Konstantin Haase 2012-09-14 00:29:58 +02:00
parent 2847673c45
commit 1e0a647271
2 changed files with 23 additions and 5 deletions

View file

@ -679,21 +679,24 @@ module Sinatra
def render(engine, data, options={}, locals={}, &block)
# merge app-level options
options = settings.send(engine).merge(options) if settings.respond_to?(engine)
options[:outvar] ||= '@_out_buf'
options[:default_encoding] ||= settings.default_encoding
engine_options = settings.respond_to?(engine) ? settings.send(engine) : {}
options = engine_options.merge(options)
# extract generic options
locals = options.delete(:locals) || locals || {}
views = options.delete(:views) || settings.views || "./views"
layout = options.delete(:layout)
eat_errors = layout.nil?
engine_layout = settings.send(engine)[:layout] if settings.respond_to?(engine)
layout = engine_layout || @default_layout if layout.nil? or layout == true
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
# set some defaults
options[:outvar] ||= '@_out_buf'
options[:default_encoding] ||= settings.default_encoding
# compile and render template
begin
layout_was = @default_layout

View file

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