Permalink
Browse files

allow engine specific layout to be true, too

  • Loading branch information...
1 parent 2847673 commit 1e0a6472717f6ee5054ddd1e67d1af41b4f80c91 @rkh rkh committed Sep 13, 2012
Showing with 23 additions and 5 deletions.
  1. +8 −5 lib/sinatra/base.rb
  2. +15 −0 test/templates_test.rb
View
13 lib/sinatra/base.rb
@@ -679,21 +679,24 @@ def render_ruby(engine, template, options={}, locals={}, &block)
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
15 test/templates_test.rb
@@ -49,6 +49,21 @@ def with_default_layout
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?

0 comments on commit 1e0a647

Please sign in to comment.