From a99adcafaa01fecd4f3bda1a781b538be720084c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 18 May 2016 09:48:09 -0700 Subject: [PATCH 1/3] Add failing test for layout bug (#4897) --- features/layout_data.feature | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/features/layout_data.feature b/features/layout_data.feature index 78998665..8f085777 100644 --- a/features/layout_data.feature +++ b/features/layout_data.feature @@ -35,3 +35,31 @@ Feature: Layout data When I run jekyll build Then the "_site/index.html" file should exist And I should see "page content\n foo: my custom data" in "_site/index.html" + + Scenario: Inherit custom layout data + Given I have a _layouts directory + And I have a "_layouts/default.html" file with content: + """ + {{ content }} foo: '{{ layout.foo }}' + """ + And I have a "_layouts/special.html" file with content: + """ + --- + layout: default + foo: my special data + --- + {{ content }} + """ + And I have a "_layouts/page.html" file with content: + """ + --- + layout: default + --- + {{ content }} + """ + And I have an "index.html" page with layout "special" that contains "page content" + And I have an "jekyll.html" page with layout "page" that contains "page content" + When I run jekyll build + Then the "_site/index.html" file should exist + And I should see "page content\n foo: 'my special data'" in "_site/index.html" + And I should see "page content\n foo: ''" in "_site/jekyll.html" From 8e939cd86e67b81ecc97108684928b4ca553dd4c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 18 May 2016 09:58:20 -0700 Subject: [PATCH 2/3] Add failing test for layout data inheritance bug (#4433) --- features/layout_data.feature | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/features/layout_data.feature b/features/layout_data.feature index 8f085777..c2af5b70 100644 --- a/features/layout_data.feature +++ b/features/layout_data.feature @@ -36,17 +36,21 @@ Feature: Layout data Then the "_site/index.html" file should exist And I should see "page content\n foo: my custom data" in "_site/index.html" - Scenario: Inherit custom layout data + Scenario: Inherit custom layout data and clear when not present Given I have a _layouts directory And I have a "_layouts/default.html" file with content: """ - {{ content }} foo: '{{ layout.foo }}' + --- + bar: i'm default + --- + {{ content }} foo: '{{ layout.foo }}' bar: '{{ layout.bar }}' """ And I have a "_layouts/special.html" file with content: """ --- layout: default foo: my special data + bar: im special --- {{ content }} """ @@ -54,6 +58,7 @@ Feature: Layout data """ --- layout: default + bar: im page --- {{ content }} """ @@ -61,5 +66,5 @@ Feature: Layout data And I have an "jekyll.html" page with layout "page" that contains "page content" When I run jekyll build Then the "_site/index.html" file should exist - And I should see "page content\n foo: 'my special data'" in "_site/index.html" - And I should see "page content\n foo: ''" in "_site/jekyll.html" + And I should see "page content\n foo: 'my special data' bar: 'im special'" in "_site/index.html" + And I should see "page content\n foo: '' bar: 'im page'" in "_site/jekyll.html" From db7cd6f61203b77d4b7e5e13d2c01e3afc5ed0b6 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 18 May 2016 09:58:48 -0700 Subject: [PATCH 3/3] Reset {{ layout }} between each render & merge layout data properly --- lib/jekyll/convertible.rb | 5 ++++- lib/jekyll/renderer.rb | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index a473b183..a5d35607 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -209,10 +209,13 @@ module Jekyll used = Set.new([layout]) + # Reset the payload layout data to ensure it starts fresh for each page. + payload["layout"] = nil + while layout Jekyll.logger.debug "Rendering Layout:", path payload["content"] = output - payload["layout"] = Utils.deep_merge_hashes(payload["layout"] || {}, layout.data) + payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {}) self.output = render_liquid(layout.content, payload, diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index f116cf60..f9eb94be 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -136,10 +136,13 @@ module Jekyll used = Set.new([layout]) + # Reset the payload layout data to ensure it starts fresh for each page. + payload["layout"] = nil + while layout payload['content'] = output payload['page'] = document.to_liquid - payload['layout'] = Utils.deep_merge_hashes(payload['layout'] || {}, layout.data) + payload['layout'] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {}) output = render_liquid( layout.content,