Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Templates: render should fall back to engine layout sinatra/sinatra#563 #574

Merged
merged 1 commit into from

2 participants

@zzak
Collaborator

No description provided.

@rkh rkh merged commit 2847673 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 13, 2012
  1. @zzak
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +2 −1  lib/sinatra/base.rb
  2. +15 −0 test/templates_test.rb
View
3  lib/sinatra/base.rb
@@ -688,7 +688,8 @@ def render(engine, data, options={}, locals={}, &block)
views = options.delete(:views) || settings.views || "./views"
layout = options.delete(:layout)
eat_errors = layout.nil?
- layout = @default_layout if layout.nil? or layout == true
+ engine_layout = settings.send(engine)[:layout] if settings.respond_to?(engine)
+ layout = engine_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
View
15 test/templates_test.rb
@@ -34,6 +34,21 @@ def with_default_layout
File.unlink(layout) rescue nil
end
+ it 'falls back to engine layout' do
+ mock_app do
+ template(:layout3) { 'Layout 3!<%= yield %>' }
+ set :erb, :layout => :layout3
+
+ get('/') do
+ erb('Hello World!', { :layout => true })
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_equal "Layout 3!Hello World!", body
+ end
+
it 'renders String templates directly' do
render_app { render(:test, 'Hello World') }
assert ok?
Something went wrong with that request. Please try again.