Skip to content

Commit

Permalink
guard 'compass' :configuration_file => 'my_custom.rb'
Browse files Browse the repository at this point in the history
Should now work. Need to create the watchers as
well.
  • Loading branch information
oliamb committed Oct 30, 2010
1 parent 126240e commit 8ef8bd1
Show file tree
Hide file tree
Showing 27 changed files with 325 additions and 51 deletions.
5 changes: 3 additions & 2 deletions 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
16 changes: 16 additions & 0 deletions README.textile
Expand Up @@ -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
Expand Down
44 changes: 38 additions & 6 deletions lib/guard/compass.rb
@@ -1,19 +1,22 @@
require 'guard'
require 'guard/guard'
require 'guard/reporter'

require 'compass'
require 'compass/commands'
require 'compass/logger'

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
Expand All @@ -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
7 changes: 6 additions & 1 deletion 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
19 changes: 19 additions & 0 deletions 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
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions 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]--> */
3 changes: 3 additions & 0 deletions 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" /> */
6 changes: 6 additions & 0 deletions 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";
9 changes: 9 additions & 0 deletions 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
Binary file not shown.
Binary file not shown.
@@ -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
5 changes: 5 additions & 0 deletions 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]--> */
@@ -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" /> */
@@ -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";
1 change: 1 addition & 0 deletions spec/fixtures/dsl/simple/Guardfile
@@ -0,0 +1 @@
guard 'compass', :workdir => 'test', :configuration_file => 'test_also.rb'
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions 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]--> */
3 changes: 3 additions & 0 deletions 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" /> */
6 changes: 6 additions & 0 deletions 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";

0 comments on commit 8ef8bd1

Please sign in to comment.