Skip to content
Browse files

Merge pull request #3 from sspinc/master

Create watchers with regexen
  • Loading branch information...
2 parents f936373 + 719b90d commit 85ec3db1edd48a15ef13d7379d823be342f5a3d3 Olivier Amblet committed May 11, 2011
Showing with 26 additions and 28 deletions.
  1. +26 −28 lib/guard/compass.rb
View
54 lib/guard/compass.rb
@@ -12,47 +12,45 @@ module Guard
class Compass < Guard
attr_reader :updater, :working_path
attr_accessor :reporter
-
+
VERSION = '0.0.7'
-
+
def initialize(watchers = [], options = {})
super
@reporter = Reporter.new
@working_path = Pathname.pwd # the Guard base path is the current working_path
end
-
+
# Load Compass Configuration
def create_watchers
# root_path is the path to the compass project
# working_path is the current Guard (and by extension Compass) working directory
-
+
watchers.clear
-
+
config_file = (options[:configuration_file] || ::Compass.detect_configuration_file(root_path))
-
+
if(config_file.nil?)
reporter.failure "Cannot find a Compass configuration file, please add information to your Guardfile guard 'compass' declaration."
return false
end
-
+
config_path = pathname(working_path, config_file)
-
+
unless(config_path.exist?)
reporter.failure "Compass configuration file not found: #{config_path}\nPlease check Guard configuration."
return false
end
src_path = pathname(root_path, ::Compass.configuration.sass_dir)
-
- watchers.push Watcher.new("^#{src_path.relative_path_from(working_path)}/.*")
- watchers.push Watcher.new("^#{config_path.relative_path_from(working_path)}$")
- puts watchers.inspect
-
+
+ watchers.push Watcher.new(%r{^#{src_path.relative_path_from(working_path)}/.*})
+ watchers.push Watcher.new(%r{^#{config_path.relative_path_from(working_path)}$})
end
-
+
def root_path
options[:project_path].nil? ? working_path : pathname(working_path, options[:project_path])
end
-
+
def valid_sass_path?
path = pathname(root_path, ::Compass.configuration.sass_dir)
unless path.exist?
@@ -62,49 +60,49 @@ def valid_sass_path?
true
end
end
-
+
# Guard Interface Implementation
-
+
# Compile all the sass|scss stylesheets
def start
UI.info "Guard::Compass is watching at your stylesheets."
create_updater
true
end
-
+
def stop
@updater = nil
true
end
-
+
# Reload the configuration
def reload
create_updater
true
end
-
+
# Compile all the sass|scss stylesheets
def run_all
perform
end
-
+
# Compile the changed stylesheets
def run_on_change(paths)
perform
end
-
+
private
include CompassHelper
-
+
# Cleanup of the given options
def cleanup_options
-
+
# Ensure configuration file make reference to an absolute path.
- if(options[:configuration_file])
+ if(options[:configuration_file])
options[:configuration_file] = pathname(working_path, options[:configuration_file]).to_s
end
end
-
+
def perform
if valid_sass_path?
@updater.execute
@@ -113,12 +111,12 @@ def perform
false
end
end
-
+
def create_updater
cleanup_options
@updater = ::Compass::Commands::UpdateProject.new(working_path.to_s, options)
create_watchers
valid_sass_path?
end
end
-end
+end

0 comments on commit 85ec3db

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