Skip to content
Browse files

Create watchers from Compass configuration.

  • Loading branch information...
1 parent 21c2e7b commit ca1ffb752380728f3da85c2abbcc8eff7fa7de8d @oliamb oliamb committed Oct 31, 2010
Showing with 104 additions and 21 deletions.
  1. +18 −2 lib/guard/compass.rb
  2. +86 −19 spec/guard/compass_spec.rb
View
20 lib/guard/compass.rb
@@ -1,5 +1,6 @@
require 'guard'
require 'guard/guard'
+require 'guard/watcher'
require 'guard/reporter'
require 'compass'
@@ -23,8 +24,9 @@ def initialize(watchers = [], options = {})
# Compile all the sass|scss stylesheets
def start
- create_updater
UI.info "Guard::Compass is watching at your stylesheets."
+ load_compass_configuration
+ create_updater
true
end
@@ -35,6 +37,7 @@ def stop
# Reload the configuration
def reload
+ load_compass_configuration
create_updater
true
end
@@ -59,7 +62,8 @@ def perform
end
end
- def create_updater
+ def load_compass_configuration
+ ::Compass.default_configuration
if(options[:configuration_file])
filepath = Pathname.new(options[:configuration_file])
if(filepath.relative?)
@@ -72,6 +76,18 @@ def create_updater
reporter.failure "Compass configuration file not found: " + filepath + "\nPlease check Guard configuration."
end
end
+
+ ::Compass.configuration.sass_dir ||= "#{options[:workdir]}/src"
+ watchers.clear
+ watchers.push Watcher.new("^#{ File.expand_path(::Compass.configuration.sass_dir, options[:workdir]) }/.*")
+ if(options[:configuration_file])
+ watchers.push Watcher.new("^#{options[:configuration_file]}$")
+ elsif conf_file = ::Compass.detect_configuration_file(options[:workdir])
+ watchers.push Watcher.new("^#{conf_file}$")
+ end
+ end
+
+ def create_updater
@updater = ::Compass::Commands::UpdateProject.new(@options[:workdir] , @options)
valid_sass_path?
end
View
105 spec/guard/compass_spec.rb
@@ -2,27 +2,43 @@
require 'spec_helper'
require 'guard/compass'
+def create_fixture(name)
+ FileUtils.mkdir(TMP_PATH) if ! File.exists? TMP_PATH
+ @project_path = "#{TMP_PATH}/#{name}"
+ FileUtils.cp_r "#{FIXTURES_PATH}/#{name}", TMP_PATH
+ subject.options.merge!(:workdir => @project_path)
+end
+
+def remove_fixtures
+ FileUtils.rm_rf(TMP_PATH)
+end
+
describe Guard::Compass do
- subject { Guard::Compass.new }
-
- it "has a reporter" do
- subject.reporter.should_not be_nil
- end
- it "might be initialized with options" do
- g = Guard::Compass.new([], :workdir => 'test', :configuration_file => 'test_also')
- g.options[:workdir].should == 'test'
- g.options[:configuration_file].should == 'test_also'
+ after :each do
+ ::Compass.reset_configuration!
end
describe "In a standard project" do
+ subject { Guard::Compass.new }
+
+ it "has a reporter" do
+ subject.reporter.should_not be_nil
+ end
+
+ it "might be initialized with options" do
+ g = Guard::Compass.new([], :workdir => 'test', :configuration_file => 'test_also')
+ g.options[:workdir].should == 'test'
+ g.options[:configuration_file].should == 'test_also'
+ end
before :each do
create_fixture(:compass_prj)
end
after :each do
remove_fixtures
+ ::Compass.reset_configuration!
end
describe "start" do
@@ -52,6 +68,7 @@
after :each do
subject.stop
+ ::Compass.reset_configuration!
end
describe "the updater" do
@@ -91,13 +108,16 @@
end
describe "with custom configuration and locations" do
+ subject { Guard::Compass.new }
+
before :each do
create_fixture(:custom_config_file)
end
after :each do
remove_fixtures
subject.stop
+ ::Compass.reset_configuration!
end
it "configure Compass correctly with an absolute path" do
@@ -123,6 +143,8 @@
end
describe "without config file" do
+ subject { Guard::Compass.new }
+
before :each do
create_fixture(:no_config_file)
subject.start
@@ -131,6 +153,7 @@
after :each do
remove_fixtures
subject.stop
+ ::Compass.reset_configuration!
end
describe "run_on_change" do
@@ -144,6 +167,8 @@
end
describe "with a bad directory configuration" do
+ subject { Guard::Compass.new }
+
before :each do
create_fixture(:bad_src_directory)
subject.reporter.stub!(:failure).with("Sass files src directory not found: #{@project_path}/src\nPlease check your Compass configuration.")
@@ -153,6 +178,7 @@
after :each do
remove_fixtures
subject.stop
+ ::Compass.reset_configuration!
end
it "rebuilds failed to build sass" do
@@ -173,6 +199,7 @@
after :each do
subject.stop
remove_fixtures
+ ::Compass.reset_configuration!
end
it "reports an error" do
@@ -184,15 +211,55 @@
end
-private
- def create_fixture(name)
- FileUtils.mkdir(TMP_PATH) if ! File.exists? TMP_PATH
- @project_path = "#{TMP_PATH}/#{name}"
- FileUtils.cp_r "#{FIXTURES_PATH}/#{name}", TMP_PATH
- subject.options.merge!(:workdir => @project_path)
- end
-
- def remove_fixtures
- FileUtils.rm_rf(TMP_PATH)
+ describe "Watchers creation" do
+
+ after :each do
+ remove_fixtures
+ ::Compass.reset_configuration!
+ end
+
+ describe "in standard project" do
+ subject {
+ Guard::Compass.new([], :workdir => "#{TMP_PATH}/compass_prj")
+ }
+
+ before :each do
+ create_fixture :compass_prj
+ end
+
+ it "should have some watchers" do
+ subject.options.should eql :workdir => "#{TMP_PATH}/compass_prj"
+ subject.start
+ subject.watchers.size.should(eql(2), subject.watchers.inspect)
+ subject.watchers.first.pattern.should == "^#{@project_path}/src/.*"
+ end
+ end
+
+ describe "in customized project" do
+ subject {
+ Guard::Compass.new([], :workdir => "#{TMP_PATH}/custom_config_file", :configuration_file => 'another_config_location/config.rb')
+ }
+
+ before :each do
+ create_fixture :custom_config_file
+ end
+
+ it "should have some watchers" do
+ subject.start
+ subject.watchers.size.should(eql(2), subject.watchers.inspect)
+ subject.watchers.first.pattern.should == "^#{@project_path}/another_src_location/.*"
+ end
+ end
end
end
+
+def create_fixture(name)
+ FileUtils.mkdir(TMP_PATH) if ! File.exists? TMP_PATH
+ @project_path = "#{TMP_PATH}/#{name}"
+ FileUtils.cp_r "#{FIXTURES_PATH}/#{name}", TMP_PATH
+ subject.options.merge!(:workdir => @project_path)
+end
+
+def remove_fixtures
+ FileUtils.rm_rf(TMP_PATH)
+end

0 comments on commit ca1ffb7

Please sign in to comment.
Something went wrong with that request. Please try again.