Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

guard 'compass' :configuration_file => 'my_custom.rb'

Should now work. Need to create the watchers as
well.
  • Loading branch information...
commit 8ef8bd1457b137d6f96eea35fc3bb82e4f33f8bd 1 parent 126240e
@oliamb oliamb authored
Showing with 325 additions and 51 deletions.
  1. +3 −2 Guardfile
  2. +16 −0 README.textile
  3. +38 −6 lib/guard/compass.rb
  4. +6 −1 lib/guard/compass/templates/Guardfile
  5. +19 −0 lib/guard/reporter.rb
  6. BIN  spec/fixtures/bad_src_directory/.sass-cache/77242121e92e5208094a0a0f6fbd9eb05d2c3832/_utilities.scssc
  7. BIN  spec/fixtures/bad_src_directory/.sass-cache/804c142587e371bce0dd76315d953aa707422b74/_reset.scssc
  8. +5 −0 spec/fixtures/bad_src_directory/bad_src/ie.scss
  9. +3 −0  spec/fixtures/bad_src_directory/bad_src/print.scss
  10. +6 −0 spec/fixtures/bad_src_directory/bad_src/screen.scss
  11. +9 −0 spec/fixtures/bad_src_directory/config.rb
  12. BIN  spec/fixtures/custom_config_file/.sass-cache/77242121e92e5208094a0a0f6fbd9eb05d2c3832/_utilities.scssc
  13. BIN  spec/fixtures/custom_config_file/.sass-cache/804c142587e371bce0dd76315d953aa707422b74/_reset.scssc
  14. +9 −0 spec/fixtures/custom_config_file/another_config_location/config.rb
  15. +5 −0 spec/fixtures/custom_config_file/another_src_location/ie.scss
  16. +3 −0  spec/fixtures/custom_config_file/another_src_location/print.scss
  17. +6 −0 spec/fixtures/custom_config_file/another_src_location/screen.scss
  18. +1 −0  spec/fixtures/dsl/simple/Guardfile
  19. BIN  spec/fixtures/no_config_file/.sass-cache/77242121e92e5208094a0a0f6fbd9eb05d2c3832/_utilities.scssc
  20. BIN  spec/fixtures/no_config_file/.sass-cache/804c142587e371bce0dd76315d953aa707422b74/_reset.scssc
  21. +5 −0 spec/fixtures/no_config_file/src/ie.scss
  22. +3 −0  spec/fixtures/no_config_file/src/print.scss
  23. +6 −0 spec/fixtures/no_config_file/src/screen.scss
  24. +142 −39 spec/guard/compass_spec.rb
  25. +19 −0 spec/guard/dsl_spec.rb
  26. +19 −0 spec/guard/reporter_spec.rb
  27. +2 −3 spec/spec_helper.rb
