From 7655b533c9297c224e50eb00d75e5967fc54d4f5 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Sat, 29 Nov 2014 10:51:30 -0800 Subject: [PATCH] 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({