lib/nanoc/cli/commands/watch.rb in nanoc-3.6.7 vs lib/nanoc/cli/commands/watch.rb in nanoc-3.6.8
- old
+ new
@@ -16,11 +16,11 @@
require 'listen'
require 'pathname'
require_site
- watcher_config = self.site.config[:watcher] || {}
+ watcher_config = site.config[:watcher] || {}
@notifier = Notifier.new
# Define rebuilder
rebuilder = lambda do |file_path|
@@ -33,11 +33,11 @@
# Notify
if filename
print "Change detected to #{filename}; recompiling… "
else
- print "Watcher started; compiling the entire site… "
+ print 'Watcher started; compiling the entire site… '
end
# Recompile
start = Time.now
site = Nanoc::Site.new('.')
@@ -48,11 +48,11 @@
notify_on_compilation_success = watcher_config.fetch(:notify_on_compilation_success) { true }
if notify_on_compilation_success
@notifier.notify('Compilation complete')
end
- time_spent = ((Time.now - start)*1000.0).round
+ time_spent = ((Time.now - start) * 1000.0).round
puts "done in #{format '%is %ims', *(time_spent.divmod(1000))}"
rescue Exception => e
# TODO include icon (--image misc/error-icon.png)
notify_on_compilation_failure = watcher_config.fetch(:notify_on_compilation_failure) { true }
if notify_on_compilation_failure
@@ -67,19 +67,19 @@
# Rebuild once
rebuilder.call(nil)
# Get directories to watch
- dirs_to_watch = watcher_config[:dirs_to_watch] || [ 'content', 'layouts', 'lib' ]
- files_to_watch = watcher_config[:files_to_watch] || [ 'nanoc.yaml', 'config.yaml', 'Rules', 'rules', 'Rules.rb', 'rules.rb' ]
+ dirs_to_watch = watcher_config[:dirs_to_watch] || %w( content layouts lib )
+ files_to_watch = watcher_config[:files_to_watch] || %w( nanoc.yaml config.yaml Rules rules Rules.rb rules.rb )
files_to_watch = Regexp.new(files_to_watch.map { |name| Regexp.quote(name) + '$' }.join('|'))
ignore_dir = Regexp.new(Dir.glob('*').map { |dir| dir if File.directory?(dir) }.compact.join('|'))
# Watch
- puts "Watching for changes…"
+ puts 'Watching for changes…'
- callback = Proc.new do |modified, added, removed|
+ callback = proc do |modified, added, removed|
rebuilder.call(modified[0]) if modified[0]
rebuilder.call(added[0]) if added[0]
rebuilder.call(removed[0]) if removed[0]
end
@@ -106,17 +106,17 @@
#
# @param [String] message The message to include in the notification
def notify(message)
return if tool.nil?
if tool == 'growlnotify' && self.on_windows?
- self.growlnotify_windows(message)
+ growlnotify_windows(message)
else
send(tool.tr('-', '_'), message)
end
end
- protected
+ protected
def have_tool_nix?(tool)
!`which #{tool}`.empty?
rescue Errno::ENOENT
false
@@ -144,26 +144,26 @@
TOOLS.find { |t| have_tool?(t) }
end
end
def terminal_notify(message)
- TerminalNotifier.notify(message, :title => "nanoc")
+ TerminalNotifier.notify(message, :title => 'nanoc')
end
def growlnotify_cmd_for(message)
[ 'growlnotify', '-m', message ]
end
def growlnotify(message)
- system(*self.growlnotify_cmd_for(message))
+ system(*growlnotify_cmd_for(message))
end
def growlnotify_windows_cmd_for(message)
[ 'growlnotify', '/t:nanoc', message ]
end
def growlnotify_windows(message)
- system(*self.growlnotify_windows_cmd_for(message))
+ system(*growlnotify_windows_cmd_for(message))
end
def notify_send(message)
system('notify-send', message)
end