From a21031eae967869e8d345e0115c0adb10342341f Mon Sep 17 00:00:00 2001 From: zachgersh Date: Sun, 2 Jun 2013 13:21:41 -0700 Subject: [PATCH 01/10] Added a --blank command which scaffolds empty files. --- bin/jekyll | 1 + lib/jekyll/commands/new.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/bin/jekyll b/bin/jekyll index f5d82931..a32e8112 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -38,6 +38,7 @@ command :new do |c| c.description = 'Creates a new Jekyll site scaffold in PATH' c.option '--force', 'Force creation even if PATH already exists' + c.option '--blank', 'Creates scaffolding but with empty files' c.action do |args, options| Jekyll::Commands::New.process(args, options.__hash__) diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index c1aa3eef..7a2cefcc 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -18,6 +18,12 @@ module Jekyll File.open(File.expand_path(self.initialized_post_name, new_blog_path), "w") do |f| f.write(self.scaffold_post_content(site_template)) end + + if options[:blank] + files_to_clear = Dir.glob("#{new_blog_path}/**/*.*") + files_to_clear.each {|file| File.truncate("#{file}", 0)} + end + puts "New jekyll site installed in #{new_blog_path}." end From 16314ee4a25227380ed070dc27a9e2c421ba4ca4 Mon Sep 17 00:00:00 2001 From: zachgersh Date: Mon, 3 Jun 2013 22:52:40 -0700 Subject: [PATCH 02/10] New leaving empty layouts / posts dirs and empty index.html. --- lib/jekyll/commands/new.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index 7a2cefcc..0139c661 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -20,8 +20,15 @@ module Jekyll end if options[:blank] - files_to_clear = Dir.glob("#{new_blog_path}/**/*.*") - files_to_clear.each {|file| File.truncate("#{file}", 0)} + file_to_truncate = "#{new_blog_path}/index.html" + file_list = [Dir.glob("#{new_blog_path}/**/_layouts/*"), + Dir.glob("#{new_blog_path}/**/_posts/*")] + + FileUtils.rm_rf Dir.glob("#{new_blog_path}/**/css") + FileUtils.rm Dir.glob("#{new_blog_path}/**/_config.yml") + + FileUtils.rm_rf(file_list) + File.truncate(file_to_truncate, 0) end puts "New jekyll site installed in #{new_blog_path}." From 7fba828f027abe04288a4aacb4ff575bfa0229f0 Mon Sep 17 00:00:00 2001 From: zachgersh Date: Mon, 3 Jun 2013 22:53:30 -0700 Subject: [PATCH 03/10] The start of something cucumber. --- features/support/env.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/features/support/env.rb b/features/support/env.rb index a7588d98..6f24647b 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -14,6 +14,14 @@ def run_jekyll(opts = {}) system command end +def call_jekyll_new(opts = {}) + command = JEKYLL_PATH.clone + command << " new" + command << " --blank" if opts[:blank] + command << " >> /dev/null 2>&1" if opts[:debug].nil? + system command +end + def slug(title) title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') end From b19997aee45f2a07357cbeac37f91dfd98b07b04 Mon Sep 17 00:00:00 2001 From: zachgersh Date: Tue, 4 Jun 2013 00:05:54 -0700 Subject: [PATCH 04/10] Broken test committed. Can't find proper directories. --- features/create_sites.feature | 7 +++++++ features/step_definitions/jekyll_steps.rb | 16 ++++++++++++---- features/support/env.rb | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/features/create_sites.feature b/features/create_sites.feature index 24e669bc..8d85f084 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -3,6 +3,13 @@ Feature: Create sites I want to be able to make a static site In order to share my awesome ideas with the interwebs + Scenario: Blank site + Given I do not have a "test_blank" directory + When I call jekyll new with test_blank --blank + Then the _layouts directory should exist + And the _posts directory should exist + And the "index.html" file should exist + Scenario: Basic site Given I have an "index.html" file that contains "Basic Site" When I run jekyll diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 7a1c7cd1..97567255 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -4,15 +4,19 @@ Before do Dir.chdir(TEST_DIR) end -After do - Dir.chdir(File.expand_path("..", TEST_DIR)) - FileUtils.rm_rf(TEST_DIR) -end +#After do +# Dir.chdir(File.expand_path("..", TEST_DIR)) +# FileUtils.rm_rf(TEST_DIR) +#end Given /^I have a blank site in "(.*)"$/ do |path| FileUtils.mkdir(path) end +Given /^I do not have a "(.*)" directory$/ do |path| + Dir.exists?("#{TEST_DIR}/#{path}") +end + # Like "I have a foo file" but gives a yaml front matter so jekyll actually processes it Given /^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$/ do |file, key, value, text| File.open(file, 'w') do |f| @@ -118,6 +122,10 @@ When /^I run jekyll with drafts$/ do run_jekyll(:drafts => true) end +When /^I call jekyll new with test_blank --blank$/ do + call_jekyll_new(:path => "test_blank", :blank => 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 6f24647b..efe6b1b6 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -17,6 +17,7 @@ end def call_jekyll_new(opts = {}) command = JEKYLL_PATH.clone command << " new" + command << " #{opts[:path]}" if opts[:path] command << " --blank" if opts[:blank] command << " >> /dev/null 2>&1" if opts[:debug].nil? system command From 3fdeb8c59149940fb37dcba4b66311e768460e1f Mon Sep 17 00:00:00 2001 From: zachgersh Date: Tue, 4 Jun 2013 00:43:33 -0700 Subject: [PATCH 05/10] Fixed my tests, I need more specific tests for the new command. --- features/create_sites.feature | 6 +++--- features/step_definitions/jekyll_steps.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/features/create_sites.feature b/features/create_sites.feature index 8d85f084..b84fac8a 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -6,9 +6,9 @@ Feature: Create sites Scenario: Blank site Given I do not have a "test_blank" directory When I call jekyll new with test_blank --blank - Then the _layouts directory should exist - And the _posts directory should exist - And the "index.html" file should exist + Then the _layouts directory should exist in the test_blank path + And the _posts directory should exist in the test_blank path + And the "index.html" file should exist in the test_blank path Scenario: Basic site Given I have an "index.html" file that contains "Basic Site" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 97567255..602b25db 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -140,6 +140,15 @@ Then /^the (.*) directory should exist$/ do |dir| assert File.directory?(dir), "The directory \"#{dir}\" does not exist" end +Then /^the "(.*)" file should exist in the (.*) path$/ do |file, path| + assert File.file?("#{TEST_DIR}/#{path}/#{file}") +end + +Then /^the (.*) directory should exist in the (.*) path$/ do |dir, path| + assert File.directory?("#{TEST_DIR}/#{path}/#{dir}"), + "The directory \"#{dir}\" does not exist" +end + Then /^I should see "(.*)" in "(.*)"$/ do |text, file| assert Regexp.new(text).match(File.open(file).readlines.join) end From 44cfa0540face9970aae704096aa75d8d1e080ae Mon Sep 17 00:00:00 2001 From: zachgersh Date: Tue, 4 Jun 2013 00:53:47 -0700 Subject: [PATCH 06/10] Switch it to file.exists? and File.directory? so 1.8.7 doesn't complain. --- features/step_definitions/jekyll_steps.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 602b25db..cede6bdb 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -14,7 +14,7 @@ Given /^I have a blank site in "(.*)"$/ do |path| end Given /^I do not have a "(.*)" directory$/ do |path| - Dir.exists?("#{TEST_DIR}/#{path}") + File.directory?("#{TEST_DIR}/#{path}") end # Like "I have a foo file" but gives a yaml front matter so jekyll actually processes it @@ -141,7 +141,7 @@ Then /^the (.*) directory should exist$/ do |dir| end Then /^the "(.*)" file should exist in the (.*) path$/ do |file, path| - assert File.file?("#{TEST_DIR}/#{path}/#{file}") + assert File.exists?("#{TEST_DIR}/#{path}/#{file}") end Then /^the (.*) directory should exist in the (.*) path$/ do |dir, path| From eb06cf0d3d73d795c425c5f8ac05dc85e8f0559b Mon Sep 17 00:00:00 2001 From: zachgersh Date: Tue, 4 Jun 2013 07:22:00 -0700 Subject: [PATCH 07/10] Adding back the removal of the TEST_DIR. Thanks to sharp eyes. --- features/step_definitions/jekyll_steps.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index cede6bdb..abdf07d3 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -4,10 +4,10 @@ Before do Dir.chdir(TEST_DIR) end -#After do -# Dir.chdir(File.expand_path("..", TEST_DIR)) -# FileUtils.rm_rf(TEST_DIR) -#end +After do + Dir.chdir(File.expand_path("..", TEST_DIR)) + FileUtils.rm_rf(TEST_DIR) +end Given /^I have a blank site in "(.*)"$/ do |path| FileUtils.mkdir(path) From a3d53a74bec6d1fa5f47ddbcbcf8bf6fe045105d Mon Sep 17 00:00:00 2001 From: zachgersh Date: Tue, 4 Jun 2013 21:34:53 -0700 Subject: [PATCH 08/10] Refactored per @parkr suggestions. Much cleaner. --- lib/jekyll/commands/new.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index 0139c661..348c4f47 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -13,27 +13,26 @@ module Jekyll exit(1) end - create_sample_files new_blog_path + if options[:blank] + create_blank_site new_blog_path + else + create_sample_files new_blog_path + end File.open(File.expand_path(self.initialized_post_name, new_blog_path), "w") do |f| f.write(self.scaffold_post_content(site_template)) end - if options[:blank] - file_to_truncate = "#{new_blog_path}/index.html" - file_list = [Dir.glob("#{new_blog_path}/**/_layouts/*"), - Dir.glob("#{new_blog_path}/**/_posts/*")] - - FileUtils.rm_rf Dir.glob("#{new_blog_path}/**/css") - FileUtils.rm Dir.glob("#{new_blog_path}/**/_config.yml") - - FileUtils.rm_rf(file_list) - File.truncate(file_to_truncate, 0) - end - puts "New jekyll site installed in #{new_blog_path}." end + def self.create_blank_site(path) + Dir.chdir(path) do + FileUtils.mkdir(%w(_layouts _posts)) + FileUtils.touch("index.html") + end + end + def self.scaffold_post_content(template_site) ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result end From 042c960df06118c87fe349e4b40513e73444ce27 Mon Sep 17 00:00:00 2001 From: zachgersh Date: Wed, 5 Jun 2013 07:58:50 -0700 Subject: [PATCH 09/10] Moved md post into else block. Added _drafts blank dir. --- lib/jekyll/commands/new.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index 348c4f47..8757a91b 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -17,10 +17,10 @@ module Jekyll create_blank_site new_blog_path else create_sample_files new_blog_path - end - File.open(File.expand_path(self.initialized_post_name, new_blog_path), "w") do |f| - f.write(self.scaffold_post_content(site_template)) + File.open(File.expand_path(self.initialized_post_name, new_blog_path), "w") do |f| + f.write(self.scaffold_post_content(site_template)) + end end puts "New jekyll site installed in #{new_blog_path}." @@ -28,7 +28,7 @@ module Jekyll def self.create_blank_site(path) Dir.chdir(path) do - FileUtils.mkdir(%w(_layouts _posts)) + FileUtils.mkdir(%w(_layouts _posts _drafts)) FileUtils.touch("index.html") end end From 270ad54eb365466c0e87593650b7ce616427e94c Mon Sep 17 00:00:00 2001 From: zachgersh Date: Mon, 10 Jun 2013 12:03:08 -0700 Subject: [PATCH 10/10] Removed extra steps and refactored my tests thanks to Maul. --- features/create_sites.feature | 6 +++--- features/step_definitions/jekyll_steps.rb | 9 --------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/features/create_sites.feature b/features/create_sites.feature index b84fac8a..346c0350 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -6,9 +6,9 @@ Feature: Create sites Scenario: Blank site Given I do not have a "test_blank" directory When I call jekyll new with test_blank --blank - Then the _layouts directory should exist in the test_blank path - And the _posts directory should exist in the test_blank path - And the "index.html" file should exist in the test_blank path + Then the test_blank/_layouts directory should exist + And the test_blank/_posts directory should exist + And the "test_blank/index.html" file should exist Scenario: Basic site Given I have an "index.html" file that contains "Basic Site" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index abdf07d3..afd20dd2 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -140,15 +140,6 @@ Then /^the (.*) directory should exist$/ do |dir| assert File.directory?(dir), "The directory \"#{dir}\" does not exist" end -Then /^the "(.*)" file should exist in the (.*) path$/ do |file, path| - assert File.exists?("#{TEST_DIR}/#{path}/#{file}") -end - -Then /^the (.*) directory should exist in the (.*) path$/ do |dir, path| - assert File.directory?("#{TEST_DIR}/#{path}/#{dir}"), - "The directory \"#{dir}\" does not exist" -end - Then /^I should see "(.*)" in "(.*)"$/ do |text, file| assert Regexp.new(text).match(File.open(file).readlines.join) end