Class: Compass::Commands::WatchProject

Inherits:
UpdateProject show all
Defined in:
lib/compass/commands/watch_project.rb

Instance Attribute Summary collapse

Attributes inherited from ProjectBase

#options, #project_name

Attributes inherited from Base

#options, #working_path

Attributes included from Actions

#logger

Instance Method Summary collapse

Methods inherited from UpdateProject

#initialize, #new_compiler_instance

Methods inherited from ProjectBase

#execute, #initialize

Methods inherited from Base

#execute, #initialize

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_filesObject

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_timeObject

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

#performObject



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, options)
    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