2011-12-21 21:13:28 +01:00
|
|
|
module Middleman::Cli
|
|
|
|
class Init < Thor
|
2011-12-21 20:03:45 +01:00
|
|
|
check_unknown_options!
|
|
|
|
|
2011-12-21 21:13:28 +01:00
|
|
|
namespace :init
|
|
|
|
|
|
|
|
desc "init NAME [options]", "Create new project NAME"
|
2011-12-21 20:03:45 +01:00
|
|
|
available_templates = ::Middleman::Templates.registered.keys.join(", ")
|
2011-12-21 21:13:28 +01:00
|
|
|
# argument :name
|
|
|
|
method_option "template",
|
2011-12-21 20:03:45 +01:00
|
|
|
:aliases => "-T",
|
|
|
|
:default => "default",
|
|
|
|
:desc => "Use a project template: #{available_templates}"
|
2011-12-21 21:13:28 +01:00
|
|
|
method_option "css_dir",
|
2011-12-21 20:03:45 +01:00
|
|
|
:default => "stylesheets",
|
|
|
|
:desc => 'The path to the css files'
|
2011-12-21 21:13:28 +01:00
|
|
|
method_option "js_dir",
|
2011-12-21 20:03:45 +01:00
|
|
|
:default => "javascripts",
|
|
|
|
:desc => 'The path to the javascript files'
|
2011-12-21 21:13:28 +01:00
|
|
|
method_option "images_dir",
|
2011-12-21 20:03:45 +01:00
|
|
|
:default => "images",
|
|
|
|
:desc => 'The path to the image files'
|
2011-12-21 21:13:28 +01:00
|
|
|
method_option "rack",
|
2011-12-21 20:03:45 +01:00
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
|
|
|
:desc => 'Include a config.ru file'
|
2011-12-21 21:13:28 +01:00
|
|
|
method_option "bundler",
|
2011-12-21 20:03:45 +01:00
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
|
|
|
:desc => 'Create a Gemfile and use Bundler to manage gems'
|
2011-12-21 21:13:28 +01:00
|
|
|
def init(name)
|
2011-12-21 20:03:45 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
Base.map({
|
|
|
|
"i" => "init",
|
|
|
|
"new" => "init",
|
|
|
|
"n" => "init"
|
|
|
|
})
|
|
|
|
end
|