Sha256: 6ff2a8c20eb16b8172619910a285d95b3063491c52260e8d65356839d5965ee0

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 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
        super
        self.last_update_time = most_recent_update_time
        loop do
          # TODO: Make this efficient by using filesystem monitoring.
          sleep 1
          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("#{project_directory}/src/**/*.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("#{project_directory}/src/**/*.sass")).detect {|sass_file| File.stat(sass_file).mtime >= t}
          [file, t]
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
chriseppstein-compass-0.1.1 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.3.0 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.3.1 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.3.2 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.3.3 lib/compass/commands/watch_project.rb
chriseppstein-compass-0.3.4 lib/compass/commands/watch_project.rb