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 132 133 134 135 136 137 138 139
|
require 'compass/commands/project_base'
require 'compass/compiler'
module Compass
module Commands
module CompileProjectOptionsParser
def set_options(opts)
opts.banner = %Q{
Usage: compass compile [path/to/project] [path/to/project/src/file.sass ...] [options]
Description:
compile project at the path specified or the current director if not specified.
Options:
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n")
opts.on("--time", "Display compilation times.") do
self.options[:time] = true
end
opts.on("--debug-info", "Turns on sass's debuging information") do
self.options[:debug_info]= true
end
opts.on("--no-debug-info", "Turns off sass's debuging information") do
self.options[:debug_info]= false
end
super
end
end
class UpdateProject < ProjectBase
register :compile
def initialize(working_path, options)
super
assert_project_directory_exists! unless dry_run?
end
def perform
compiler = new_compiler_instance
check_for_sass_files!(compiler)
compiler.clean! if compiler.new_config?
error_count = compiler.run
failed! if error_count > 0
end
def check_for_sass_files!(compiler)
if compiler.sass_files.empty? && !dry_run?
message = "Nothing to compile. If you're trying to start a new project, you have left off the directory argument.\n"
message << "Run \"compass -h\" to get help."
raise Compass::Error, message
end
end
def dry_run?
options[:dry_run]
end
def new_compiler_instance(additional_options = {})
@compiler_opts ||= begin
compiler_opts = {:sass => Compass.sass_engine_options}
compiler_opts.merge!(options)
compiler_opts[:sass_files] = explicit_sass_files
compiler_opts[:cache_location] = determine_cache_location
if options.include?(:debug_info) && options[:debug_info]
compiler_opts[:sass][:debug_info] = options.delete(:debug_info)
end
compiler_opts
end
@memory_store ||= Sass::CacheStores::Memory.new
@backing_store ||= compiler_opts[:cache_store]
@backing_store ||= Sass::CacheStores::Filesystem.new(determine_cache_location)
@cache_store ||= Sass::CacheStores::Chain.new(@memory_store, @backing_store)
@memory_store.reset!
Compass::Compiler.new(
working_path,
Compass.configuration.sass_path,
Compass.configuration.css_path,
@compiler_opts.merge(:cache_store => @cache_store).merge(additional_options)
)
end
def explicit_sass_files
return unless options[:sass_files]
options[:sass_files].map do |sass_file|
if absolute_path? sass_file
sass_file
else
File.join(Dir.pwd, sass_file)
end
end
end
def determine_cache_location
Compass.configuration.cache_path || Sass::Plugin.options[:cache_location] || File.join(working_path, ".sass-cache")
end
class << self
def option_parser(arguments)
parser = Compass::Exec::CommandOptionParser.new(arguments)
parser.extend(Compass::Exec::GlobalOptionsParser)
parser.extend(Compass::Exec::ProjectOptionsParser)
parser.extend(CompileProjectOptionsParser)
end
def usage
option_parser([]).to_s
end
def primary; true; end
def description(command)
"Compile Sass stylesheets to CSS"
end
def parse!(arguments)
parser = option_parser(arguments)
parser.parse!
parse_arguments!(parser, arguments)
parser.options
end
def parse_arguments!(parser, arguments)
if arguments.size > 0
parser.options[:project_name] = arguments.shift if File.directory?(arguments.first)
unless arguments.empty?
parser.options[:sass_files] = arguments.dup
parser.options[:force] = true
end
end
end
end
end
end
end
|