New subcommand: compile
This commit is contained in:
parent
f9c5644dcc
commit
c8df3f3c42
@ -4,7 +4,7 @@ Feature: Command Line
|
|||||||
I want to create a new project
|
I want to create a new project
|
||||||
|
|
||||||
Scenario: Install a project without a framework
|
Scenario: Install a project without a framework
|
||||||
When I run: compass create my_project
|
When I create a project using: compass create my_project
|
||||||
Then a directory my_project/ is created
|
Then a directory my_project/ is created
|
||||||
And a configuration file my_project/config.rb is created
|
And a configuration file my_project/config.rb is created
|
||||||
And a sass file my_project/src/screen.sass is created
|
And a sass file my_project/src/screen.sass is created
|
||||||
@ -21,7 +21,7 @@ Feature: Command Line
|
|||||||
And I am told how to conditionally link "IE" to /stylesheets/ie.css for media "screen, projection"
|
And I am told how to conditionally link "IE" to /stylesheets/ie.css for media "screen, projection"
|
||||||
|
|
||||||
Scenario: Install a project with blueprint
|
Scenario: Install a project with blueprint
|
||||||
When I run: compass create bp_project --using blueprint
|
When I create a project using: compass create bp_project --using blueprint
|
||||||
Then a directory bp_project/ is created
|
Then a directory bp_project/ is created
|
||||||
And a configuration file bp_project/config.rb is created
|
And a configuration file bp_project/config.rb is created
|
||||||
And a sass file bp_project/src/screen.sass is created
|
And a sass file bp_project/src/screen.sass is created
|
||||||
@ -39,7 +39,7 @@ Feature: Command Line
|
|||||||
And I am told how to conditionally link "lt IE 8" to /stylesheets/ie.css for media "screen, projection"
|
And I am told how to conditionally link "lt IE 8" to /stylesheets/ie.css for media "screen, projection"
|
||||||
|
|
||||||
Scenario: Install a project with specific directories
|
Scenario: Install a project with specific directories
|
||||||
When I run: compass create custom_project --using blueprint --sass-dir sass --css-dir css --images-dir assets/imgs
|
When I create a project using: compass create custom_project --using blueprint --sass-dir sass --css-dir css --images-dir assets/imgs
|
||||||
Then a directory custom_project/ is created
|
Then a directory custom_project/ is created
|
||||||
And a directory custom_project/sass/ is created
|
And a directory custom_project/sass/ is created
|
||||||
And a directory custom_project/css/ is created
|
And a directory custom_project/css/ is created
|
||||||
@ -49,7 +49,7 @@ Feature: Command Line
|
|||||||
And an image file custom_project/assets/imgs/grid.png is created
|
And an image file custom_project/assets/imgs/grid.png is created
|
||||||
|
|
||||||
Scenario: Perform a dry run of creating a project
|
Scenario: Perform a dry run of creating a project
|
||||||
When I run: compass create my_project --dry-run
|
When I create a project using: compass create my_project --dry-run
|
||||||
Then a directory my_project/ is not created
|
Then a directory my_project/ is not created
|
||||||
But a configuration file my_project/config.rb is reported created
|
But a configuration file my_project/config.rb is reported created
|
||||||
And a sass file my_project/src/screen.sass is reported created
|
And a sass file my_project/src/screen.sass is reported created
|
||||||
@ -60,7 +60,7 @@ Feature: Command Line
|
|||||||
And I am told how to conditionally link "IE" to /stylesheets/ie.css for media "screen, projection"
|
And I am told how to conditionally link "IE" to /stylesheets/ie.css for media "screen, projection"
|
||||||
|
|
||||||
Scenario: Creating a bare project
|
Scenario: Creating a bare project
|
||||||
When I run: compass create bare_project --bare
|
When I create a project using: compass create bare_project --bare
|
||||||
Then a directory bare_project/ is created
|
Then a directory bare_project/ is created
|
||||||
And a configuration file bare_project/config.rb is created
|
And a configuration file bare_project/config.rb is created
|
||||||
And a directory bare_project/src/ is created
|
And a directory bare_project/src/ is created
|
||||||
@ -70,6 +70,54 @@ Feature: Command Line
|
|||||||
And I am told how to compile my sass stylesheets
|
And I am told how to compile my sass stylesheets
|
||||||
|
|
||||||
Scenario: Creating a bare project with a framework
|
Scenario: Creating a bare project with a framework
|
||||||
When I run: compass create bare_project --using blueprint --bare
|
When I create a project using: compass create bare_project --using blueprint --bare
|
||||||
Then an error message is printed out: A bare project cannot be created when a framework is specified.
|
Then an error message is printed out: A bare project cannot be created when a framework is specified.
|
||||||
And the command exits with a non-zero error code
|
And the command exits with a non-zero error code
|
||||||
|
|
||||||
|
Scenario: Compiling an existing project.
|
||||||
|
Given I am using the existing project in test/fixtures/stylesheets/compass
|
||||||
|
When I run: compass compile
|
||||||
|
Then a directory tmp/ is created
|
||||||
|
And a sass file sass/layout.sass is reported compiled
|
||||||
|
And a sass file sass/print.sass is reported compiled
|
||||||
|
And a sass file sass/reset.sass is reported compiled
|
||||||
|
And a sass file sass/utilities.sass is reported compiled
|
||||||
|
And a css file tmp/layout.css is created
|
||||||
|
And a css file tmp/print.css is created
|
||||||
|
And a css file tmp/reset.css is created
|
||||||
|
And a css file tmp/utilities.css is created
|
||||||
|
|
||||||
|
Scenario: Compiling an existing project with a specified project
|
||||||
|
Given I am using the existing project in test/fixtures/stylesheets/compass
|
||||||
|
And I am in the parent directory
|
||||||
|
When I run: compass compile tmp_compass
|
||||||
|
Then a directory tmp_compass/tmp/ is created
|
||||||
|
And a sass file tmp_compass/sass/layout.sass is reported compiled
|
||||||
|
And a sass file tmp_compass/sass/print.sass is reported compiled
|
||||||
|
And a sass file tmp_compass/sass/reset.sass is reported compiled
|
||||||
|
And a sass file tmp_compass/sass/utilities.sass is reported compiled
|
||||||
|
And a css file tmp_compass/tmp/layout.css is created
|
||||||
|
And a css file tmp_compass/tmp/print.css is created
|
||||||
|
And a css file tmp_compass/tmp/reset.css is created
|
||||||
|
And a css file tmp_compass/tmp/utilities.css is created
|
||||||
|
|
||||||
|
Scenario: Recompiling 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
|
||||||
|
Then a sass file sass/layout.sass is reported unchanged
|
||||||
|
And a sass file sass/print.sass is reported unchanged
|
||||||
|
And a sass file sass/reset.sass is reported unchanged
|
||||||
|
And a sass file sass/utilities.sass is reported unchanged
|
||||||
|
|
||||||
|
Scenario: Recompiling a project with no material changes
|
||||||
|
Given I am using the existing project in test/fixtures/stylesheets/compass
|
||||||
|
When I run: compass compile
|
||||||
|
And I wait 1 second
|
||||||
|
And I touch sass/layout.sass
|
||||||
|
And I run: compass compile
|
||||||
|
Then a sass file sass/layout.sass is reported compiled
|
||||||
|
Then a css file tmp/layout.css is reported identical
|
||||||
|
And a sass file sass/print.sass is reported unchanged
|
||||||
|
And a sass file sass/reset.sass is reported unchanged
|
||||||
|
And a sass file sass/utilities.sass is reported unchanged
|
||||||
|
@ -10,25 +10,48 @@ include Compass::IoHelper
|
|||||||
|
|
||||||
Before do
|
Before do
|
||||||
@cleanup_directories = []
|
@cleanup_directories = []
|
||||||
|
@original_working_directory = Dir.pwd
|
||||||
end
|
end
|
||||||
|
|
||||||
After do
|
After do
|
||||||
|
Dir.chdir @original_working_directory
|
||||||
@cleanup_directories.each do |dir|
|
@cleanup_directories.each do |dir|
|
||||||
FileUtils.rm_rf dir
|
FileUtils.rm_rf dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
When /I run: compass create ([^\s]+) ?(.+)?/ do |dir, args|
|
# Given Preconditions
|
||||||
|
Given %r{^I am using the existing project in ([^\s]+)$} do |project|
|
||||||
|
tmp_project = "tmp_#{File.basename(project)}"
|
||||||
|
@cleanup_directories << tmp_project
|
||||||
|
FileUtils.cp_r project, tmp_project
|
||||||
|
Dir.chdir tmp_project
|
||||||
|
end
|
||||||
|
|
||||||
|
Given %r{^I am in the parent directory$} do
|
||||||
|
Dir.chdir ".."
|
||||||
|
end
|
||||||
|
|
||||||
|
# When Actions are performed
|
||||||
|
When /^I create a project using: compass create ([^\s]+) ?(.+)?$/ do |dir, args|
|
||||||
@cleanup_directories << dir
|
@cleanup_directories << dir
|
||||||
compass 'create', dir, *(args || '').split
|
compass 'create', dir, *(args || '').split
|
||||||
end
|
end
|
||||||
|
|
||||||
# When /I run: compass ([^\s]+) ?(.+)?/ do |command, args|
|
When /^I run: compass ([^\s]+) ?(.+)?$/ do |command, args|
|
||||||
# compass command, *args.split
|
compass command, *(args || '').split
|
||||||
# end
|
end
|
||||||
|
|
||||||
|
When /^I touch ([^\s]+)$/ do |filename|
|
||||||
Then /a directory ([^ ]+) is (not )?created/ do |directory, negated|
|
FileUtils.touch filename
|
||||||
|
end
|
||||||
|
|
||||||
|
When /^I wait ([\d.]+) seconds?$/ do |count|
|
||||||
|
sleep count.to_f
|
||||||
|
end
|
||||||
|
|
||||||
|
# Then postconditions
|
||||||
|
Then /^a directory ([^ ]+) is (not )?created$/ do |directory, negated|
|
||||||
File.directory?(directory).should == !negated
|
File.directory?(directory).should == !negated
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -44,6 +67,14 @@ Then /a \w+ file ([^ ]+) is (?:reported )?compiled/ do |filename|
|
|||||||
@last_result.should =~ /compile #{Regexp.escape(filename)}/
|
@last_result.should =~ /compile #{Regexp.escape(filename)}/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then /a \w+ file ([^ ]+) is reported unchanged/ do |filename|
|
||||||
|
@last_result.should =~ /unchanged #{Regexp.escape(filename)}/
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /a \w+ file ([^ ]+) is reported identical/ do |filename|
|
||||||
|
@last_result.should =~ /identical #{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
|
||||||
@ -73,3 +104,5 @@ Then /^I am told how to compile my sass stylesheets$/ do
|
|||||||
@last_result.should =~ /You must compile your sass stylesheets into CSS when they change.\nThis can be done in one of the following ways:/
|
@last_result.should =~ /You must compile your sass stylesheets into CSS when they change.\nThis can be done in one of the following ways:/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
@ -3,8 +3,25 @@ require 'compass/compiler'
|
|||||||
|
|
||||||
module Compass
|
module Compass
|
||||||
module Commands
|
module Commands
|
||||||
|
module CompileProjectOptionsParser
|
||||||
|
def set_options(opts)
|
||||||
|
opts.banner = %Q{
|
||||||
|
Usage: compass compile [path/to/project] [options]
|
||||||
|
|
||||||
|
Description:
|
||||||
|
compile project at the path specified or the current director if not specified.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n")
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class UpdateProject < ProjectBase
|
class UpdateProject < ProjectBase
|
||||||
|
|
||||||
|
register :compile
|
||||||
|
|
||||||
def initialize(working_path, options)
|
def initialize(working_path, options)
|
||||||
super
|
super
|
||||||
assert_project_directory_exists! unless dry_run?
|
assert_project_directory_exists! unless dry_run?
|
||||||
@ -33,6 +50,37 @@ module Compass
|
|||||||
:force => options[:force]).merge(additional_options))
|
:force => options[:force]).merge(additional_options))
|
||||||
end
|
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 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 == 1
|
||||||
|
parser.options[:project_name] = arguments.shift
|
||||||
|
elsif arguments.size > 1
|
||||||
|
raise Compass::Error, "Too many arguments were specified."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user