Skip to content

Commit

Permalink
Added compass syntax success/error notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Dec 2, 2010
1 parent 8bdda05 commit 9b4c6de
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions lib/guard/compass.rb
Expand Up @@ -5,58 +5,77 @@
require 'compass'
require 'compass/commands'
require 'compass/logger'
require 'compass/compiler'

module Compass
class Compiler
alias :old_handle_exception :handle_exception
def handle_exception(sass_filename, css_filename, e)
old_handle_exception(sass_filename, css_filename, e)
# rethrow the exception, we need it to notificate the user!
raise Sass::SyntaxError, "[#{File.basename(sass_filename)}:#{e.sass_line}] #{e.message}"
end
end
end

module Guard
class Compass < Guard
attr_reader :updater, :options
attr_accessor :reporter

def initialize(watchers = [], options = {})
super
@reporter = Reporter.new
@options[:workdir] ||= File.expand_path(File.dirname("."))
end

# Guard Interface Implementation

# Compile all the sass|scss stylesheets
def start
create_updater
reporter.announce "Guard::Compass is watching at your stylesheets."
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
def perform
if valid_sass_path?
@updater.execute
true
begin
@updater.execute
Notifier.notify("No errors.", :title => "Compass")
true
rescue Sass::SyntaxError => e
Notifier.notify(e.message, :image => :failed, :title => "Compass")
reporter.failure "#{e.message}"
false
end
else
false
end
end

def create_updater
if(options[:configuration_file])
filepath = Pathname.new(options[:configuration_file])
Expand All @@ -73,7 +92,7 @@ def create_updater
@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.")
Expand Down

0 comments on commit 9b4c6de

Please sign in to comment.