[Command Line] Specification of sass files to compile

The command line compiler now lets you target specific sass files for
compilation. When specified explicitly, the sass files are always
compiled even if they are older than the corresponding css file (--force
is implied).

Usage Examples:

From the project directory:
compass compile src/screen.sass src/ie.sass

From another directory:
compass compile my_project my_project/src/screen.sass my_project/src/ie.sass
This commit is contained in:
Chris Eppstein 2009-12-16 08:42:51 -08:00
parent a3cdf182c9
commit 6d6e1ca0e3
4 changed files with 46 additions and 8 deletions

View File

@ -120,6 +120,26 @@ Feature: Command Line
And a sass file sass/reset.sass is reported unchanged And a sass file sass/reset.sass is reported unchanged
And a sass file sass/utilities.sass is reported unchanged And a sass file sass/utilities.sass is reported unchanged
Scenario: compiling a specific file in a project
Given I am using the existing project in test/fixtures/stylesheets/compass
And I run: compass compile sass/utilities.sass
Then a sass file sass/layout.sass is not mentioned
And a sass file sass/print.sass is not mentioned
And a sass file sass/reset.sass is not mentioned
And a sass file sass/utilities.sass is reported compiled
And a css file tmp/utilities.css is reported created
And a css file tmp/utilities.css is created
Scenario: Re-compiling a specific file in a project with no changes
Given I am using the existing project in test/fixtures/stylesheets/compass
When I run: compass compile
And I run: compass compile sass/utilities.sass
Then a sass file sass/layout.sass is not mentioned
And a sass file sass/print.sass is not mentioned
And a sass file sass/reset.sass is not mentioned
And a sass file sass/utilities.sass is reported compiled
And a css file tmp/utilities.css is reported identical
Scenario: Installing a pattern into a project Scenario: Installing a pattern into a project
Given I am using the existing project in test/fixtures/stylesheets/compass Given I am using the existing project in test/fixtures/stylesheets/compass
When I run: compass install blueprint/buttons When I run: compass install blueprint/buttons
@ -129,7 +149,6 @@ Feature: Command Line
And an image file images/buttons/tick.png is created And an image file images/buttons/tick.png is created
And a css file tmp/buttons.css is created And a css file tmp/buttons.css is created
@now
Scenario: Basic help Scenario: Basic help
When I run: compass help When I run: compass help
Then I should see the following "primary" commands: Then I should see the following "primary" commands:

View File

@ -135,6 +135,10 @@ Then /a \w+ file ([^ ]+) is reported overwritten/ do |filename|
@last_result.should =~ /overwrite #{Regexp.escape(filename)}/ @last_result.should =~ /overwrite #{Regexp.escape(filename)}/
end end
Then /a \w+ file ([^ ]+) is not mentioned/ do |filename|
@last_result.should_not =~ /#{Regexp.escape(filename)}/
end
Then /I am told how to link to ([^ ]+) for media "([^"]+)"/ do |stylesheet, media| Then /I am told how to link to ([^ ]+) for media "([^"]+)"/ do |stylesheet, media|
@last_result.should =~ %r{<link href="#{stylesheet}" media="#{media}" rel="stylesheet" type="text/css" />} @last_result.should =~ %r{<link href="#{stylesheet}" media="#{media}" rel="stylesheet" type="text/css" />}
end end

View File

@ -6,7 +6,7 @@ module Compass
module CompileProjectOptionsParser module CompileProjectOptionsParser
def set_options(opts) def set_options(opts)
opts.banner = %Q{ opts.banner = %Q{
Usage: compass compile [path/to/project] [options] Usage: compass compile [path/to/project] [path/to/project/src/file.sass ...] [options]
Description: Description:
compile project at the path specified or the current director if not specified. compile project at the path specified or the current director if not specified.
@ -47,9 +47,22 @@ module Compass
projectize(Compass.configuration.sass_dir), projectize(Compass.configuration.sass_dir),
projectize(Compass.configuration.css_dir), projectize(Compass.configuration.css_dir),
Compass.sass_engine_options.merge(:quiet => options[:quiet], Compass.sass_engine_options.merge(:quiet => options[:quiet],
:force => options[:force]).merge(additional_options)) :force => options[:force],
:sass_files => explicit_sass_files).merge(additional_options))
end 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
class << self class << self
def option_parser(arguments) def option_parser(arguments)
parser = Compass::Exec::CommandOptionParser.new(arguments) parser = Compass::Exec::CommandOptionParser.new(arguments)
@ -76,10 +89,12 @@ module Compass
end end
def parse_arguments!(parser, arguments) def parse_arguments!(parser, arguments)
if arguments.size == 1 if arguments.size > 0
parser.options[:project_name] = arguments.shift parser.options[:project_name] = arguments.shift if File.directory?(arguments.first)
elsif arguments.size > 1 unless arguments.empty?
raise Compass::Error, "Too many arguments were specified." parser.options[:sass_files] = arguments.dup
parser.options[:force] = true
end
end end
end end
end end

View File

@ -15,7 +15,7 @@ module Compass
def sass_files(options = {}) def sass_files(options = {})
exclude_partials = options.fetch(:exclude_partials, true) exclude_partials = options.fetch(:exclude_partials, true)
@sass_files || Dir.glob(separate("#{from}/**/#{'[^_]' if exclude_partials}*.sass")) @sass_files = self.options[:sass_files] || Dir.glob(separate("#{from}/**/#{'[^_]' if exclude_partials}*.sass"))
end end
def stylesheet_name(sass_file) def stylesheet_name(sass_file)