View
5 Guardfile
@@ -1,6 +1,7 @@
guard 'rspec', :version => 2 do
require 'growl' rescue nil
watch('^spec/(.*)_spec.rb')
- watch('^lib/(.*).rb') { |m| "spec/#{m[1]}_spec.rb" }
- watch('^spec/spec_helper.rb') { "spec" }
+ watch('^lib/(.*).rb') { |m| "spec/#{m[1]}_spec.rb" }
+ watch('^spec/spec_helper.rb') { "spec" }
+ watch('^spec/fixtures/(.*)') { "spec" }
end
View
16 README.textile
@@ -23,6 +23,22 @@ $ guard
Your scss(or sass) stylesheets are now guarded.
+h2. Configure Guard::Compass plug-in
+
+The default configuration generated by 'guard init compass' looks like this
+
+bc. guard 'compass' do
+ watch('^src/(.*)\.s[ac]ss')
+end
+
+the compass guard accept two options:
+
+ * :workdir: all compass relative path will be computed from there
+ * :configuration_file: relative or absolute path to your compass configuration file
+
+By default, the working directory is the folder where you run guard in and
+the configuration_file is computed by compass
+
h2. Roadmap
h3. 0.1.0
View
44 lib/guard/compass.rb
@@ -1,5 +1,6 @@
require 'guard'
require 'guard/guard'
+require 'guard/reporter'
require 'compass'
require 'compass/commands'
@@ -7,13 +8,15 @@
module Guard
class Compass < Guard
- attr_reader :updater
+ attr_reader :updater, :options
+ attr_accessor :reporter
VERSION = '0.0.6'
def initialize(watchers = [], options = {})
super
- @options[:workdir] = File.expand_path(File.dirname("."))
+ @reporter = Reporter.new
+ @options[:workdir] ||= File.expand_path(File.dirname("."))
end
# Guard Interface Implementation
@@ -38,19 +41,48 @@ def reload
# Compile all the sass|scss stylesheets
def run_all
- @updater.execute
- true
+ perform
end
# Compile the changed stylesheets
def run_on_change(paths)
- @updater.execute
- true
+ perform
end
private
+ def perform
+ if valid_sass_path?
+ @updater.execute
+ true
+ else
+ false
+ end
+ end
+
def create_updater
+ if(options[:configuration_file])
+ filepath = Pathname.new(options[:configuration_file])
+ if(filepath.relative?)
+ filepath = Pathname.new([options[:workdir], options[:configuration_file]].join("/"))
+ end
+ if(filepath.exist?)
+ ::Compass.add_configuration filepath
+ options[:configuration_file] = filepath
+ else
+ reporter.failure "Cannot find the Compass configuration file: " + filepath + "\nPlease check your configuration."
+ end
+ end
@updater = ::Compass::Commands::UpdateProject.new(@options[:workdir] , @options)
+ valid_sass_path?
+ end
+
+ def valid_sass_path?
+ unless File.exists? ::Compass.configuration.sass_path
+ reporter.failure("Sass files src directory not found: #{::Compass.configuration.sass_path}\nPlease check your Compass configuration.")
+ false
+ else
+ true
+ end
end
end
end
View
7 lib/guard/compass/templates/Guardfile
@@ -1,3 +1,8 @@
guard 'compass' do
watch('^src/(.*)\.s[ac]ss')
-end
+end
+
+# # Alternative
+# guard 'compass', :workdir => 'not_current_dir', :configuration_file => 'path/to/my/compass_config.rb' do
+# watch('^src/(.*)\.s[ac]ss')
+# end
View
19 lib/guard/reporter.rb
@@ -0,0 +1,19 @@
+module Guard
+ # Send a report to the Guard UI
+ # The Reporter is a wrapper arround guard UI because
+ # it is currently subject to change.
+ class Reporter
+ def success(message)
+ UI.info(message)
+ end
+ def failure(message)
+ UI.error(message)
+ end
+ def unstable(message)
+ UI.info(message)
+ end
+ def announce(message)
+ UI.info(message)
+ end
+ end
+end
View
BIN  spec/fixtures/bad_src_directory/.sass-cache/77242121e92e5208094a0a0f6fbd9eb05d2c3832/_utilities.scssc
Binary file not shown
View
BIN  spec/fixtures/bad_src_directory/.sass-cache/804c142587e371bce0dd76315d953aa707422b74/_reset.scssc
Binary file not shown
View
5 spec/fixtures/bad_src_directory/bad_src/ie.scss
@@ -0,0 +1,5 @@
+/* Welcome to Compass. Use this file to write IE specific override styles.
+ * Import this file using the following HTML or equivalent:
+ * <!--[if IE]>
+ * <link href="/stylesheets/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
+ * <![endif]--> */
View
3  spec/fixtures/bad_src_directory/bad_src/print.scss
@@ -0,0 +1,3 @@
+/* Welcome to Compass. Use this file to define print styles.
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css" /> */
View
6 spec/fixtures/bad_src_directory/bad_src/screen.scss
@@ -0,0 +1,6 @@
+/* Welcome to Compass.
+ * In this file you should write your main styles. (or centralize your imports)
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" /> */
+
+@import "compass/reset";
View
9 spec/fixtures/bad_src_directory/config.rb
@@ -0,0 +1,9 @@
+# Require any additional compass plugins here.
+# Set this to the root of your project when deployed:
+http_path = "/"
+css_dir = "stylesheets"
+sass_dir = "src"
+images_dir = "images"
+javascripts_dir = "javascripts"
+# To enable relative paths to assets via compass helper functions. Uncomment:
+# relative_assets = true
View
BIN  spec/fixtures/custom_config_file/.sass-cache/77242121e92e5208094a0a0f6fbd9eb05d2c3832/_utilities.scssc
Binary file not shown
View
BIN  spec/fixtures/custom_config_file/.sass-cache/804c142587e371bce0dd76315d953aa707422b74/_reset.scssc
Binary file not shown
View
9 spec/fixtures/custom_config_file/another_config_location/config.rb
@@ -0,0 +1,9 @@
+# Require any additional compass plugins here.
+# Set this to the root of your project when deployed:
+http_path = "/"
+css_dir = "another_stylesheets_location"
+sass_dir = "another_src_location"
+images_dir = "another_images_location"
+javascripts_dir = "another_javascripts_location"
+# To enable relative paths to assets via compass helper functions. Uncomment:
+# relative_assets = true
View
5 spec/fixtures/custom_config_file/another_src_location/ie.scss
@@ -0,0 +1,5 @@
+/* Welcome to Compass. Use this file to write IE specific override styles.
+ * Import this file using the following HTML or equivalent:
+ * <!--[if IE]>
+ * <link href="/stylesheets/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
+ * <![endif]--> */
View
3  spec/fixtures/custom_config_file/another_src_location/print.scss
@@ -0,0 +1,3 @@
+/* Welcome to Compass. Use this file to define print styles.
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css" /> */
View
6 spec/fixtures/custom_config_file/another_src_location/screen.scss
@@ -0,0 +1,6 @@
+/* Welcome to Compass.
+ * In this file you should write your main styles. (or centralize your imports)
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" /> */
+
+@import "compass/reset";
View
1  spec/fixtures/dsl/simple/Guardfile
@@ -0,0 +1 @@
+guard 'compass', :workdir => 'test', :configuration_file => 'test_also.rb'
View
BIN  spec/fixtures/no_config_file/.sass-cache/77242121e92e5208094a0a0f6fbd9eb05d2c3832/_utilities.scssc
Binary file not shown
View
BIN  spec/fixtures/no_config_file/.sass-cache/804c142587e371bce0dd76315d953aa707422b74/_reset.scssc
Binary file not shown
View
5 spec/fixtures/no_config_file/src/ie.scss
@@ -0,0 +1,5 @@
+/* Welcome to Compass. Use this file to write IE specific override styles.
+ * Import this file using the following HTML or equivalent:
+ * <!--[if IE]>
+ * <link href="/stylesheets/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
+ * <![endif]--> */
View
3  spec/fixtures/no_config_file/src/print.scss
@@ -0,0 +1,3 @@
+/* Welcome to Compass. Use this file to define print styles.
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css" /> */
View
6 spec/fixtures/no_config_file/src/screen.scss
@@ -0,0 +1,6 @@
+/* Welcome to Compass.
+ * In this file you should write your main styles. (or centralize your imports)
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" /> */
+
+@import "compass/reset";
View
181 spec/guard/compass_spec.rb
@@ -5,70 +5,173 @@
describe Guard::Compass do
subject { Guard::Compass.new }
- before :each do
- @project_path = File.expand_path('./compass_prj')
+ it "has a reporter" do
+ subject.reporter.should_not be_nil
end
- describe "start" do
- it "supports creation of the updater instance" do
- subject.updater.should be_nil
- subject.start.should be_true
- subject.updater.should_not be_nil
+ 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
+
+ describe "In a standard project" do
+
+ before :each do
+ create_fixture(:compass_prj)
+ end
+
+ after :each do
+ remove_fixtures
end
+
+ describe "start" do
+ it "supports creation of the updater instance" do
+ subject.updater.should be_nil
+ subject.start.should be_true
+ subject.updater.should_not be_nil
+ end
- it "should not generate anything" do
- File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+ it "should not generate anything" do
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+ end
end
- end
- describe "default options" do
- it "should have a default path mathching the run location" do
- subject.options[:workdir].should == File.expand_path(".")
- subject.start.should be_true
+ describe "default options" do
+ it "should have a default path mathching the run location" do
+ subject.options[:workdir].should == @project_path
+ subject.start.should be_true
+ end
end
- end
- describe "after start" do
+ describe "after start" do
+
+ before :each do
+ subject.start
+ end
+
+ after :each do
+ subject.stop
+ end
+
+ describe "the updater" do
+ it "should contains an options hashmap with config file values" do
+ ::Compass.configuration.sass_path.should_not be_nil
+ ::Compass.configuration.sass_path.should == "#{@project_path}/src"
+ end
+ end
+
+ describe "stop" do
+ it "Stop remove the updater" do
+ subject.updater.should_not be_nil
+ subject.stop.should be_true
+ subject.updater.should be_nil
+ end
+ end
+
+ describe "run_on_change" do
+ it "rebuilds all scss files in compass path" do
+ File.exists?(@project_path + "/src/screen.scss").should(be_true)
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+ subject.run_on_change(@project_path + "/src/screen.scss").should be_true
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_true
+ end
+ end
+
+ describe "run all" do
+ it "rebuilds all scss files in compass path" do
+ File.exists?(@project_path + "/src/screen.scss").should(be_true)
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+ subject.run_all.should be_true
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_true
+ end
+ end
+ end
+ end
+
+ describe "with custom configuration and locations" do
before :each do
- FileUtils.mkdir(TMP_PATH) if ! File.exists? TMP_PATH
- @project_path = TMP_PATH + '/compass_prj'
- FileUtils.cp_r FIXTURES_PATH + '/compass_prj', TMP_PATH
- subject.options.merge!(:workdir => @project_path)
-
- subject.start
+ create_fixture(:custom_config_file)
end
+
after :each do
- FileUtils.rm_rf(TMP_PATH)
-
+ remove_fixtures
subject.stop
end
- describe "stop" do
- it "Stop remove the updater" do
- subject.updater.should_not be_nil
- subject.stop.should be_true
- subject.updater.should be_nil
- end
+ it "configure Compass correctly with an absolute path" do
+ subject.options[:configuration_file] = "#{@project_path}/another_config_location/config.rb"
+ subject.start
+ Compass.configuration.sass_path.should == "#{@project_path}/another_src_location"
+ Compass.configuration.sass_path.should == "#{@project_path}/another_src_location"
+ end
+
+ it "configure Compass correctly with a path relative to the workdir" do
+ subject.options[:configuration_file] = "another_config_location/config.rb"
+ subject.start
+ end
+
+ it "rebuilds all scss files in compass path" do
+ subject.options[:configuration_file] = "#{@project_path}/another_config_location/config.rb"
+ subject.start
+ File.exists?("#{@project_path}/another_src_location/screen.scss").should(be_true)
+ File.exists?("#{@project_path}/another_stylesheets_location/screen.css").should be_false
+ subject.run_on_change(@project_path + "/another_src_location/screen.scss").should be_true
+ File.exists?(@project_path + "/another_stylesheets_location/screen.css").should be_true
+ end
+ end
+
+ describe "without config file" do
+ before :each do
+ create_fixture(:no_config_file)
+ subject.start
+ end
+
+ after :each do
+ remove_fixtures
+ subject.stop
end
describe "run_on_change" do
- it "rebuilds all scss files in compass path" do
+ it "rebuilds all scss files in src by default" do
File.exists?(@project_path + "/src/screen.scss").should(be_true)
File.exists?(@project_path + "/stylesheets/screen.css").should be_false
subject.run_on_change(@project_path + "/src/screen.scss").should be_true
File.exists?(@project_path + "/stylesheets/screen.css").should be_true
end
end
-
- describe "run all" do
- it "rebuilds all scss files in compass path" do
- File.exists?(@project_path + "/src/screen.scss").should(be_true)
- File.exists?(@project_path + "/stylesheets/screen.css").should be_false
- subject.run_all.should be_true
- File.exists?(@project_path + "/stylesheets/screen.css").should be_true
- end
+ end
+
+ describe "with a bad directory configuration" do
+ 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.")
+ subject.start
+ end
+
+ after :each do
+ remove_fixtures
+ subject.stop
end
+ it "rebuilds failed to build sass" do
+ File.exists?(@project_path + "/bad_src/screen.scss").should(be_true)
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+
+ subject.run_on_change(@project_path + "/bad_src/screen.scss")
+ end
+ 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)
end
end
View
19 spec/guard/dsl_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+require 'guard/dsl'
+
+describe Guard::Dsl do
+ subject {Guard::Dsl}
+
+ it "load a guard from the DSL" do
+ File.exists?("#{FIXTURES_PATH}/dsl/simple").should be_true
+ File.exists?("#{FIXTURES_PATH}/dsl/simple/Guardfile").should be_true
+
+ ## Hack to make guard look into the correct fixture folder
+ Dir.stub!(:pwd).and_return("#{FIXTURES_PATH}/dsl/simple")
+ Dir.pwd.should == "#{FIXTURES_PATH}/dsl/simple"
+
+ ::Guard.stub!(:add_guard)
+ ::Guard.should_receive(:add_guard).with('compass', [], hash_including(:workdir, :configuration_file))
+ subject.evaluate_guardfile
+ end
+end
View
19 spec/guard/reporter_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+require 'guard/reporter'
+
+describe Guard::Reporter do
+ subject {Guard::Reporter.new}
+
+ it "respond_to failure" do
+ subject.should respond_to :failure
+ end
+ it "respond_to success" do
+ subject.should respond_to :success
+ end
+ it "respond_to announce" do
+ subject.should respond_to :announce
+ end
+ it "respond_to unstable" do
+ subject.should respond_to :unstable
+ end
+end
View
5 spec/spec_helper.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
-FIXTURES_PATH = File.expand_path(File.dirname(__FILE__) + '/fixtures')
+FIXTURES_PATH = Pathname.new(File.expand_path('../fixtures/', __FILE__))
+LIB_PATH = Pathname.new(File.expand_path('../../lib/', __FILE__))
TMP_PATH = File.expand_path(File.dirname(__FILE__) + '/tmp_files')
RSpec.configure do |config|
@@ -10,7 +11,5 @@
config.before(:each) do
ENV["GUARD_ENV"] = 'test'
- @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
- @lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.