1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
require 'fileutils'
require 'compass/commands/stamp_pattern'
module Compass
module Commands
module CreateProjectOptionsParser
def set_options(opts)
if $command == "create"
opts.banner = %Q{
Usage: compass create path/to/project [options]
Description:
Create a new compass project at the path specified.
Options:
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n")
opts.on_tail("--bare", "Don't generate any Sass or CSS files.") do
self.options[:bare] = true
end
else
opts.banner = %Q{
Usage: compass init project_type path/to/project [options]
Description:
Initialize an existing project at the path specified.
Supported Project Types:
* rails
Options:
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n").strip
end
opts.on("--using PATTERN", "A framework's pattern to use when creating the project.") do |framework|
framework = framework.split('/', 2)
self.options[:framework] = framework[0]
self.options[:pattern] = framework[1]
end
opts.on("-x", "--syntax SYNTAX", [:sass, :scss], "Specify the syntax to use when generating stylesheets.", "One of sass or scss. Defaults to scss.") do |syntax|
self.options[:preferred_syntax] = syntax
end
opts.on("--prepare", "Prepare the project by only creating configuration files.") do
self.options[:prepare] = true
end
super
end
end
class CreateProject < StampPattern
register :create
register :init
class << self
def option_parser(arguments)
parser = Compass::Exec::CommandOptionParser.new(arguments)
parser.extend(Compass::Exec::GlobalOptionsParser)
parser.extend(Compass::Exec::ProjectOptionsParser)
parser.extend(CreateProjectOptionsParser)
end
def usage
option_parser([]).to_s
end
def description(command)
if command.to_sym == :create
"Create a new compass project"
else
"Add compass to an existing project"
end
end
def primary; true; end
def parse!(arguments)
parser = option_parser(arguments)
parse_options!(parser, arguments)
parse_arguments!(parser, arguments)
if parser.options[:framework] && parser.options[:bare]
raise Compass::Error, "A bare project cannot be created when a framework is specified."
end
set_default_arguments(parser)
parser.options
end
def parse_init!(arguments)
parser = option_parser(arguments)
parse_options!(parser, arguments)
if arguments.size > 0
parser.options[:project_type] = arguments.shift.to_sym
end
parse_arguments!(parser, arguments)
set_default_arguments(parser)
parser.options
end
def parse_options!(parser, arguments)
parser.parse!
parser
end
def parse_arguments!(parser, arguments)
if arguments.size == 1
parser.options[:project_name] = arguments.shift
elsif arguments.size == 0
# default to the current directory.
else
raise Compass::Error, "Too many arguments were specified."
end
end
def set_default_arguments(parser)
parser.options[:framework] ||= :compass
parser.options[:pattern] ||= "project"
end
end
def is_project_creation?
true
end
end
end
end
|