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
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 |
# File 'lib/compass/commands/watch_project.rb', line 12 def perform Signal.trap("INT") do puts "" exit 0 end puts ">>> Compass is watching for changes. Press Ctrl-C to Stop." loop do # TODO: Make this efficient by using filesystem monitoring. compiler = new_compiler_instance(:quiet => true) remove_obsolete_css(compiler) recompile(compiler) sleep 1 end end |
#recompile(compiler) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/compass/commands/watch_project.rb', line 37 def recompile(compiler) 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(compiler) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/compass/commands/watch_project.rb', line 27 def remove_obsolete_css(compiler) 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 |