Sha256: 175b52fa7f02b05e6d9a33fda3742ccad7dd2ca609b19e4478d870cf2267ba67

Contents?: true

Size: 1.48 KB

Versions: 15

Compression:

Stored size: 1.48 KB

Contents

require 'rubygems'
require 'sass'
require 'fileutils'
require 'pathname'
require File.join(File.dirname(__FILE__), 'base')
require File.join(File.dirname(__FILE__), 'update_project')

module Compass
  module Commands
    class WatchProject < UpdateProject

      attr_accessor :last_update_time

      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

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

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

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
bsherman-compass-0.5.2 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.5.1 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.5.2 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.5.3 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.5.4 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.5.5 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.5.9 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.6.0 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.6.1 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.6.2 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.6.3 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.6.4 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.6.5 lib/compass/commands/watch_project.rb
jwhitmire-compass-0.5.1.1 lib/compass/commands/watch_project.rb
jwhitmire-compass-0.5.1.2 lib/compass/commands/watch_project.rb