Merge pull request #1171 from zachgersh/new_empty
Added a --blank command which scaffolds empty files.
This commit is contained in:
commit
fdebe492cc
|
@ -38,6 +38,7 @@ command :new do |c|
|
||||||
c.description = 'Creates a new Jekyll site scaffold in PATH'
|
c.description = 'Creates a new Jekyll site scaffold in PATH'
|
||||||
|
|
||||||
c.option '--force', 'Force creation even if PATH already exists'
|
c.option '--force', 'Force creation even if PATH already exists'
|
||||||
|
c.option '--blank', 'Creates scaffolding but with empty files'
|
||||||
|
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
Jekyll::Commands::New.process(args, options.__hash__)
|
Jekyll::Commands::New.process(args, options.__hash__)
|
||||||
|
|
|
@ -3,6 +3,13 @@ Feature: Create sites
|
||||||
I want to be able to make a static site
|
I want to be able to make a static site
|
||||||
In order to share my awesome ideas with the interwebs
|
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
|
Scenario: Basic site
|
||||||
Given I have an "index.html" file that contains "Basic Site"
|
Given I have an "index.html" file that contains "Basic Site"
|
||||||
When I run jekyll
|
When I run jekyll
|
||||||
|
|
|
@ -8,6 +8,10 @@ Given /^I have a blank site in "(.*)"$/ do |path|
|
||||||
FileUtils.mkdir(path)
|
FileUtils.mkdir(path)
|
||||||
end
|
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
|
# 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|
|
Given /^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$/ do |file, key, value, text|
|
||||||
File.open(file, 'w') do |f|
|
File.open(file, 'w') do |f|
|
||||||
|
@ -113,6 +117,10 @@ When /^I run jekyll with drafts$/ do
|
||||||
run_jekyll(:drafts => true)
|
run_jekyll(:drafts => true)
|
||||||
end
|
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
|
When /^I debug jekyll$/ do
|
||||||
run_jekyll(:debug => true)
|
run_jekyll(:debug => true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,15 @@ def run_jekyll(opts = {})
|
||||||
system command
|
system command
|
||||||
end
|
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)
|
def slug(title)
|
||||||
title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,14 +13,26 @@ module Jekyll
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
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|
|
File.open(File.expand_path(self.initialized_post_name, new_blog_path), "w") do |f|
|
||||||
f.write(self.scaffold_post_content(site_template))
|
f.write(self.scaffold_post_content(site_template))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "New jekyll site installed in #{new_blog_path}."
|
puts "New jekyll site installed in #{new_blog_path}."
|
||||||
end
|
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)
|
def self.scaffold_post_content(template_site)
|
||||||
ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
|
ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue