Expose collections as site.<collection_name> in Liquid as array of docs.

This commit is contained in:
Parker Moore 2014-04-05 17:28:04 -04:00
parent 00ca09a2ea
commit f0e68d7d86
4 changed files with 19 additions and 13 deletions

View File

@ -4,15 +4,15 @@ Feature: Collections
And render them And render them
Scenario: Unrendered collection Scenario: Unrendered collection
Given I have an "index.html" page that contains "Collections: {{ site.collections }}" Given I have an "index.html" page that contains "Collections: {{ site.methods }}"
And I have fixture collections And I have fixture collections
And I have a configuration file with "collections" set to "['methods']" And I have a configuration file with "collections" set to "['methods']"
When I run jekyll When I run jekyll
Then the _site directory should exist Then the _site directory should exist
And I should see "Collections: {\"methods\"=>#<Jekyll::Collection @label=methods docs=\[#<Jekyll::Document _methods/configuration.md collection=methods>, #<Jekyll::Document _methods/sanitized_path.md collection=methods>, #<Jekyll::Document _methods/site/generate.md collection=methods>, #<Jekyll::Document _methods/site/initialize.md collection=methods>, #<Jekyll::Document _methods/um_hi.md collection=methods>\]>}" in "_site/index.html" 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"
Scenario: Rendered collection Scenario: Rendered collection
Given I have an "index.html" page that contains "Collections: {{ site.collections.methods.label }}" Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
And I have fixture collections And I have fixture collections
And I have a configuration file with: And I have a configuration file with:
| key | value | | key | value |
@ -24,7 +24,7 @@ Feature: Collections
And I should see "<p>Whatever: foo.bar</p>" in "_site/methods/configuration.html" And I should see "<p>Whatever: foo.bar</p>" in "_site/methods/configuration.html"
Scenario: Rendered document in a layout Scenario: Rendered document in a layout
Given I have an "index.html" page that contains "Collections: {{ site.collections.methods.label }}" 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 a default layout that contains "<div class='title'>Tom Preston-Werner</div> {{content}}"
And I have fixture collections And I have fixture collections
And I have a configuration file with: And I have a configuration file with:

View File

@ -86,10 +86,7 @@ module Jekyll
# #
# Returns a representation of this collection for use in Liquid. # Returns a representation of this collection for use in Liquid.
def to_liquid def to_liquid
{ docs
"label" => label,
"docs" => docs
}
end end
end end

View File

@ -209,6 +209,13 @@ module Jekyll
"#<Jekyll::Document #{relative_path} collection=#{collection.label}>" "#<Jekyll::Document #{relative_path} collection=#{collection.label}>"
end end
# The string representation for this document.
#
# Returns the content of the document
def to_s
output || content
end
# Compare this document against another document. # Compare this document against another document.
# Comparison is a comparison between the 2 paths of the documents. # Comparison is a comparison between the 2 paths of the documents.
# #

View File

@ -215,8 +215,8 @@ module Jekyll
def render def render
relative_permalinks_deprecation_method relative_permalinks_deprecation_method
collections.each do |label, collection| to_render.each do |label|
collection.docs.each do |document| collections[label].docs.each do |document|
document.output = Jekyll::Renderer.new(self, document).run document.output = Jekyll::Renderer.new(self, document).run
end end
end end
@ -296,7 +296,8 @@ module Jekyll
# See Site#post_attr_hash for type info. # See Site#post_attr_hash for type info.
def site_payload def site_payload
{"jekyll" => { "version" => Jekyll::VERSION }, {"jekyll" => { "version" => Jekyll::VERSION },
"site" => config.merge({ "site" => Utils.deep_merge_hashes(config,
Utils.deep_merge_hashes(collections, {
"time" => time, "time" => time,
"posts" => posts.sort { |a, b| b <=> a }, "posts" => posts.sort { |a, b| b <=> a },
"pages" => pages, "pages" => pages,
@ -304,8 +305,9 @@ module Jekyll
"html_pages" => pages.reject { |page| !page.html? }, "html_pages" => pages.reject { |page| !page.html? },
"categories" => post_attr_hash('categories'), "categories" => post_attr_hash('categories'),
"tags" => post_attr_hash('tags'), "tags" => post_attr_hash('tags'),
"data" => site_data, "data" => site_data
"collections" => collections})} }))
}
end end
# Filter out any files/directories that are hidden or backup files (start # Filter out any files/directories that are hidden or backup files (start