From 099fcc27d6517310e957a30d7d3ed0a2778ced69 Mon Sep 17 00:00:00 2001 From: Daniel Grieve Date: Wed, 13 Mar 2013 19:21:11 +0000 Subject: [PATCH 1/4] raise ArgumentError if no args. rename sample post --- lib/jekyll/commands/new.rb | 30 +++++++++---------- ...0000-00-00-welcome-to-jekyll.markdown.erb} | 0 2 files changed, 15 insertions(+), 15 deletions(-) rename lib/site_template/_posts/{0000-00-00-sample_post.markdown.erb => 0000-00-00-welcome-to-jekyll.markdown.erb} (100%) diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index dc71545f..103a5950 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -3,8 +3,9 @@ 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 @@ -28,23 +29,22 @@ module Jekyll end private + def self.create_sample_files!(path) + FileUtils.cp_r sample_files, 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.sample_files + Dir.glob("#{template_site}/**/*") + 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.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 diff --git a/lib/site_template/_posts/0000-00-00-sample_post.markdown.erb b/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb similarity index 100% rename from lib/site_template/_posts/0000-00-00-sample_post.markdown.erb rename to lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb From 1ab83ff9e96b83566874a32fea52c9f5ba92e9be Mon Sep 17 00:00:00 2001 From: Daniel Grieve Date: Wed, 13 Mar 2013 19:55:15 +0000 Subject: [PATCH 2/4] fix test to highlight issue with FileUtils.cp_r --- test/test_new_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_new_command.rb b/test/test_new_command.rb index 2532bea8..739fcb13 100644 --- a/test/test_new_command.rb +++ b/test/test_new_command.rb @@ -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) == '.erb' end assert_same_elements static_template_files, new_site_files From 4be5dfdb9a5bcc2befaa057feb13988f909768ef Mon Sep 17 00:00:00 2001 From: Daniel Grieve Date: Wed, 13 Mar 2013 21:27:41 +0000 Subject: [PATCH 3/4] fix copying of site template files --- jekyll.gemspec | 2 +- lib/jekyll/commands/new.rb | 16 ++++++---------- test/test_new_command.rb | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/jekyll.gemspec b/jekyll.gemspec index 8291d9ae..0ebd7f67 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -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 diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index 103a5950..e650dc52 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -9,16 +9,16 @@ module Jekyll 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 @@ -29,16 +29,12 @@ module Jekyll end private - def self.create_sample_files!(path) - FileUtils.cp_r sample_files, path + def self.create_sample_files(path) + FileUtils.cp_r site_template + '/.', path FileUtils.rm File.expand_path(scaffold_path, path) end - def self.sample_files - Dir.glob("#{template_site}/**/*") - end - - def self.template_site + def self.site_template File.expand_path("../../site_template", File.dirname(__FILE__)) end diff --git a/test/test_new_command.rb b/test/test_new_command.rb index 739fcb13..bc9e6585 100644 --- a/test/test_new_command.rb +++ b/test/test_new_command.rb @@ -43,7 +43,7 @@ class TestNewCommand < Test::Unit::TestCase capture_stdout { Jekyll::Commands::New.process(@args) } new_site_files = dir_contents(@full_path).reject do |f| - File.extname(f) == '.erb' + File.extname(f) == '.markdown' end assert_same_elements static_template_files, new_site_files From 5bcc2fd8f9a0690701d6c4b4eafaa5acca0b423a Mon Sep 17 00:00:00 2001 From: Daniel Grieve Date: Wed, 13 Mar 2013 21:57:08 +0000 Subject: [PATCH 4/4] update safe_yaml --- jekyll.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll.gemspec b/jekyll.gemspec index 0ebd7f67..a6efcd62 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -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")