From 06c45df8c3181fa2967dcc7952939e90b11af23a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 4 Jan 2016 12:09:19 -0800 Subject: [PATCH 1/3] Drop: hash syntax should use setter method for a property if it's defined --- lib/jekyll/drops/drop.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/drops/drop.rb b/lib/jekyll/drops/drop.rb index c194a5ba..af249996 100644 --- a/lib/jekyll/drops/drop.rb +++ b/lib/jekyll/drops/drop.rb @@ -62,7 +62,9 @@ module Jekyll # and the key matches a method in which case it raises a # DropMutationException. def []=(key, val) - if self.class.mutable + if respond_to?("#{key}=") + public_send("#{key}=", val) + elsif self.class.mutable @mutations[key] = val elsif respond_to? key raise Errors::DropMutationException, "Key #{key} cannot be set in the drop." From 62d7f5ecade234b07fe51fda22ed4ffd1e391bcc Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 4 Jan 2016 12:10:05 -0800 Subject: [PATCH 2/3] Add feature test for layout data Fixes issue defined here: https://github.com/jekyll/jekyll/issues/4246#issuecomment-168367510 --- features/layout_data.feature | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 features/layout_data.feature diff --git a/features/layout_data.feature b/features/layout_data.feature new file mode 100644 index 00000000..a06502c8 --- /dev/null +++ b/features/layout_data.feature @@ -0,0 +1,18 @@ +Feature: Layout data + As a hacker who likes to avoid repetition + I want to be able to embed data into my layouts + In order to make the layouts slightly dynamic + + Scenario: Use custom layout data + Given I have a _layouts directory + And I have a "_layouts/custom.html" file with content: + """ + --- + foo: my custom data + --- + {{ content }} foo: {{ layout.foo }} + """ + And I have an "index.html" page with layout "custom" 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 custom data" in "_site/index.html" From 95a3c54ddb374a757cec468caed3d413dd2ea9e9 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 4 Jan 2016 12:41:40 -0800 Subject: [PATCH 3/3] drop: only check mutable if the key is a method --- lib/jekyll/drops/drop.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/drops/drop.rb b/lib/jekyll/drops/drop.rb index af249996..b4a07fc7 100644 --- a/lib/jekyll/drops/drop.rb +++ b/lib/jekyll/drops/drop.rb @@ -64,10 +64,12 @@ module Jekyll def []=(key, val) if respond_to?("#{key}=") public_send("#{key}=", val) - elsif self.class.mutable - @mutations[key] = val elsif respond_to? key - raise Errors::DropMutationException, "Key #{key} cannot be set in the drop." + if self.class.mutable + @mutations[key] = val + else + raise Errors::DropMutationException, "Key #{key} cannot be set in the drop." + end else fallback_data[key] = val end