lib/slippery/rake_tasks.rb in slippery-0.2.0 vs lib/slippery/rake_tasks.rb in slippery-0.3.0
- old
+ new
@@ -1,7 +1,7 @@
require 'rake/tasklib'
-require 'rb-inotify'
+require 'listen'
module Slippery
class RakeTasks < Rake::TaskLib
attr_reader :name
attr_accessor :presentations, :options, :processors
@@ -53,11 +53,10 @@
@infile.dirname.join('assets'),
@infile
).(doc)
end
-
def title(title)
processor 'head' do |head|
head <<= H[:title, title]
end
end
@@ -86,39 +85,31 @@
files = files.select {|f| File.exist?(f)}
desc "watch #{name} for changes"
WatchTask.new(name, [path.to_s, *files]) do
dest = Tempfile.new("#{name}.html")
- File.open("#{name}.html") { |src| FileUtils.copy_stream(src, dest) }
+ File.open("#{name}.html", 'w+') { |src| FileUtils.copy_stream(src, dest) }
dest.close
Rake::Task["#{@name}:build:#{name}"].execute
puts "="*60
print `diff -u #{dest.path} #{name}.html | cut -c1-150` if File.exist? "#{name}.html"
end
end
end
-
end
-
end
end
class WatchTask
def initialize(name, files, &block)
Rake::Task.define_task name do
- Array(files).each do |pattern|
- notifier.watch(pattern, :modify, &block)
- end
+ listener = Listen.to('.', :only => /#{files.join('|')}/, &block)
+
at_exit do
- block.call
- notifier.run
+ listener.start # not blocking
+ sleep
end
end
end
-
- def notifier
- @notifier ||= INotify::Notifier.new
- end
end
-
end