Skip to content
This repository
Browse code

Templates: render should fall back to engine layout #563

  • Loading branch information...
commit d8f1d8e566effabeb91fd5eca849d1d765642c41 1 parent 18fc8f9
Zachary Scott authored September 13, 2012
3  lib/sinatra/base.rb
@@ -688,7 +688,8 @@ def render(engine, data, options={}, locals={}, &block)
688 688
       views           = options.delete(:views)  || settings.views || "./views"
689 689
       layout          = options.delete(:layout)
690 690
       eat_errors      = layout.nil?
691  
-      layout          = @default_layout if layout.nil? or layout == true
  691
+      engine_layout   = settings.send(engine)[:layout] if settings.respond_to?(engine)
  692
+      layout          = engine_layout || @default_layout if layout.nil? or layout == true
692 693
       content_type    = options.delete(:content_type)  || options.delete(:default_content_type)
693 694
       layout_engine   = options.delete(:layout_engine) || engine
694 695
       scope           = options.delete(:scope)         || self
15  test/templates_test.rb
@@ -34,6 +34,21 @@ def with_default_layout
34 34
     File.unlink(layout) rescue nil
35 35
   end
36 36
 
  37
+  it 'falls back to engine layout' do
  38
+    mock_app do
  39
+      template(:layout3) { 'Layout 3!<%= yield %>' }
  40
+      set :erb, :layout => :layout3
  41
+
  42
+      get('/') do
  43
+        erb('Hello World!', { :layout => true })
  44
+      end
  45
+    end
  46
+
  47
+    get '/'
  48
+    assert ok?
  49
+    assert_equal "Layout 3!Hello World!", body
  50
+  end
  51
+
37 52
   it 'renders String templates directly' do
38 53
     render_app { render(:test, 'Hello World') }
39 54
     assert ok?

0 notes on commit d8f1d8e

Please sign in to comment.
Something went wrong with that request. Please try again.