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/features/create_sites.feature b/features/create_sites.feature index 24e669bc..346c0350 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 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" When I run jekyll diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 626a58a5..c1f4347f 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -8,6 +8,10 @@ Given /^I have a blank site in "(.*)"$/ do |path| FileUtils.mkdir(path) end +Given /^I do not have a "(.*)" directory$/ do |path| + File.directory?("#{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| @@ -113,6 +117,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 a7588d98..efe6b1b6 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -14,6 +14,15 @@ def run_jekyll(opts = {}) system command 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 +end + def slug(title) title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') end diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index c1aa3eef..8757a91b 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -13,14 +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 - 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}." end + def self.create_blank_site(path) + Dir.chdir(path) do + FileUtils.mkdir(%w(_layouts _posts _drafts)) + 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