Using modularized commands (Jekyll::Commands) as per @tombell's latest PR merge
This commit is contained in:
parent
f3856a444a
commit
a8671ed52b
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue