Merge pull request #4312 from jekyll/fix-layout-metadata

Merge pull request 4312
This commit is contained in:
Parker Moore 2016-01-04 13:05:00 -08:00
commit e097a15657
2 changed files with 25 additions and 3 deletions

View File

@ -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"

View File

@ -62,10 +62,14 @@ module Jekyll
# and the key matches a method in which case it raises a
# DropMutationException.
def []=(key, val)
if respond_to?("#{key}=")
public_send("#{key}=", val)
elsif respond_to? key
if self.class.mutable
@mutations[key] = val
elsif respond_to? key
else
raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
end
else
fallback_data[key] = val
end