-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,58 @@ | ||
module Compass | ||
module Watcher | ||
|
||
class LivereloadWatch < Watch | ||
def match?(changed_path) | ||
@glob.split(/,/).each do |ext| | ||
changed_path =~ Regexp.new("#{ext}\\Z") | ||
end | ||
end | ||
end | ||
|
||
class AppWatcher < ProjectWatcher | ||
def initialize(project_path, watches=[], options={}, poll=false) | ||
super | ||
@watchers << livereload_watchers | ||
setup_listener | ||
end | ||
|
||
def listen_callback(modified_files, added_files, removed_files) | ||
#log_action(:info, ">>> Listen Callback fired added: #{added_files}, mod: #{modified_files}, rem: #{removed_files}", {}) | ||
files = {:modified => modified_files, | ||
:added => added_files, | ||
:removed => removed_files} | ||
require 'livereload.rb' | ||
|
||
run_once, run_each = watchers.partition {|w| w.run_once_per_changeset?} | ||
class AppWatcher < Compass::Commands::WatchProject | ||
def initialize(project_path, options={}) | ||
super | ||
|
||
run_once.each do |watcher| | ||
if file = files.values.flatten.detect{|f| watcher.match?(f) } | ||
action = files.keys.detect{|k| files[k].include?(file) } | ||
log_action(:warning, Dir.pwd, {}) | ||
log_action(:warning, project_path.inspect,{}) | ||
watcher.run_callback(project_path, relative_to(file, project_path), action) | ||
end | ||
end | ||
CompassHooker::WatchHooker.watches += livereload_watchers | ||
|
||
end | ||
|
||
run_each.each do |watcher| | ||
files.each do |action, list| | ||
list.each do |file| | ||
watcher.run_callback(project_path, relative_to(file, project_path), action) if watcher.match?(file) | ||
end | ||
end | ||
end | ||
java.lang.System.gc() | ||
end | ||
def watch! | ||
perform | ||
sass_compiler.compile! | ||
end | ||
|
||
def stop | ||
listener = sass_compiler.compiler.listener | ||
|
||
log_action(:info, "AppWatcher stop!",{}) | ||
begin | ||
listener.stop if listener and listener.adapter | ||
rescue Exception => e | ||
log_action(:warning, "#{e.message}\n#{e.backtrace}", {}) | ||
end | ||
|
||
def watch! | ||
compile | ||
super | ||
end | ||
end | ||
|
||
def stop | ||
log_action(:info, "AppWatcher stop!",{}) | ||
begin | ||
listener.stop | ||
rescue Exception => e | ||
log_action(:warning, "#{e.message}\n#{e.backtrace}", {}) | ||
end | ||
end | ||
|
||
def custom_watcher(dir, extensions, callback) | ||
filter = File.join(dir, extensions) | ||
childe_filter = File.join(dir, "**", extensions) | ||
|
||
def livereload_watchers | ||
Watcher::LivereloadWatch.new(::App::CONFIG["services_livereload_extensions"], &method(:livereload_callback)) | ||
end | ||
[Compass::Configuration::Watch.new(filter, &callback), | ||
Compass::Configuration::Watch.new(childe_filter, &callback)] | ||
end | ||
|
||
def livereload_watchers | ||
watches = [] | ||
App::CONFIG["services_livereload_extensions"].split(/\s*,\s*/).each do |ext| | ||
watches += custom_watcher("", "*.#{ext}", method(:livereload_callback)) | ||
end | ||
watches | ||
end | ||
|
||
def livereload_callback(base, file, action) | ||
puts ">>> #{action} detected to: #{file}" | ||
SimpleLivereload.instance.send_livereload_msg( base, file ) if SimpleLivereload.instance.alive? | ||
def livereload_callback(base, file, action) | ||
puts ">>> #{action} detected to: #{file}" | ||
SimpleLivereload.instance.send_livereload_msg( base, file ) if SimpleLivereload.instance.alive? | ||
|
||
if App::CONFIG["notifications"].include?(:overwrite) && action == :modified | ||
App.notifications << "Changed: #{file}" | ||
end | ||
if App::CONFIG["notifications"].include?(:overwrite) && action == :modified | ||
App.notifications << "Changed: #{file}" | ||
end | ||
|
||
tray = Tray.instance | ||
tray.shell.display.wake if tray.shell | ||
end | ||
tray = Tray.instance | ||
tray.shell.display.wake if tray.shell | ||
end | ||
|
||
def setup_listener | ||
@listener = Listen.to(@project_path, :relative_paths => true) | ||
if poll | ||
@listener = listener.force_polling(true) | ||
end | ||
@listener = listener.polling_fallback_message(POLLING_MESSAGE) | ||
#@listener = listener.ignore(/\.css$/) # we dont ignore .css, because we need livereload | ||
@listener = listener.change(&method(:listen_callback)) | ||
end | ||
|
||
end | ||
end | ||
end |