From 7655b533c9297c224e50eb00d75e5967fc54d4f5 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Sat, 29 Nov 2014 10:51:30 -0800 Subject: [PATCH 1/2] Allow documents to set `published` in front matter --- lib/jekyll/collection.rb | 13 ++++++++- test/source/_slides/non-outputted-slide.html | 7 +++++ test/test_document.rb | 28 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/source/_slides/non-outputted-slide.html diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index 73e480dd..f768b836 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -40,7 +40,7 @@ module Jekyll if Utils.has_yaml_header? full_path doc = Jekyll::Document.new(full_path, { site: site, collection: self }) doc.read - docs << doc + docs << doc if publisher.publish?(doc) else relative_dir = Jekyll.sanitized_path(relative_directory, File.dirname(file_path)).chomp("/.") files << StaticFile.new(site, site.source, relative_dir, File.basename(full_path), self) @@ -184,5 +184,16 @@ module Jekyll end end + + private + + # A Publisher object used to determine which documents should be + # added to the docs list + # + # Returns a Publisher object. + def publisher + @publisher ||= Publisher.new(site) + end + end end diff --git a/test/source/_slides/non-outputted-slide.html b/test/source/_slides/non-outputted-slide.html new file mode 100644 index 00000000..5eca1568 --- /dev/null +++ b/test/source/_slides/non-outputted-slide.html @@ -0,0 +1,7 @@ +--- + title: Non outputted slide + layout: slide + published: false +--- + +This should not be output diff --git a/test/test_document.rb b/test/test_document.rb index 57c14c22..ba2c4d8c 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -237,6 +237,34 @@ class TestDocument < Test::Unit::TestCase end end + context "documents in a collection" do + setup do + @site = Site.new(Jekyll.configuration({ + "collections" => { + "slides" => { + "output" => true + } + }, + "source" => source_dir, + "destination" => dest_dir + })) + @site.process + @files = @site.collections["slides"].docs + end + + context "without output overrides" do + should "be output according to collection defaults" do + assert_not_nil @files.find { |doc| doc.relative_path == "_slides/example-slide-4.html" } + end + end + + context "with output overrides" do + should "be output according its front matter" do + assert_nil @files.find { |doc| doc.relative_path == "_slides/non-outputted-slide.html" } + end + end + end + context "a static file in a collection" do setup do @site = Site.new(Jekyll.configuration({ From c58ac78a5e4c0c3a5d27f1540e4763656edc8fbe Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Sun, 30 Nov 2014 18:46:45 -0800 Subject: [PATCH 2/2] Expose Publisher in Site --- lib/jekyll/collection.rb | 14 +------------- lib/jekyll/site.rb | 8 ++++---- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index f768b836..b09a7ed9 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -40,7 +40,7 @@ module Jekyll if Utils.has_yaml_header? full_path doc = Jekyll::Document.new(full_path, { site: site, collection: self }) doc.read - docs << doc if publisher.publish?(doc) + docs << doc if site.publisher.publish?(doc) else relative_dir = Jekyll.sanitized_path(relative_directory, File.dirname(file_path)).chomp("/.") files << StaticFile.new(site, site.source, relative_dir, File.basename(full_path), self) @@ -183,17 +183,5 @@ module Jekyll {} end end - - - private - - # A Publisher object used to determine which documents should be - # added to the docs list - # - # Returns a Publisher object. - def publisher - @publisher ||= Publisher.new(site) - end - end end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 7b8a4a00..2754a6e5 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -497,6 +497,10 @@ module Jekyll override['full_rebuild'] || config['full_rebuild'] end + def publisher + @publisher ||= Publisher.new(self) + end + private def has_relative_page? @@ -517,9 +521,5 @@ module Jekyll name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') name.gsub(/\s+/, '_') end - - def publisher - @publisher ||= Publisher.new(self) - end end end