-
-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support data sources #1003
support data sources #1003
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Feature: Data | ||
In order to use well-formatted data in my blog | ||
As a blog's user | ||
I want to use _data directory in my site | ||
|
||
Scenario: autoload *.yaml files in _data directory | ||
Given I have a _data directory | ||
And I have a "_data/products.yaml" file with content: | ||
""" | ||
- name: sugar | ||
price: 5.3 | ||
- name: salt | ||
price: 2.5 | ||
""" | ||
And I have an "index.html" page that contains "{% for product in site.data.products %}{{product.name}}{% endfor %}" | ||
When I run jekyll | ||
Then the "_site/index.html" file should exist | ||
And I should see "sugar" in "_site/index.html" | ||
And I should see "salt" in "_site/index.html" | ||
|
||
Scenario: autoload *.yml files in _data directory | ||
Given I have a _data directory | ||
And I have a "_data/members.yml" file with content: | ||
""" | ||
- name: Jack | ||
age: 28 | ||
- name: Leon | ||
age: 34 | ||
""" | ||
And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}" | ||
When I run jekyll | ||
Then the "_site/index.html" file should exist | ||
And I should see "Jack" in "_site/index.html" | ||
And I should see "Leon" in "_site/index.html" | ||
|
||
Scenario: autoload *.yml files in _data directory with space in file name | ||
Given I have a _data directory | ||
And I have a "_data/team members.yml" file with content: | ||
""" | ||
- name: Jack | ||
age: 28 | ||
- name: Leon | ||
age: 34 | ||
""" | ||
And I have an "index.html" page that contains "{% for member in site.data.team_members %}{{member.name}}{% endfor %}" | ||
When I run jekyll | ||
Then the "_site/index.html" file should exist | ||
And I should see "Jack" in "_site/index.html" | ||
And I should see "Leon" in "_site/index.html" | ||
|
||
Scenario: should be backward compatible with site.data in _config.yml | ||
Given I have a "_config.yml" file with content: | ||
""" | ||
data: | ||
- name: Jack | ||
age: 28 | ||
- name: Leon | ||
age: 34 | ||
""" | ||
And I have an "index.html" page that contains "{% for member in site.data %}{{member.name}}{% endfor %}" | ||
When I run jekyll | ||
Then the "_site/index.html" file should exist | ||
And I should see "Jack" in "_site/index.html" | ||
And I should see "Leon" in "_site/index.html" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ A basic Jekyll site usually looks something like this: | |
├── _posts | ||
| ├── 2007-10-29-why-every-programmer-should-play-nethack.textile | ||
| └── 2009-04-26-barcamp-boston-4-roundup.textile | ||
├── _data | ||
| └── members.yml | ||
├── _site | ||
└── index.html | ||
{% endhighlight %} | ||
|
@@ -121,6 +123,21 @@ An overview of what each of these does: | |
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<p><code>_data</code></p> | ||
</td> | ||
<td> | ||
<p> | ||
|
||
Well-formatted site data should be placed here. The jekyll engine will | ||
autoload all yaml files (ends with <code>.yml</code> or <code>.yaml</code>) | ||
in this directory. If there's a file <code>members.yml</code> under the directory, | ||
then you can access contents of the file through <code>site.data.members</code>. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plese change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve seen |
||
|
||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<p><code>_site</code></p> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- java | ||
- ruby |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- name: Jack | ||
age: 27 | ||
blog: http://example.com/jack | ||
|
||
- name: John | ||
age: 32 | ||
blog: http://example.com/john |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../products.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- name: sugar | ||
price: 5.3 | ||
- name: salt | ||
price: 2.5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a test for this bit of logic around the backward compatibility? If we're going to maintain backwards compatibility, I'd like to make sure we don't break it.
Not a blocker, so I think I'll go ahead and merge this, but it's something that would be nice to have for later. 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattr- There's already a feature test for backward compatibility. https://github.com/mojombo/jekyll/pull/1003/files#diff-56fe92355e35cf3947a3fdd53aa0b8cbR51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right you are! I totally missed that before. Thank you!