Sha256: 46dcf91ed8cf1651ba0544ba573a067ef39852a39fbe45e92ac1060b1062bf25

Contents?: true

Size: 1.87 KB

Versions: 10

Compression:

Stored size: 1.87 KB

Contents

require 'fileutils'
require 'pathname'
require 'compass/commands/base'
require 'compass/commands/update_project'

module Compass
  module Commands
    class WatchProject < UpdateProject

      register :watch

      attr_accessor :last_update_time, :last_sass_files

      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

      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

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

    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/compass-0.10.0.pre4/lib/compass/commands/watch_project.rb
compass-0.10.0.pre4 lib/compass/commands/watch_project.rb
compass-0.10.0.pre3 lib/compass/commands/watch_project.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/lib/compass/commands/watch_project.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/lib/compass/commands/watch_project.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/lib/compass/commands/watch_project.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/compass-0.10.0.pre2/lib/compass/commands/watch_project.rb
compass-0.10.0.pre2 lib/compass/commands/watch_project.rb
compass-0.10.0.pre1 lib/compass/commands/watch_project.rb
compass-edge-0.9.5.0 lib/compass/commands/watch_project.rb