From a8671ed52b116d6f7bd489d2ee34204d32296d7e Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 27 Jan 2013 23:17:45 +0100 Subject: [PATCH] Using modularized commands (Jekyll::Commands) as per @tombell's latest PR merge --- bin/jekyll | 2 +- lib/jekyll/commands/new.rb | 46 ++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 3db3f672..6c3577c5 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -22,7 +22,7 @@ command :new do |c| c.description = 'Creates a new Jekyll site scaffold in PATH' c.action do |args, options| - Jekyll::NewCommand.process(args) + Jekyll::Commands::New.process(args) end end diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index 9b7e930e..51152429 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -1,31 +1,33 @@ require 'yaml' module Jekyll - class NewCommand < Command + module Commands + class New < Command - def self.process(args) - path = File.expand_path(args.join(" "), Dir.pwd) - template_site = File.expand_path("../../site_template", File.dirname(__FILE__)) - FileUtils.mkdir_p path - FileUtils.cp_r Dir["#{template_site}/*"], path - File.open(File.expand_path(self.initialized_post_name, path), "w") do |f| - content = [ - { "layout" => "post", "title" => "Welcome to Jekyll!", "date" => Time.now.strftime('%Y-%m-%d %H:%M:%S'), "categories" => %w(jekyll update) }.to_yaml + "---", - "You'll find this post in your `_posts` directory - edit this post and re-build (or run with the `-w` switch) to see your changes!", - "To add new posts, simply add a file in the `_posts` directory that follows the convention: YYYY-MM-DD-name-of-post.ext.", - "Check out the [Jeyll docs][jekyll] for more info on how to get the most out of Jekyll. File all bugs/feature requests at [Jekyll's GitHub repo][jekyll-gh].", - "[jekyll-gh]: https://github.com/mojombo/github\n[jekyll]: http://jekyllrb.com" - ] - f.write(content.join("#{$/*2}")) + def self.process(args) + path = File.expand_path(args.join(" "), Dir.pwd) + template_site = File.expand_path("../../site_template", File.dirname(__FILE__)) + FileUtils.mkdir_p path + FileUtils.cp_r Dir["#{template_site}/*"], path + File.open(File.expand_path(self.initialized_post_name, path), "w") do |f| + content = [ + { "layout" => "post", "title" => "Welcome to Jekyll!", "date" => Time.now.strftime('%Y-%m-%d %H:%M:%S'), "categories" => %w(jekyll update) }.to_yaml + "---", + "You'll find this post in your `_posts` directory - edit this post and re-build (or run with the `-w` switch) to see your changes!", + "To add new posts, simply add a file in the `_posts` directory that follows the convention: YYYY-MM-DD-name-of-post.ext.", + "Check out the [Jeyll docs][jekyll] for more info on how to get the most out of Jekyll. File all bugs/feature requests at [Jekyll's GitHub repo][jekyll-gh].", + "[jekyll-gh]: https://github.com/mojombo/github\n[jekyll]: http://jekyllrb.com" + ] + f.write(content.join("#{$/*2}")) + end + puts "New jekyll site installed in #{path}." end - puts "New jekyll site installed in #{path}." - end - # Internal: Gets the filename of the sample post to be created - # - # Returns the filename of the sample post, as a String - def self.initialized_post_name - "_posts/#{Time.now.strftime('%Y-%m-%d')}-welcome-to-jekyll.markdown" + # Internal: Gets the filename of the sample post to be created + # + # Returns the filename of the sample post, as a String + def self.initialized_post_name + "_posts/#{Time.now.strftime('%Y-%m-%d')}-welcome-to-jekyll.markdown" + end end end end \ No newline at end of file