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

Methods inherited from ProjectBase

#initialize

Methods inherited from Base

#initialize

Methods included from Actions

#basename, #compile, #copy, #directory, #relativize, #separate, #strip_trailing_separator, #write_file

Constructor Details

This class inherits a constructor from Compass::Commands::UpdateProject

Instance Attribute Details

#last_update_timeObject

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

#most_recent_update_timeObject



40
41
42
# File 'lib/compass/commands/watch_project.rb', line 40

def most_recent_update_time
  Dir.glob(separate("#{project_src_directory}/**/*.sass")).map {|sass_file| File.stat(sass_file).mtime}.max
end

#performObject



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
# File 'lib/compass/commands/watch_project.rb', line 14

def perform
  puts ">>> Compiling all stylesheets."
  super
  self.last_update_time = most_recent_update_time
  puts ">>> Compass is now watching for changes. Press Ctrl-C to Stop."
  loop do
    # TODO: Make this efficient by using filesystem monitoring.
    begin
      sleep 1
    rescue Interrupt
      puts ""
      exit 0
    end
    file, t = should_update?
    if t
      begin
        puts ">>> Change detected to: #{file}"
        super
      rescue StandardError => e
        ::Compass::Exec.report_error(e, options)
      end
      self.last_update_time = t
    end
  end
end

#should_update?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/compass/commands/watch_project.rb', line 44

def should_update?
  t = most_recent_update_time
  if t > last_update_time
    file = Dir.glob(separate("#{project_src_directory}/**/*.sass")).detect {|sass_file| File.stat(sass_file).mtime >= t}
    [file, t]
  end
end