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
description, #dry_run?, #initialize, #new_compiler_instance, option_parser, parse!, parse_arguments!, primary, usage
Methods inherited from ProjectBase
Methods inherited from Base
#execute, #initialize, register
Methods included from Actions
#basename, #compile, #copy, #directory, #process_erb, #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.
12 13 14 |
# File 'lib/compass/commands/watch_project.rb', line 12 def last_sass_files @last_sass_files end |
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
12 13 14 |
# File 'lib/compass/commands/watch_project.rb', line 12 def last_update_time @last_update_time end |
Instance Method Details
#perform ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/compass/commands/watch_project.rb', line 14 def perform Signal.trap("INT") do puts "" exit 0 end recompile puts ">>> Compass is watching for changes. Press Ctrl-C to Stop." begin require 'fssm' rescue LoadError $: << File.join(Compass.lib_directory, 'vendor') retry end 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
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/compass/commands/watch_project.rb', line 57 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::Helpers.report_error(e, ) end end end |
#remove_obsolete_css(base = nil, relative = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/compass/commands/watch_project.rb', line 46 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 |