TEST THE COLLECTIONS

This commit is contained in:
Parker Moore 2014-04-24 13:59:11 -04:00
parent dd4fe87f69
commit c906dfdf71
3 changed files with 41 additions and 14 deletions

View File

@ -9,30 +9,50 @@ Feature: Collections
And I have a configuration file with "collections" set to "['methods']"
When I run jekyll build
Then the _site directory should exist
And I should see "Collections: Use `{{ page.title }}` to build a full configuration for use w/Jekyll.\n\nWhatever: {{ page.whatever }}\n`{{ page.title }}` is used to make sure your path is in your source.\nRun your generators! {{ page.layout }}\nCreate dat site.\nRun your generators! {{ page.layout }}" in "_site/index.html"
And I should see "Collections: <p>Use <code>Jekyll.configuration</code> to build a full configuration for use w/Jekyll.</p>\n\n<p>Whatever: foo.bar</p>\n<p><code>Jekyll.sanitized_path</code> is used to make sure your path is in your source.</p>\n<p>Run your generators! default</p>\n<p>Create dat site.</p>\n<p>Run your generators! default</p>" in "_site/index.html"
And the "_site/methods/configuration.html" file should not exist
Scenario: Rendered collection
Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
And I have an "collection_metadata.html" page that contains "Methods metadata: {{ site.collections.methods.foo }} {{ site.collections.methods }}"
And I have fixture collections
And I have a configuration file with:
| key | value |
| collections | ['methods'] |
| render | ['methods'] |
And I have a "_config.yml" file with content:
"""
collections:
methods:
write: true
foo: bar
"""
When I run jekyll build
Then the _site directory should exist
And I should see "Collections: methods" in "_site/index.html"
And I should see "Collections: {\"methods" in "_site/index.html"
And I should see "Methods metadata: bar" in "_site/collection_metadata.html"
And I should see "<p>Whatever: foo.bar</p>" in "_site/methods/configuration.html"
Scenario: Rendered document in a layout
Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
And I have a default layout that contains "<div class='title'>Tom Preston-Werner</div> {{content}}"
And I have fixture collections
And I have a configuration file with:
| key | value |
| collections | ['methods'] |
| render | ['methods'] |
And I have a "_config.yml" file with content:
"""
collections:
methods:
write: true
foo: bar
"""
When I run jekyll build
Then the _site directory should exist
And I should see "Collections: methods" in "_site/index.html"
And I should see "Collections: {\"methods" in "_site/index.html"
And I should see "<p>Run your generators! default</p>" in "_site/methods/site/generate.html"
And I should see "<div class='title'>Tom Preston-Werner</div>" in "_site/methods/site/generate.html"
And I should see "<div class='title'>Tom Preston-Werner</div>" in "_site/methods/site/generate.html"
Scenario: Collections directly on the site
Given I have an "index.html" page that contains "Collections: {% for method in site.methods %}{{ method.relative_path }} {% endfor %}"
And I have fixture collections
And I have a "_config.yml" file with content:
"""
collections: [methods]
"""
When I run jekyll
Then the _site directory should exist
And I should see "Collections: _methods/configuration.md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md" in "_site/index.html"

View File

@ -115,7 +115,13 @@ module Jekyll
#
# Returns a representation of this collection for use in Liquid.
def to_liquid
docs
metadata.merge({
"label" => label,
"docs" => docs,
"directory" => directory,
"written" => write?,
"relative_directory" => relative_directory
})
end
# Whether the collection's documents ought to be written as individual

View File

@ -316,7 +316,7 @@ module Jekyll
def site_payload
{"jekyll" => { "version" => Jekyll::VERSION },
"site" => Utils.deep_merge_hashes(config,
Utils.deep_merge_hashes(collections, {
Utils.deep_merge_hashes(Hash[collections.map{|label, coll| [label, coll.docs]}], {
"time" => time,
"posts" => posts.sort { |a, b| b <=> a },
"pages" => pages,
@ -324,6 +324,7 @@ module Jekyll
"html_pages" => pages.reject { |page| !page.html? },
"categories" => post_attr_hash('categories'),
"tags" => post_attr_hash('tags'),
"collections" => collections,
"data" => site_data
}))
}