From eded314bb134a169c940fc3d1771b2cba9bb2af9 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 2 Sep 2013 13:03:16 +0200 Subject: [PATCH 1/7] add a cucumber feature to test "published" for pages --- features/create_sites.feature | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/features/create_sites.feature b/features/create_sites.feature index 5d22397b..0f3bb778 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -139,3 +139,11 @@ Feature: Create sites When I run jekyll Then the _site/test directory should exist And I should see "some other stuff" in "_site/test/index.html" + + Scenario: Basic site with unpublished page + Given I have an "index.html" page with title "index" that contains "Published page" + And I have a "secret.html" page with published "false" that contains "Unpublished page" + When I run jekyll + Then the _site directory should exist + And the "_site/index.html" file should exist + But the "_site/secret.html" file should not exist From 91e9ecfa63b68ead5595ecfd67fea3e5ad33aef4 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 7 Apr 2014 15:35:25 +0200 Subject: [PATCH 2/7] Add an --unpublished option to render unpublished posts Fixes #1337, #469. --- lib/jekyll/command.rb | 1 + lib/jekyll/configuration.rb | 1 + lib/jekyll/site.rb | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/command.rb b/lib/jekyll/command.rb index 957e9825..62a532f6 100644 --- a/lib/jekyll/command.rb +++ b/lib/jekyll/command.rb @@ -70,6 +70,7 @@ module Jekyll c.option 'force_polling', '--force_polling', 'Force watch to use polling' c.option 'lsi', '--lsi', 'Use LSI for improved related posts' c.option 'show_drafts', '-D', '--drafts', 'Render posts in the _drafts folder' + c.option 'unpublished', '--unpublished', 'Render posts that were marked as unpublished' c.option 'quiet', '-q', '--quiet', 'Silence output.' c.option 'verbose', '-V', '--verbose', 'Print verbose output.' end diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 091bebc4..93dc5193 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -24,6 +24,7 @@ module Jekyll 'limit_posts' => 0, 'lsi' => false, 'future' => true, # remove and make true just default + 'unpublished' => false, 'relative_permalinks' => true, # backwards-compatibility with < 1.0 # will be set to false once 2.0 hits diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 8497dd10..60093e8f 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -2,7 +2,7 @@ module Jekyll class Site attr_accessor :config, :layouts, :posts, :pages, :static_files, :exclude, :include, :source, :dest, :lsi, :highlighter, - :permalink_style, :time, :future, :safe, :plugins, :limit_posts, + :permalink_style, :time, :future, :unpublished, :safe, :plugins, :limit_posts, :show_drafts, :keep_files, :baseurl, :data, :file_read_opts, :gems, :plugin_manager @@ -14,7 +14,7 @@ module Jekyll def initialize(config) self.config = config.clone - %w[safe lsi highlighter baseurl exclude include future show_drafts limit_posts keep_files gems].each do |opt| + %w[safe lsi highlighter baseurl exclude include future unpublished show_drafts limit_posts keep_files gems].each do |opt| self.send("#{opt}=", config[opt]) end From 26663a6cf91ed6fd9293a91a3ec80d4cda58be43 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 7 Apr 2014 15:36:26 +0200 Subject: [PATCH 3/7] add the Publisher class to handle publishing logic --- lib/jekyll.rb | 1 + lib/jekyll/publisher.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lib/jekyll/publisher.rb diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 604ff238..e2dd369c 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -50,6 +50,7 @@ require 'jekyll/related_posts' require 'jekyll/cleaner' require 'jekyll/entry_filter' require 'jekyll/layout_reader' +require 'jekyll/publisher' # extensions require 'jekyll/plugin' diff --git a/lib/jekyll/publisher.rb b/lib/jekyll/publisher.rb new file mode 100644 index 00000000..e86e96b6 --- /dev/null +++ b/lib/jekyll/publisher.rb @@ -0,0 +1,21 @@ +module Jekyll + class Publisher + def initialize(site) + @site = site + end + + def publish?(thing) + can_be_published?(thing) && !hidden_in_the_future?(thing) + end + + private + + def can_be_published?(thing) + thing.data.fetch('published', true) || @site.unpublished + end + + def hidden_in_the_future?(thing) + thing.is_a?(Post) && !@site.future && thing.date > @site.time + end + end +end \ No newline at end of file From 3a330dc7fcbbd0b4e4fe50a904f1b6b9df6fdb42 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 7 Apr 2014 15:38:11 +0200 Subject: [PATCH 4/7] Use Publisher instead of Post#published? --- lib/jekyll/site.rb | 8 +++++--- test/test_post.rb | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 60093e8f..d9152b9d 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -134,9 +134,7 @@ module Jekyll posts = read_content(dir, '_posts', Post) posts.each do |post| - if post.published? && (future || post.date <= time) - aggregate_post_info(post) - end + aggregate_post_info(post) if publisher.publish?(post) end end @@ -391,5 +389,9 @@ module Jekyll name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') name.gsub(/\s+/, '_') end + + def publisher + @publisher ||= Publisher.new(self) + end end end diff --git a/test/test_post.rb b/test/test_post.rb index d7a57510..87644e24 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -417,12 +417,12 @@ class TestPost < Test::Unit::TestCase context "initializing posts" do should "publish when published yaml is no specified" do post = setup_post("2008-02-02-published.textile") - assert_equal true, post.published? + assert_equal true, @site.send(:publisher).publish?(post) end should "not published when published yaml is false" do post = setup_post("2008-02-02-not-published.textile") - assert_equal false, post.published? + assert_equal false, @site.send(:publisher).publish?(post) end should "recognize date in yaml" do From 46a5ab99f9710539c05131ce1526cbd834180fe9 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 2 Sep 2013 13:25:22 +0200 Subject: [PATCH 5/7] Support "published: false" for pages Fixes 1034. --- lib/jekyll/site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index d9152b9d..54a6f1ad 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -115,7 +115,7 @@ module Jekyll read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs elsif has_yaml_header?(f_abs) page = Page.new(self, source, dir, f) - pages << page if page.published? + pages << page if publisher.publish?(page) else static_files << StaticFile.new(self, source, dir, f) end From 199728144942c7fe599ce74a9e3c3d84f7422711 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 7 Apr 2014 15:46:21 +0200 Subject: [PATCH 6/7] Add feature for the "--unsupported" flag Also make step definitions a little more generic. --- features/create_sites.feature | 6 ++++++ features/step_definitions/jekyll_steps.rb | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/features/create_sites.feature b/features/create_sites.feature index 0f3bb778..33327df6 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -143,7 +143,13 @@ Feature: Create sites Scenario: Basic site with unpublished page Given I have an "index.html" page with title "index" that contains "Published page" And I have a "secret.html" page with published "false" that contains "Unpublished page" + When I run jekyll Then the _site directory should exist And the "_site/index.html" file should exist But the "_site/secret.html" file should not exist + + When I run jekyll with "--unpublished" + Then the _site directory should exist + And the "_site/index.html" file should exist + And the "_site/secret.html" file should exist diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 00264fb6..93de5c10 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -130,9 +130,8 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table| end end - -When /^I run jekyll$/ do - run_jekyll_build +When /^I run jekyll(?: with "(.+)")?$/ do |opt| + run_jekyll_build(opt) end When /^I run jekyll in safe mode$/ do From 2804e08908628755b53febe007356e283952c00e Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Tue, 10 Sep 2013 21:48:12 +0200 Subject: [PATCH 7/7] delete old superfluous tests; extend feature --- features/create_sites.feature | 3 +++ test/test_post.rb | 10 ---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/features/create_sites.feature b/features/create_sites.feature index 33327df6..c84d90f8 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -142,14 +142,17 @@ Feature: Create sites Scenario: Basic site with unpublished page Given I have an "index.html" page with title "index" that contains "Published page" + And I have a "public.html" page with published "true" that contains "Explicitly published page" And I have a "secret.html" page with published "false" that contains "Unpublished page" When I run jekyll Then the _site directory should exist And the "_site/index.html" file should exist + And the "_site/public.html" file should exist But the "_site/secret.html" file should not exist When I run jekyll with "--unpublished" Then the _site directory should exist And the "_site/index.html" file should exist + And the "_site/public.html" file should exist And the "_site/secret.html" file should exist diff --git a/test/test_post.rb b/test/test_post.rb index 87644e24..9f963d0f 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -415,16 +415,6 @@ class TestPost < Test::Unit::TestCase end context "initializing posts" do - should "publish when published yaml is no specified" do - post = setup_post("2008-02-02-published.textile") - assert_equal true, @site.send(:publisher).publish?(post) - end - - should "not published when published yaml is false" do - post = setup_post("2008-02-02-not-published.textile") - assert_equal false, @site.send(:publisher).publish?(post) - end - should "recognize date in yaml" do post = setup_post("2010-01-09-date-override.textile") do_render(post)