Class: Guard::Compass

Inherits:
Plugin
  • Object
show all
Includes:
CompassHelper
Defined in:
lib/guard/compass.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CompassHelper

#check_for_sass_files!, #new_compiler_instance, #pathname

Constructor Details

#initialize(options = {}) ⇒ Compass

Returns a new instance of Compass.



28
29
30
31
32
# 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

Instance Attribute Details

#reporterObject

Returns the value of attribute reporter.



26
27
28
# File 'lib/guard/compass.rb', line 26

def reporter
  @reporter
end

#updaterObject (readonly)

Returns the value of attribute updater.



25
26
27
# File 'lib/guard/compass.rb', line 25

def updater
  @updater
end

#working_pathObject (readonly)

Returns the value of attribute working_path.



25
26
27
# File 'lib/guard/compass.rb', line 25

def working_path
  @working_path
end

Instance Method Details

#create_watchersObject

Load Compass Configuration



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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

#reloadObject

Reload the configuration



111
112
113
114
# File 'lib/guard/compass.rb', line 111

def reload
  create_updater
  true
end

#root_pathObject



53
54
55
# File 'lib/guard/compass.rb', line 53

def root_path
  options[:project_path].nil? ? working_path : pathname(working_path, options[:project_path])
end

#run_allObject

Compile all the sass|scss stylesheets



117
118
119
# File 'lib/guard/compass.rb', line 117

def run_all
  perform
end

#run_on_change(paths) ⇒ Object

Compile the changed stylesheets



122
123
124
# File 'lib/guard/compass.rb', line 122

def run_on_change(paths)
  perform
end

#startObject

Compile all the sass|scss stylesheets



94
95
96
97
98
99
100
101
102
103
# 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

#stopObject



105
106
107
108
# File 'lib/guard/compass.rb', line 105

def stop
  @updater = nil
  true
end

#valid_configuration_path?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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