From 0ad623fb85377c8554b9d3eea5d472d164d6e2ba Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 20 Jan 2013 02:20:00 +0200 Subject: [PATCH 01/15] first pass at --drafts flag --- bin/jekyll | 1 + lib/jekyll/post.rb | 6 +++--- lib/jekyll/site.rb | 34 ++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 309ffc91..c05d5dce 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -37,6 +37,7 @@ command :serve do |c| c.option '-w', '--watch', 'Watch for changes and rebuild' c.option '--lsi', 'Use LSI for improved related posts' + c.option '--drafts', 'Render posts in the _drafts folder' c.option '-p', '--port [PORT]', 'Port to listen on' c.option '-h', '--host [HOST]', 'Host to bind to' diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 835f9a42..f94169b0 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -30,12 +30,12 @@ module Jekyll # site - The Site. # base - The String path to the dir containing the post file. # name - The String filename of the post file. - # categories - An Array of Strings for the categories for this post. + # subdir - The String path to the subdirectory. # # Returns the new Post. - def initialize(site, source, dir, name) + def initialize(site, source, dir, name, subdir = '_posts') @site = site - @base = File.join(source, dir, '_posts') + @base = File.join(source, dir, subdir) @name = name self.categories = dir.split('/').reject { |x| x.empty? } diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 462da488..636045be 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -5,7 +5,7 @@ module Jekyll class Site attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude, :include, :source, :dest, :lsi, :pygments, - :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, + :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, :show_drafts, :keep_files attr_accessor :converters, :generators @@ -26,6 +26,7 @@ module Jekyll self.exclude = config['exclude'] || [] self.include = config['include'] || [] self.future = config['future'] + self.show_drafts = config['drafts'] || nil self.limit_posts = config['limit_posts'] || nil self.keep_files = config['keep_files'] || [] @@ -136,7 +137,19 @@ module Jekyll base = File.join(self.source, dir) entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) } - self.read_posts(dir) + self.read_posts(dir,'_posts') + + if self.show_drafts + self.read_posts(dir,'_drafts') + end + + self.posts.sort! + + # limit the posts if :limit_posts option is set + if limit_posts + limit = self.posts.length < limit_posts ? self.posts.length : limit_posts + self.posts = self.posts[-limit, limit] + end entries.each do |f| f_abs = File.join(base, f) @@ -160,18 +173,19 @@ module Jekyll # Read all the files in //_posts and create a new Post # object with each one. # - # dir - The String relative path of the directory to read. + # dir - The String relative path of the directory to read. + # subdir - The String relative path of the subdirectory to read. # # Returns nothing. - def read_posts(dir) - base = File.join(self.source, dir, '_posts') + def read_posts(dir, subdir) + base = File.join(self.source, dir, subdir) return unless File.exists?(base) entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } # first pass processes, but does not yet render post content entries.each do |f| if Post.valid?(f) - post = Post.new(self, self.source, dir, f) + post = Post.new(self, self.source, dir, f, subdir) if post.published && (self.future || post.date <= self.time) self.posts << post @@ -180,14 +194,6 @@ module Jekyll end end end - - self.posts.sort! - - # limit the posts if :limit_posts option is set - if limit_posts - limit = self.posts.length < limit_posts ? self.posts.length : limit_posts - self.posts = self.posts[-limit, limit] - end end # Run each of the Generators. From 2df63e5b9df8c6e28f805d6052c86bf9214a3731 Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 20 Jan 2013 03:14:11 +0200 Subject: [PATCH 02/15] fix tests --- test/test_site.rb | 2 +- test/test_tags.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_site.rb b/test/test_site.rb index c698a887..e0f90c44 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -124,7 +124,7 @@ class TestSite < Test::Unit::TestCase end should "read posts" do - @site.read_posts('') + @site.read_posts('', '_posts') posts = Dir[source_dir('_posts', '*')] assert_equal posts.size - 1, @site.posts.size end diff --git a/test/test_tags.rb b/test/test_tags.rb index 816fd809..286b1817 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -11,7 +11,7 @@ class TestTags < Test::Unit::TestCase site = Site.new(Jekyll.configuration) if override['read_posts'] - site.read_posts('') + site.read_posts('', '_posts') end info = { :filters => [Jekyll::Filters], :registers => { :site => site } } From c48de6b320b3a6d48407b82d9005b9c854d152de Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 20 Jan 2013 04:38:23 +0200 Subject: [PATCH 03/15] add drafts.feature --- bin/jekyll | 1 + features/drafts.feature | 25 +++++++++++++++++++++++ features/step_definitions/jekyll_steps.rb | 10 +++++++-- features/support/env.rb | 3 ++- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 features/drafts.feature diff --git a/bin/jekyll b/bin/jekyll index c05d5dce..e25a16a4 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -23,6 +23,7 @@ command :build do |c| c.option '-w', '--watch', 'Watch for changes and rebuild' c.option '--lsi', 'Use LSI for improved related posts' + c.option '--drafts', 'Render posts in the _drafts folder' c.action do |args, options| options.defaults :serving => false diff --git a/features/drafts.feature b/features/drafts.feature new file mode 100644 index 00000000..d7a6eb31 --- /dev/null +++ b/features/drafts.feature @@ -0,0 +1,25 @@ +Feature: Draft Posts + As a hacker who likes to blog + I want to be able to preview drafts locally + In order to see if they look alright before publishing + + Scenario: Preview a draft + Given I have a configuration file with "permalink" set to "none" + And I have a _drafts directory + And I have the following draft: + | title | date | layout | content | + | Recipe | 3/27/2009 | default | Not baked yet. | + When I run jekyll with drafts + Then the _site directory should exist + And I should see "Not baked yet." in "_site/recipe.html" + + Scenario: Don't preview a draft + Given I have a configuration file with "permalink" set to "none" + And I have an "index.html" page that contains "Totally index" + And I have a _drafts directory + And I have the following draft: + | title | date | layout | content | + | Recipe | 3/27/2009 | default | Not baked yet. | + When I run jekyll + Then the _site directory should exist + And the "_site/recipe.html" file should not exist diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 20128964..4c1b0cc1 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -50,7 +50,9 @@ Given /^I have an? (.*) directory$/ do |dir| FileUtils.mkdir_p(dir) end -Given /^I have the following posts?(?: (.*) "(.*)")?:$/ do |direction, folder, table| +Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |type, direction, folder, table| + subdir = "_#{type}s" + table.hashes.each do |post| date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d') title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') @@ -61,7 +63,7 @@ Given /^I have the following posts?(?: (.*) "(.*)")?:$/ do |direction, folder, t after = folder || '.' end - path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}") + path = File.join(before || '.', subdir, after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}") matter_hash = {} %w(title layout tag tags category categories published author).each do |key| @@ -117,6 +119,10 @@ When /^I run jekyll$/ do run_jekyll end +When /^I run jekyll with drafts$/ do + run_jekyll(:drafts => true) +end + When /^I debug jekyll$/ do run_jekyll(:debug => true) end diff --git a/features/support/env.rb b/features/support/env.rb index 1ed330a1..7e550c6c 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -10,8 +10,9 @@ TEST_DIR = File.join('/', 'tmp', 'jekyll') JEKYLL_PATH = File.join(ENV['PWD'], 'bin', 'jekyll') def run_jekyll(opts = {}) - command = JEKYLL_PATH + command = JEKYLL_PATH.clone command << " build" + command << " --drafts" if opts[:drafts] command << " >> /dev/null 2>&1" if opts[:debug].nil? system command end From daa9e11994482d0cde3901732dd0758f8e33400d Mon Sep 17 00:00:00 2001 From: scribu Date: Thu, 31 Jan 2013 05:35:19 +0200 Subject: [PATCH 04/15] fix whitespace in drafts.feature --- features/drafts.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/drafts.feature b/features/drafts.feature index d7a6eb31..27832fc4 100644 --- a/features/drafts.feature +++ b/features/drafts.feature @@ -11,7 +11,7 @@ Feature: Draft Posts | Recipe | 3/27/2009 | default | Not baked yet. | When I run jekyll with drafts Then the _site directory should exist - And I should see "Not baked yet." in "_site/recipe.html" + And I should see "Not baked yet." in "_site/recipe.html" Scenario: Don't preview a draft Given I have a configuration file with "permalink" set to "none" @@ -22,4 +22,4 @@ Feature: Draft Posts | Recipe | 3/27/2009 | default | Not baked yet. | When I run jekyll Then the _site directory should exist - And the "_site/recipe.html" file should not exist + And the "_site/recipe.html" file should not exist From 1ac46b17c43dbeead83b62bc6820dd8ebf96717a Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 9 Feb 2013 18:01:19 +0200 Subject: [PATCH 05/15] Don't require date in draft filenames. --- features/step_definitions/jekyll_steps.rb | 14 +++++--- lib/jekyll.rb | 1 + lib/jekyll/draft.rb | 22 +++++++++++++ lib/jekyll/post.rb | 5 ++- lib/jekyll/site.rb | 40 +++++++++++++++++++---- 5 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 lib/jekyll/draft.rb diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 4c1b0cc1..1b0eb519 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -50,11 +50,8 @@ Given /^I have an? (.*) directory$/ do |dir| FileUtils.mkdir_p(dir) end -Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |type, direction, folder, table| - subdir = "_#{type}s" - +Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, direction, folder, table| table.hashes.each do |post| - date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d') title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') if direction && direction == "in" @@ -63,7 +60,14 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |type, direct after = folder || '.' end - path = File.join(before || '.', subdir, after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}") + ext = post['type'] || 'textile' + + if "draft" == status + path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}") + else + date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d') + path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}") + end matter_hash = {} %w(title layout tag tags category categories published author).each do |key| diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 477247dd..0fa50895 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -33,6 +33,7 @@ require 'jekyll/convertible' require 'jekyll/layout' require 'jekyll/page' require 'jekyll/post' +require 'jekyll/draft' require 'jekyll/filters' require 'jekyll/static_file' require 'jekyll/errors' diff --git a/lib/jekyll/draft.rb b/lib/jekyll/draft.rb new file mode 100644 index 00000000..43a47e4c --- /dev/null +++ b/lib/jekyll/draft.rb @@ -0,0 +1,22 @@ +module Jekyll + + class Draft < Post + + # Valid post name regex (no date) + MATCHER = /^(.*)(\.[^.]+)$/ + + # Extract information from the post filename. + # + # name - The String filename of the post file. + # + # Returns nothing. + def process(name) + slug, ext = *name.match(MATCHER) + self.date = File.mtime(File.join(@base, name)) + self.slug = slug + self.ext = ext + end + + end + +end diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index f94169b0..1386c6ef 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -30,12 +30,11 @@ module Jekyll # site - The Site. # base - The String path to the dir containing the post file. # name - The String filename of the post file. - # subdir - The String path to the subdirectory. # # Returns the new Post. - def initialize(site, source, dir, name, subdir = '_posts') + def initialize(site, source, dir, name) @site = site - @base = File.join(source, dir, subdir) + @base = File.join(source, dir) @name = name self.categories = dir.split('/').reject { |x| x.empty? } diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 636045be..55964bee 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -137,10 +137,10 @@ module Jekyll base = File.join(self.source, dir) entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) } - self.read_posts(dir,'_posts') + self.read_posts(dir) if self.show_drafts - self.read_posts(dir,'_drafts') + self.read_drafts(dir) end self.posts.sort! @@ -174,18 +174,46 @@ module Jekyll # object with each one. # # dir - The String relative path of the directory to read. - # subdir - The String relative path of the subdirectory to read. # # Returns nothing. - def read_posts(dir, subdir) - base = File.join(self.source, dir, subdir) + def read_posts(dir) + dir = File.join(dir, '_posts') + + base = File.join(self.source, dir) return unless File.exists?(base) entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } # first pass processes, but does not yet render post content entries.each do |f| if Post.valid?(f) - post = Post.new(self, self.source, dir, f, subdir) + post = Post.new(self, self.source, dir, f) + + if post.published && (self.future || post.date <= self.time) + self.posts << post + post.categories.each { |c| self.categories[c] << post } + post.tags.each { |c| self.tags[c] << post } + end + end + end + end + + # Read all the files in //_drafts and create a new Post + # object with each one. + # + # dir - The String relative path of the directory to read. + # + # Returns nothing. + def read_drafts(dir) + dir = File.join(dir, '_drafts') + + base = File.join(self.source, dir) + return unless File.exists?(base) + entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } + + # first pass processes, but does not yet render post content + entries.each do |f| + if Post.valid?(f) + post = Draft.new(self, self.source, dir, f) if post.published && (self.future || post.date <= self.time) self.posts << post From 642349f797c41b2cd87f8774d7c598339c832a54 Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 9 Feb 2013 22:41:47 +0200 Subject: [PATCH 06/15] implement and use Draft.valid? --- lib/jekyll/draft.rb | 8 ++++++++ lib/jekyll/site.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/draft.rb b/lib/jekyll/draft.rb index 43a47e4c..a381d8e4 100644 --- a/lib/jekyll/draft.rb +++ b/lib/jekyll/draft.rb @@ -5,6 +5,14 @@ module Jekyll # Valid post name regex (no date) MATCHER = /^(.*)(\.[^.]+)$/ + # Draft name validator. Draft filenames must be like: + # my-awesome-post.textile + # + # Returns true if valid, false if not. + def self.valid?(name) + name =~ MATCHER + end + # Extract information from the post filename. # # name - The String filename of the post file. diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 55964bee..16e9ad40 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -212,7 +212,7 @@ module Jekyll # first pass processes, but does not yet render post content entries.each do |f| - if Post.valid?(f) + if Draft.valid?(f) post = Draft.new(self, self.source, dir, f) if post.published && (self.future || post.date <= self.time) From 78831d94cde90d4ed7422f436744f2c339458c1f Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 9 Feb 2013 22:49:49 +0200 Subject: [PATCH 07/15] don't mess with dir parameter --- lib/jekyll/draft.rb | 5 +++++ lib/jekyll/post.rb | 7 ++++++- lib/jekyll/site.rb | 8 ++------ test/test_site.rb | 2 +- test/test_tags.rb | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/draft.rb b/lib/jekyll/draft.rb index a381d8e4..c28b7c2f 100644 --- a/lib/jekyll/draft.rb +++ b/lib/jekyll/draft.rb @@ -13,6 +13,11 @@ module Jekyll name =~ MATCHER end + # Get the full path to the directory containing the draft files + def get_base(source, dir) + return File.join(source, dir, '_drafts') + end + # Extract information from the post filename. # # name - The String filename of the post file. diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 1386c6ef..2a5bdafa 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -34,7 +34,7 @@ module Jekyll # Returns the new Post. def initialize(site, source, dir, name) @site = site - @base = File.join(source, dir) + @base = self.get_base(source, dir) @name = name self.categories = dir.split('/').reject { |x| x.empty? } @@ -65,6 +65,11 @@ module Jekyll end end + # Get the full path to the directory containing the post files + def get_base(source, dir) + return File.join(source, dir, '_posts') + end + # Read the YAML frontmatter. # # base - The String path to the dir containing the file. diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 16e9ad40..5d1bfd70 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -177,9 +177,7 @@ module Jekyll # # Returns nothing. def read_posts(dir) - dir = File.join(dir, '_posts') - - base = File.join(self.source, dir) + base = File.join(self.source, dir, '_posts') return unless File.exists?(base) entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } @@ -204,9 +202,7 @@ module Jekyll # # Returns nothing. def read_drafts(dir) - dir = File.join(dir, '_drafts') - - base = File.join(self.source, dir) + base = File.join(self.source, dir, '_drafts') return unless File.exists?(base) entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } diff --git a/test/test_site.rb b/test/test_site.rb index e0f90c44..c698a887 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -124,7 +124,7 @@ class TestSite < Test::Unit::TestCase end should "read posts" do - @site.read_posts('', '_posts') + @site.read_posts('') posts = Dir[source_dir('_posts', '*')] assert_equal posts.size - 1, @site.posts.size end diff --git a/test/test_tags.rb b/test/test_tags.rb index 286b1817..816fd809 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -11,7 +11,7 @@ class TestTags < Test::Unit::TestCase site = Site.new(Jekyll.configuration) if override['read_posts'] - site.read_posts('', '_posts') + site.read_posts('') end info = { :filters => [Jekyll::Filters], :registers => { :site => site } } From 2588d681c96679b3eafa2647759db73f13792bbd Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 9 Feb 2013 23:38:13 +0200 Subject: [PATCH 08/15] fix draft filename processing --- lib/jekyll/draft.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/draft.rb b/lib/jekyll/draft.rb index c28b7c2f..629efd64 100644 --- a/lib/jekyll/draft.rb +++ b/lib/jekyll/draft.rb @@ -24,7 +24,7 @@ module Jekyll # # Returns nothing. def process(name) - slug, ext = *name.match(MATCHER) + m, slug, ext = *name.match(MATCHER) self.date = File.mtime(File.join(@base, name)) self.slug = slug self.ext = ext From 3e164d6daf5b035cec672d06a3b12f09a00f151d Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 9 Feb 2013 23:47:17 +0200 Subject: [PATCH 09/15] don't check if draft is published or if its date is in the future --- lib/jekyll/site.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 5d1bfd70..ae9c9d30 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -206,16 +206,14 @@ module Jekyll return unless File.exists?(base) entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } - # first pass processes, but does not yet render post content + # first pass processes, but does not yet render draft content entries.each do |f| if Draft.valid?(f) - post = Draft.new(self, self.source, dir, f) + draft = Draft.new(self, self.source, dir, f) - if post.published && (self.future || post.date <= self.time) - self.posts << post - post.categories.each { |c| self.categories[c] << post } - post.tags.each { |c| self.tags[c] << post } - end + self.posts << draft + draft.categories.each { |c| self.categories[c] << draft } + draft.tags.each { |c| self.tags[c] << draft } end end end From 538c2086a58047d41cbb4e3eb3661bcef86e3601 Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 10 Feb 2013 04:49:27 +0200 Subject: [PATCH 10/15] whitespace fixes --- lib/jekyll/site.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index ae9c9d30..1f9bd565 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -5,8 +5,8 @@ module Jekyll class Site attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude, :include, :source, :dest, :lsi, :pygments, - :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, :show_drafts, - :keep_files + :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, + :show_drafts, :keep_files attr_accessor :converters, :generators @@ -173,7 +173,7 @@ module Jekyll # Read all the files in //_posts and create a new Post # object with each one. # - # dir - The String relative path of the directory to read. + # dir - The String relative path of the directory to read. # # Returns nothing. def read_posts(dir) @@ -198,7 +198,7 @@ module Jekyll # Read all the files in //_drafts and create a new Post # object with each one. # - # dir - The String relative path of the directory to read. + # dir - The String relative path of the directory to read. # # Returns nothing. def read_drafts(dir) From 1a351284ca4cb4a37031bfcd084e5437559f69c4 Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 3 Mar 2013 12:56:12 +0200 Subject: [PATCH 11/15] rename get_base() to containing_dir() --- lib/jekyll/draft.rb | 2 +- lib/jekyll/post.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/draft.rb b/lib/jekyll/draft.rb index 629efd64..32457fac 100644 --- a/lib/jekyll/draft.rb +++ b/lib/jekyll/draft.rb @@ -14,7 +14,7 @@ module Jekyll end # Get the full path to the directory containing the draft files - def get_base(source, dir) + def containing_dir(source, dir) return File.join(source, dir, '_drafts') end diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 2a5bdafa..e4703c0d 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -34,7 +34,7 @@ module Jekyll # Returns the new Post. def initialize(site, source, dir, name) @site = site - @base = self.get_base(source, dir) + @base = self.containing_dir(source, dir) @name = name self.categories = dir.split('/').reject { |x| x.empty? } @@ -66,7 +66,7 @@ module Jekyll end # Get the full path to the directory containing the post files - def get_base(source, dir) + def containing_dir(source, dir) return File.join(source, dir, '_posts') end From ef9388684b35f22cff66fc9e25b01fbc37135701 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 3 Mar 2013 18:04:31 -0800 Subject: [PATCH 12/15] Turn off debug mode on feature to suppress output. --- features/create_sites.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/create_sites.feature b/features/create_sites.feature index 438ee358..cbdfb64b 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -89,7 +89,7 @@ Feature: Create sites And I have an "_includes/about.textile" file that contains "Generated by {% include jekyll.textile %}" And I have an "_includes/jekyll.textile" file that contains "Jekyll" And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}" - When I debug jekyll + When I run jekyll Then the _site directory should exist And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html" From 2b9b61368745f85d0255ac50042922662733d818 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 3 Mar 2013 18:23:02 -0800 Subject: [PATCH 13/15] Normalize CLI options to match configuration expectations. --- bin/jekyll | 19 +++++++++++++++++-- lib/jekyll/site.rb | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 0855ff03..d135b952 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -17,6 +17,19 @@ global_option '--safe', 'Safe mode (defaults to false)' global_option '--plugins', 'Plugins directory (defaults to ./_plugins)' global_option '--layouts', 'Layouts directory (defaults to ./_layouts)' +# Option names don't always directly match the configuration value we'd like. +# This method will rename options to match what Jekyll configuration expects. +# +# options - The Hash of options from Commander. +# +# Returns the normalized Hash. +def normalize_options(options) + if drafts_state = options.delete(:drafts) + options[:show_drafts] = drafts_state + end + options +end + command :build do |c| c.syntax = 'jekyll build [options]' c.description = 'Build your site' @@ -29,7 +42,8 @@ command :build do |c| c.action do |args, options| options.defaults :serving => false - options = Jekyll.configuration(options.__hash__) + options = normalize_options(options.__hash__) + options = Jekyll.configuration(options) Jekyll::Commands::Build.process(options) end end @@ -54,7 +68,8 @@ command :serve do |c| :baseurl => '/', :serving => true - options = Jekyll.configuration(options.__hash__) + options = normalize_options(options.__hash__) + options = Jekyll.configuration(options) Jekyll::Commands::Build.process(options) Jekyll::Commands::Serve.process(options) end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index ad85d42f..18488431 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -25,7 +25,7 @@ module Jekyll self.exclude = config['exclude'] || [] self.include = config['include'] || [] self.future = config['future'] - self.show_drafts = config['drafts'] || nil + self.show_drafts = config['show_drafts'] || nil self.limit_posts = config['limit_posts'] || nil self.keep_files = config['keep_files'] || [] From b46000f6afc3d9632ad870f85f24cd40990e3de9 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 3 Mar 2013 18:43:54 -0800 Subject: [PATCH 14/15] Kill unnecessary return keyword. --- lib/jekyll/draft.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/draft.rb b/lib/jekyll/draft.rb index 32457fac..321a6e58 100644 --- a/lib/jekyll/draft.rb +++ b/lib/jekyll/draft.rb @@ -15,7 +15,7 @@ module Jekyll # Get the full path to the directory containing the draft files def containing_dir(source, dir) - return File.join(source, dir, '_drafts') + File.join(source, dir, '_drafts') end # Extract information from the post filename. From da273b685a699d257ead4d590e861e4c14f9e288 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 3 Mar 2013 18:55:50 -0800 Subject: [PATCH 15/15] Update history for drafts feature. --- History.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/History.txt b/History.txt index d4703de5..cd85b56d 100644 --- a/History.txt +++ b/History.txt @@ -2,6 +2,7 @@ * Major Enhancements * Refactored jekyll commands into subcommands: build, serve, and migrate. (#690) * Removed importers/migrators from main project, migrated to jekyll-import sub-gem (#793) + * Added ability to render drafts in _drafts folder via command line (#833) * Minor Enhancements * Improve debugability of error message for a malformed highlight tag (#785) * Allow symlinked files in unsafe mode (#824)