Class: Compass::Commands::WatchProject
- Inherits:
-
UpdateProject
- Object
- Base
- ProjectBase
- UpdateProject
- Compass::Commands::WatchProject
- Defined in:
- lib/compass/commands/watch_project.rb
Instance Attribute Summary collapse
-
#last_sass_files ⇒ Object
Returns the value of attribute last_sass_files.
-
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
Attributes inherited from ProjectBase
Attributes inherited from Base
Attributes included from Actions
Instance Method Summary collapse
- #perform ⇒ Object
- #recompile(base = nil, relative = nil) ⇒ Object
- #remove_obsolete_css(base = nil, relative = nil) ⇒ Object
Methods inherited from UpdateProject
#initialize, #new_compiler_instance
Methods inherited from ProjectBase
Methods inherited from Base
Methods included from Actions
#basename, #compile, #copy, #directory, #relativize, #remove, #separate, #strip_trailing_separator, #write_file
Constructor Details
This class inherits a constructor from Compass::Commands::UpdateProject
Instance Attribute Details
#last_sass_files ⇒ Object
Returns the value of attribute last_sass_files.
10 11 12 |
# File 'lib/compass/commands/watch_project.rb', line 10 def last_sass_files @last_sass_files end |
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
10 11 12 |
# File 'lib/compass/commands/watch_project.rb', line 10 def last_update_time @last_update_time end |
Instance Method Details
#perform ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/compass/commands/watch_project.rb', line 12 def perform Signal.trap("INT") do puts "" exit 0 end recompile puts ">>> Compass is watching for changes. Press Ctrl-C to Stop." require File.join(Compass.lib_directory, 'vendor', 'fssm') FSSM.monitor do |monitor| Compass.configuration.sass_load_paths.each do |load_path| monitor.path load_path do |path| path.glob '**/*.sass' path.update &method(:recompile) path.delete {|base, relative| remove_obsolete_css(base,relative); recompile(base, relative)} path.create &method(:recompile) end end end end |
#recompile(base = nil, relative = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/compass/commands/watch_project.rb', line 50 def recompile(base = nil, relative = nil) compiler = new_compiler_instance(:quiet => true) if file = compiler.out_of_date? begin puts ">>> Change detected to: #{file}" compiler.run rescue StandardError => e ::Compass::Exec.report_error(e, ) end end end |
#remove_obsolete_css(base = nil, relative = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/compass/commands/watch_project.rb', line 39 def remove_obsolete_css(base = nil, relative = nil) compiler = new_compiler_instance(:quiet => true) sass_files = compiler.sass_files deleted_sass_files = (last_sass_files || []) - sass_files deleted_sass_files.each do |deleted_sass_file| css_file = compiler.corresponding_css_file(deleted_sass_file) remove(css_file) if File.exists?(css_file) end self.last_sass_files = sass_files end |