Merge pull request #856 from danielgrieve/jekyll-new
Jekyll 'new' command fixes
This commit is contained in:
commit
5bde4a3131
|
@ -30,7 +30,7 @@ Gem::Specification.new do |s|
|
|||
s.add_runtime_dependency('kramdown', "~> 0.13.4")
|
||||
s.add_runtime_dependency('pygments.rb', "~> 0.3.2")
|
||||
s.add_runtime_dependency('commander', "~> 4.1.3")
|
||||
s.add_runtime_dependency('safe_yaml', "~> 0.4")
|
||||
s.add_runtime_dependency('safe_yaml', "~> 0.7.0")
|
||||
|
||||
s.add_development_dependency('rake', "~> 0.9")
|
||||
s.add_development_dependency('rdoc', "~> 3.11")
|
||||
|
@ -113,7 +113,7 @@ Gem::Specification.new do |s|
|
|||
lib/site_template/_config.yml
|
||||
lib/site_template/_layouts/default.html
|
||||
lib/site_template/_layouts/post.html
|
||||
lib/site_template/_posts/0000-00-00-sample_post.markdown.erb
|
||||
lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb
|
||||
lib/site_template/css/screen.css
|
||||
lib/site_template/css/syntax.css
|
||||
lib/site_template/images/.gitkeep
|
||||
|
|
|
@ -3,21 +3,22 @@ require 'erb'
|
|||
module Jekyll
|
||||
module Commands
|
||||
class New < Command
|
||||
|
||||
def self.process(args)
|
||||
raise ArgumentError.new('You must specify a path.') if args.empty?
|
||||
|
||||
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
|
||||
FileUtils.mkdir_p new_blog_path
|
||||
|
||||
create_sample_files! new_blog_path
|
||||
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(template_site))
|
||||
f.write(self.scaffold_post_content(site_template))
|
||||
end
|
||||
puts "New jekyll site installed in #{new_blog_path}."
|
||||
end
|
||||
|
||||
def self.scaffold_post_content(template_site)
|
||||
ERB.new(File.read(File.expand_path(scaffold_path, template_site))).result
|
||||
ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
|
||||
end
|
||||
|
||||
# Internal: Gets the filename of the sample post to be created
|
||||
|
@ -28,23 +29,18 @@ module Jekyll
|
|||
end
|
||||
|
||||
private
|
||||
def self.create_sample_files(path)
|
||||
FileUtils.cp_r site_template + '/.', path
|
||||
FileUtils.rm File.expand_path(scaffold_path, path)
|
||||
end
|
||||
|
||||
def self.create_sample_files!(path)
|
||||
FileUtils.cp_r sample_files, path
|
||||
FileUtils.rm File.expand_path(scaffold_path, path)
|
||||
end
|
||||
def self.site_template
|
||||
File.expand_path("../../site_template", File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
def self.sample_files
|
||||
Dir.glob("#{template_site}/**/*")
|
||||
end
|
||||
|
||||
def self.template_site
|
||||
File.expand_path("../../site_template", File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
def self.scaffold_path
|
||||
"_posts/0000-00-00-sample_post.markdown.erb"
|
||||
end
|
||||
def self.scaffold_path
|
||||
"_posts/0000-00-00-welcome-to-jekyll.markdown.erb"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,8 +42,8 @@ class TestNewCommand < Test::Unit::TestCase
|
|||
|
||||
capture_stdout { Jekyll::Commands::New.process(@args) }
|
||||
|
||||
new_site_files = dir_contents(@full_path).select do |f|
|
||||
static_template_files.include? f
|
||||
new_site_files = dir_contents(@full_path).reject do |f|
|
||||
File.extname(f) == '.markdown'
|
||||
end
|
||||
|
||||
assert_same_elements static_template_files, new_site_files
|
||||
|
|
Loading…
Reference in New Issue