middleman/middleman-core/lib/middleman-core/cli/init.rb

52 lines
1.5 KiB
Ruby
Raw Normal View History

2011-12-29 07:52:51 +01:00
# CLI Module
2011-12-21 21:13:28 +01:00
module Middleman::Cli
2011-12-29 07:52:51 +01:00
# A thor task for creating new projects
2011-12-21 21:13:28 +01:00
class Init < Thor
check_unknown_options!
2011-12-21 21:13:28 +01:00
namespace :init
desc "init NAME [options]", "Create new project NAME"
available_templates = ::Middleman::Templates.registered.keys.join(", ")
2011-12-21 21:13:28 +01:00
method_option "template",
:aliases => "-T",
:default => "default",
:desc => "Use a project template: #{available_templates}"
2011-12-21 21:13:28 +01:00
method_option "css_dir",
# :default => "stylesheets",
:desc => 'The path to the css files'
2011-12-21 21:13:28 +01:00
method_option "js_dir",
# :default => "javascripts",
:desc => 'The path to the javascript files'
2011-12-21 21:13:28 +01:00
method_option "images_dir",
# :default => "images",
:desc => 'The path to the image files'
2011-12-21 21:13:28 +01:00
method_option "rack",
:type => :boolean,
:default => false,
:desc => 'Include a config.ru file'
2011-12-21 21:13:28 +01:00
method_option "bundler",
:type => :boolean,
:default => false,
:desc => 'Create a Gemfile and use Bundler to manage gems'
2011-12-29 07:52:51 +01:00
# The init task
# @param [String] name
2011-12-21 21:13:28 +01:00
def init(name)
key = options[:template].to_sym
unless ::Middleman::Templates.registered.has_key?(key)
raise Thor::Error.new "Unknown project template '#{key}'"
end
thor_group = ::Middleman::Templates.registered[key]
thor_group.new([name], options).invoke_all
end
end
2011-12-29 07:52:51 +01:00
# Map "i", "new" and "n" to "init"
Base.map({
"i" => "init",
"new" => "init",
"n" => "init"
})
end