class Guard::Compass

Attributes

reporter[RW]
updater[R]
working_path[R]

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/guard/compass.rb, line 28
def initialize(options = {})
  super
  @reporter = Reporter.new
  @working_path = Pathname.pwd # the Guard base path is the current working_path
end

Public Instance Methods

create_watchers() click to toggle source

Load Compass Configuration

# File lib/guard/compass.rb, line 35
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))
  config_path = pathname(working_path, config_file)
  src_path = pathname(root_path, ::Compass.configuration.sass_dir)

  watchers.push Watcher.new(%r{^#{src_path.relative_path_from(working_path)}/.*})
  watchers.push Watcher.new(%r{^#{config_path.relative_path_from(working_path)}$})

  Array(::Compass.configuration.additional_import_paths).each do |additional_path|
    watchers.push Watcher.new(%r{^#{pathname(additional_path).relative_path_from(working_path)}/.*})
  end
end
reload() click to toggle source

Reload the configuration

# File lib/guard/compass.rb, line 111
def reload
  create_updater
  true
end
root_path() click to toggle source
# File lib/guard/compass.rb, line 53
def root_path
  options[:project_path].nil? ? working_path : pathname(working_path, options[:project_path])
end
run_all() click to toggle source

Compile all the sass|scss stylesheets

# File lib/guard/compass.rb, line 117
def run_all
  perform
end
run_on_change(paths) click to toggle source

Compile the changed stylesheets

# File lib/guard/compass.rb, line 122
def run_on_change(paths)
  perform
end
start() click to toggle source

Compile all the sass|scss stylesheets

# File lib/guard/compass.rb, line 94
def start
  create_updater
  if options[:compile_on_start]
    reporter.announce "Guard::Compass is going to compile your stylesheets."
    perform
  else
    reporter.announce "Guard::Compass is waiting to compile your stylesheets."
  end
  true
end
stop() click to toggle source
# File lib/guard/compass.rb, line 105
def stop
  @updater = nil
  true
end
valid_configuration_path?() click to toggle source
# File lib/guard/compass.rb, line 73
def valid_configuration_path?
  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)

  if config_path.exist?
    true
  else
    reporter.failure "Compass configuration file not found: #{config_path}\nPlease check Guard configuration."
    false
  end
end
valid_sass_path?() click to toggle source
# File lib/guard/compass.rb, line 57
def valid_sass_path?
  if ::Compass.configuration.sass_dir.nil?
    reporter.failure("Sass files src directory not set.\nPlease check your Compass configuration.")
    return false
  end

  path = pathname(root_path, ::Compass.configuration.sass_dir )

  unless path.exist?
    reporter.failure("Sass files src directory not found: #{path}\nPlease check your Compass configuration.")
    false
  else
    true
  end
end

Private Instance Methods

cleanup_options() click to toggle source

Cleanup of the given options

# File lib/guard/compass.rb, line 130
def cleanup_options
  # Ensure configuration file make reference to an absolute path.
  if options[:configuration_file]
    options[:configuration_file] = pathname(working_path, options[:configuration_file]).to_s
  end
end
create_updater() click to toggle source
# File lib/guard/compass.rb, line 155
def create_updater
  cleanup_options
  if valid_configuration_path?
    @updater = ::Compass::Commands::UpdateProject.new(working_path.to_s, options)
    create_watchers
    return valid_sass_path?
  else
    return false
  end
end
perform() click to toggle source
# File lib/guard/compass.rb, line 137
def perform
  if valid_sass_path?
    begin
      @updater.execute
    rescue Sass::SyntaxError => e
      msg = "#{e.sass_backtrace_str}"
      ::Guard::Notifier.notify msg, title: "Guard Compass", image: :failed
      return false
    rescue Exception => e
      ::Guard::Notifier.notify e.to_s, title: "Guard Compass", image: :failed
      return false
    end
    true
  else
    false
  end
end