From c48de6b320b3a6d48407b82d9005b9c854d152de Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 20 Jan 2013 04:38:23 +0200 Subject: [PATCH] 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