From 2ab294c6029b0e5cc783157c9f548e7c4dc01284 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 1 Jun 2012 20:05:07 -0700 Subject: [PATCH] Fix wrap_layout for all know templating engines. Fixes #417 --- .../core_extensions/rendering.rb | 24 +++++++++++++------ .../features/nested_layouts.feature | 13 +++++++++- .../source/another.html.markdown | 7 ++++++ .../source/haml-test.html.markdown | 7 ++++++ .../source/layouts/inner_haml.haml | 3 +++ .../source/layouts/inner_slim.slim | 3 +++ .../source/layouts/master_haml.haml | 3 +++ .../source/layouts/master_slim.slim | 3 +++ .../source/layouts/outer_haml.haml | 3 +++ .../source/layouts/outer_slim.slim | 3 +++ .../source/slim-test.html.markdown | 7 ++++++ 11 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 middleman-more/fixtures/nested-layout-app/source/another.html.markdown create mode 100644 middleman-more/fixtures/nested-layout-app/source/haml-test.html.markdown create mode 100644 middleman-more/fixtures/nested-layout-app/source/layouts/inner_haml.haml create mode 100644 middleman-more/fixtures/nested-layout-app/source/layouts/inner_slim.slim create mode 100644 middleman-more/fixtures/nested-layout-app/source/layouts/master_haml.haml create mode 100644 middleman-more/fixtures/nested-layout-app/source/layouts/master_slim.slim create mode 100644 middleman-more/fixtures/nested-layout-app/source/layouts/outer_haml.haml create mode 100644 middleman-more/fixtures/nested-layout-app/source/layouts/outer_slim.slim create mode 100644 middleman-more/fixtures/nested-layout-app/source/slim-test.html.markdown diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index fea8659f..14794718 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -329,19 +329,29 @@ module Middleman def wrap_layout(layout_name, &block) # Save current buffer for later @_out_buf, _buf_was = "", @_out_buf + begin - content = capture(&block) if block_given? + content = if block_given? + capture_html(&block) + else + "" + end ensure # Reset stored buffer @_out_buf = _buf_was end + layout_path = locate_layout(layout_name, current_engine) - - if !@_out_buf - raise "wrap_layout is currently broken for this templating system" - end - - @_out_buf.concat render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content } + + extension = File.extname(layout_path) + engine = extension[1..-1].to_sym + + # Store last engine for later (could be inside nested renders) + @current_engine, engine_was = engine, @current_engine + + concat_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content } + ensure + @current_engine = engine_was end # The currently rendering engine diff --git a/middleman-more/features/nested_layouts.feature b/middleman-more/features/nested_layouts.feature index 2267f23a..496b9dc1 100644 --- a/middleman-more/features/nested_layouts.feature +++ b/middleman-more/features/nested_layouts.feature @@ -13,13 +13,24 @@ Feature: Allow nesting of layouts And I should see "Inner" And I should see "Outer" And I should see "Master" - When I go to "/haml-test.html" + + Scenario: A page uses an inner layout when uses an outer layout (slim) + Given the Server is running at "nested-layout-app" + When I go to "/slim-test.html" And I should see "New Article Title" And I should see "The Article Content" And I should see "Inner" And I should see "Outer" And I should see "Master" + Scenario: A page uses an inner layout when uses an outer layout (haml) + Given the Server is running at "nested-layout-app" + When I go to "/haml-test.html" + And I should see "New Article Title" + And I should see "The Article Content" + And I should see "Inner" + And I should see "Outer" + And I should see "Master" Scenario: YAML Front Matter isn't clobbered with nested layouts Given the Server is running at "nested-layout-app" diff --git a/middleman-more/fixtures/nested-layout-app/source/another.html.markdown b/middleman-more/fixtures/nested-layout-app/source/another.html.markdown new file mode 100644 index 00000000..562ceae5 --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/another.html.markdown @@ -0,0 +1,7 @@ +--- +title: "New Article Title" +date: 2011-01-01 +layout: inner +--- + +The Article Content diff --git a/middleman-more/fixtures/nested-layout-app/source/haml-test.html.markdown b/middleman-more/fixtures/nested-layout-app/source/haml-test.html.markdown new file mode 100644 index 00000000..38a7bee8 --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/haml-test.html.markdown @@ -0,0 +1,7 @@ +--- +title: "New Article Title" +date: 2011-01-01 +layout: inner_haml +--- + +The Article Content diff --git a/middleman-more/fixtures/nested-layout-app/source/layouts/inner_haml.haml b/middleman-more/fixtures/nested-layout-app/source/layouts/inner_haml.haml new file mode 100644 index 00000000..e3976d7c --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/layouts/inner_haml.haml @@ -0,0 +1,3 @@ +- wrap_layout :outer_haml do + Inner + = yield \ No newline at end of file diff --git a/middleman-more/fixtures/nested-layout-app/source/layouts/inner_slim.slim b/middleman-more/fixtures/nested-layout-app/source/layouts/inner_slim.slim new file mode 100644 index 00000000..30f769b4 --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/layouts/inner_slim.slim @@ -0,0 +1,3 @@ +- wrap_layout :outer_slim do + Inner + = yield \ No newline at end of file diff --git a/middleman-more/fixtures/nested-layout-app/source/layouts/master_haml.haml b/middleman-more/fixtures/nested-layout-app/source/layouts/master_haml.haml new file mode 100644 index 00000000..bdc6ccc5 --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/layouts/master_haml.haml @@ -0,0 +1,3 @@ +Master += data.page.title += yield \ No newline at end of file diff --git a/middleman-more/fixtures/nested-layout-app/source/layouts/master_slim.slim b/middleman-more/fixtures/nested-layout-app/source/layouts/master_slim.slim new file mode 100644 index 00000000..bdc6ccc5 --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/layouts/master_slim.slim @@ -0,0 +1,3 @@ +Master += data.page.title += yield \ No newline at end of file diff --git a/middleman-more/fixtures/nested-layout-app/source/layouts/outer_haml.haml b/middleman-more/fixtures/nested-layout-app/source/layouts/outer_haml.haml new file mode 100644 index 00000000..641e42c5 --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/layouts/outer_haml.haml @@ -0,0 +1,3 @@ +- wrap_layout :master_haml do + Outer + = yield diff --git a/middleman-more/fixtures/nested-layout-app/source/layouts/outer_slim.slim b/middleman-more/fixtures/nested-layout-app/source/layouts/outer_slim.slim new file mode 100644 index 00000000..f0025db4 --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/layouts/outer_slim.slim @@ -0,0 +1,3 @@ +- wrap_layout :master_slim do + Outer + = yield diff --git a/middleman-more/fixtures/nested-layout-app/source/slim-test.html.markdown b/middleman-more/fixtures/nested-layout-app/source/slim-test.html.markdown new file mode 100644 index 00000000..ab06396b --- /dev/null +++ b/middleman-more/fixtures/nested-layout-app/source/slim-test.html.markdown @@ -0,0 +1,7 @@ +--- +title: "New Article Title" +date: 2011-01-01 +layout: inner_slim +--- + +The Article Content