<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -243,6 +243,9 @@ module Sinatra
 
   private
     def render(engine, template, options={}) #:nodoc:
+      @renderdepth ||= 0
+      options[:layout] = (@renderdepth == 0) if options[:layout].nil?
+      @renderdepth += 1
       data   = lookup_template(engine, template, options)
       output = __send__(&quot;render_#{engine}&quot;, template, data, options)
       layout, data = lookup_layout(engine, options)
@@ -251,6 +254,8 @@ module Sinatra
       else
         output
       end
+    ensure
+      @renderdepth -= 1
     end
 
     def lookup_template(engine, template, options={})</diff>
      <filename>lib/sinatra/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -78,4 +78,19 @@ describe &quot;ERB Templates&quot; do
     assert ok?
     assert_equal '&lt;outer&gt;&lt;inner&gt;hi&lt;/inner&gt;&lt;/outer&gt;', body
   end
+
+  it &quot;defaults to no layout on nested render&quot; do
+    mock_app {
+      template(:inner) { &quot;&lt;inner&gt;&lt;%= 'hi' %&gt;&lt;/inner&gt;&quot; }
+      template(:outer) { &quot;&lt;outer&gt;&lt;%= erb :inner %&gt;&lt;/outer&gt;&quot; }
+      template(:layout) { &quot;&lt;html&gt;&lt;%= yield %&gt;&lt;/html&gt;&quot; }
+      get '/' do
+        erb :outer
+      end
+    }
+
+    get '/'
+    assert ok?
+    assert_equal '&lt;html&gt;&lt;outer&gt;&lt;inner&gt;hi&lt;/inner&gt;&lt;/outer&gt;&lt;/html&gt;', body
+  end
 end</diff>
      <filename>test/erb_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -65,4 +65,33 @@ describe &quot;HAML Templates&quot; do
     assert ok?
     assert_equal &quot;&lt;!DOCTYPE html&gt;\n&lt;h1&gt;Hello World&lt;/h1&gt;\n&quot;, body
   end
+
+  it &quot;can be used in a nested fashion for partials and whatnot&quot; do
+    mock_app {
+      template(:inner) { &quot;%inner hi&quot; }
+      template(:outer) { &quot;%outer= haml(:inner)&quot; }
+      get '/' do
+        haml :outer
+      end
+    }
+
+    get '/'
+    assert ok?
+    assert_equal &quot;&lt;outer&gt;&lt;inner&gt;hi&lt;/inner&gt;&lt;/outer&gt;\n&quot;, body
+  end
+
+  it &quot;defaults to no layout on nested render&quot; do
+    mock_app {
+      template(:inner) { &quot;%inner hi&quot; }
+      template(:outer) { &quot;%outer= haml(:inner)&quot; }
+      template(:layout) { &quot;%html= yield&quot; }
+      get '/' do
+        haml :outer
+      end
+    }
+
+    get '/'
+    assert ok?
+    assert_equal &quot;&lt;html&gt;&lt;outer&gt;&lt;inner&gt;hi&lt;/inner&gt;&lt;/outer&gt;&lt;/html&gt;\n&quot;, body
+  end
 end</diff>
      <filename>test/haml_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>271a421b983373dc083fb9eefd86c445fc92f27b</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </author>
  <url>http://github.com/rtomayko/sinatra/commit/a00c2b5a556a81bd5a02650b9f342a0113af8ed3</url>
  <id>a00c2b5a556a81bd5a02650b9f342a0113af8ed3</id>
  <committed-date>2009-03-11T10:31:57-07:00</committed-date>
  <authored-date>2009-03-11T10:31:57-07:00</authored-date>
  <message>Automatic partials [#181]</message>
  <tree>d7131f2aae05aea2625db14f7fa71e70f2a42ca3</tree>
  <committer>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </committer>
</commit>
