From 26663a6cf91ed6fd9293a91a3ec80d4cda58be43 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 7 Apr 2014 15:36:26 +0200 Subject: [PATCH] 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