From c906dfdf713fa07f3a45b2026111233c362b5e1c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Thu, 24 Apr 2014 13:59:11 -0400 Subject: [PATCH] TEST THE COLLECTIONS --- features/collections.feature | 44 ++++++++++++++++++++++++++---------- lib/jekyll/collection.rb | 8 ++++++- lib/jekyll/site.rb | 3 ++- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/features/collections.feature b/features/collections.feature index 6ff41080..6e8d76a8 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -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:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

\n

Jekyll.sanitized_path is used to make sure your path is in your source.

\n

Run your generators! default

\n

Create dat site.

\n

Run your generators! default

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

Whatever: foo.bar

" 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 "
Tom Preston-Werner
{{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 "

Run your generators! default

" in "_site/methods/site/generate.html" - And I should see "
Tom Preston-Werner
" in "_site/methods/site/generate.html" \ No newline at end of file + And I should see "
Tom Preston-Werner
" 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" diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index be590e0d..ba8f8d91 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -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 diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 4f3d04fe..ccc6d2c6 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -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 })) }