From a2169bf0c4170e9dfae53e51ce07d508a745c3a5 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 4 May 2014 21:19:09 -0400 Subject: [PATCH 1/4] Have separate methods for all docs and just the docs that are being written. --- lib/jekyll/site.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index ccc6d2c6..3f57a83f 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -405,7 +405,7 @@ module Jekyll end end - def documents + def docs_to_write collections.reduce(Set.new) do |docs, (_, collection)| if collection.write? docs.merge(collection.docs) @@ -415,8 +415,14 @@ module Jekyll end end + def documents + collections.reduce(Set.new) do |docs, (_, collection)| + docs.merge(collection.docs) + end + end + def each_site_file - %w(posts pages static_files documents).each do |type| + %w(posts pages static_files docs_to_write).each do |type| send(type).each do |item| yield item end From 54b74fafba7d42d54a22abf4cb41033900a9aa0e Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 4 May 2014 21:22:51 -0400 Subject: [PATCH 2/4] Add documents to site payload --- lib/jekyll/document.rb | 9 +++++++++ lib/jekyll/site.rb | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 0a75fe96..3b2b6eeb 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -228,5 +228,14 @@ module Jekyll path <=> anotherDocument.path end + # Determine whether this document should be written. + # Based on the Collection to which it belongs. + # + # True if the document has a collection and if that collection's #write? + # method returns true, otherwise false. + def write? + collection && collection.write? + end + end end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 3f57a83f..0b785e51 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -325,6 +325,7 @@ module Jekyll "categories" => post_attr_hash('categories'), "tags" => post_attr_hash('tags'), "collections" => collections, + "documents" => documents, "data" => site_data })) } From fc98f06ed718d0c077de888e4417c5a0e6b0a674 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 4 May 2014 21:22:57 -0400 Subject: [PATCH 3/4] Refactor docs_to_write --- lib/jekyll/site.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 0b785e51..5350edec 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -407,13 +407,7 @@ module Jekyll end def docs_to_write - collections.reduce(Set.new) do |docs, (_, collection)| - if collection.write? - docs.merge(collection.docs) - else - docs - end - end + documents.select(&:write?) end def documents From 3755437d089674102289edea4dab5c0c99c96ea5 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 6 May 2014 00:11:35 -0400 Subject: [PATCH 4/4] Write test for site.documents. --- features/collections.feature | 12 ++++++++++++ lib/jekyll/site.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/features/collections.feature b/features/collections.feature index 32e9161c..402e7dab 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -70,3 +70,15 @@ Feature: Collections When I run jekyll build 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" + + Scenario: All the documents + Given I have an "index.html" page that contains "All documents: {% for doc in site.documents %}{{ doc.relative_path }} {% endfor %}" + And I have fixture collections + And I have a "_config.yml" file with content: + """ + collections: + - methods + """ + When I run jekyll build + Then the _site directory should exist + And I should see "All documents: _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/site.rb b/lib/jekyll/site.rb index 5350edec..5ebf3c20 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -413,7 +413,7 @@ module Jekyll def documents collections.reduce(Set.new) do |docs, (_, collection)| docs.merge(collection.docs) - end + end.to_a end def each_site_file