Sha256: 11c88d845a25fa6c07160f5cccae3a9547f3ba30e69bb18a197c887502314b37

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

require 'listen'

module Fontrobot
  class Watcher
    def self.watch(*args)
      callback = Proc.new do |modified, added, removed|
        puts '    >> Changed: ' + modified.join(' ') unless modified.empty?
        puts '    >> Added: ' + added.join(' ') unless added.empty?
        puts '    >> Removed: ' + removed.join(' ') unless removed.empty?

        changed = modified + added + removed
        Fontrobot.compile(*args) unless changed.empty?
      end

      dir = args.first
      @listener = Listen.to(dir).filter(/\.(eps|svg)$/).change(&callback)

      begin
        puts 'Fontrobot is watching your icons at ' + dir
        puts 'Press Ctrl + C to stop.'
        Fontrobot.compile(*args)
        @listener.start()

      # Catches Ctrl + C
      # Does listen gem have a better way of handling this?
      rescue SignalException
        stop
      end
    end

    def self.stop
      # Newline exists so message is not prepended with ^C on SIGTERM
      puts "\nFontrobot is signing off. Goodnight and good luck."
      @listener.stop
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fontrobot-0.1.8 lib/fontrobot/watcher.rb
fontrobot-0.1.7 lib/fontrobot/watcher.rb
fontrobot-0.1.6 lib/fontrobot/watcher.rb
fontrobot-0.1.5 lib/fontrobot/watcher.rb
fontrobot-0.1.4 lib/fontrobot/watcher.rb
fontrobot-0.1.3 lib/fontrobot/watcher.rb
fontrobot-0.1.2 lib/fontrobot/watcher.rb
fontrobot-0.1 lib/fontrobot/watcher.rb