lib/nanoc/cli/commands/watch.rb in nanoc-3.6.2 vs lib/nanoc/cli/commands/watch.rb in nanoc-3.6.3

- old
+ new

@@ -78,16 +78,16 @@ rebuilder.call(modified[0]) if modified[0] rebuilder.call(added[0]) if added[0] rebuilder.call(removed[0]) if removed[0] end - listener = Listen::MultiListener.new(*dirs_to_watch).change(&callback) - listener_root = Listen::MultiListener.new('', :filter => files_to_watch, :ignore => ignore_dir).change(&callback) + listener = Listen::Listener.new(*dirs_to_watch).change(&callback) + listener_root = Listen::Listener.new('.', :filter => files_to_watch, :ignore => ignore_dir).change(&callback) begin - listener_root.start(false) - listener.start + listener_root.start + listener.start! rescue Interrupt listener.stop listener_root.stop end end @@ -96,46 +96,79 @@ class Notifier # A list of commandline tool names that can be used to send notifications TOOLS = %w( growlnotify notify-send ) unless defined? TOOLS - # The tool to use for discovering binaries' locations - FIND_BINARY_COMMAND = RUBY_PLATFORM =~ /mingw|mswin/ ? "where" : "which" unless defined? FIND_BINARY_COMMAND - # Send a notification. If no notifier is found, no notification will be # created. # # @param [String] message The message to include in the notification def notify(message) return if tool.nil? - send(tool.tr('-', '_'), message) + if tool == 'growlnotify' && self.on_windows? + self.growlnotify_windows(message) + else + send(tool.tr('-', '_'), message) + end end - private + protected + def have_tool_nix?(tool) + !`which #{tool}`.empty? + rescue Errno::ENOENT + false + end + + def have_tool_windows?(tool) + !`where #{tool} 2> nul`.empty? + rescue Errno::ENOENT + false + end + + def have_tool?(tool) + if self.on_windows? + self.have_tool_windows?(tool) + else + self.have_tool_nix?(tool) + end + end + def tool @tool ||= begin require 'terminal-notifier' 'terminal-notify' rescue LoadError - begin - TOOLS.find { |t| !`#{FIND_BINARY_COMMAND} #{t}`.empty? } - rescue Errno::ENOENT - nil - end + TOOLS.find { |t| have_tool?(t) } end end def terminal_notify(message) TerminalNotifier.notify(message, :title => "nanoc") end + def growlnotify_cmd_for(message) + [ 'growlnotify', '-m', message ] + end + def growlnotify(message) - system('growlnotify', '-m', message) + system(*self.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)) + end + def notify_send(message) system('notify-send', message) + end + + def on_windows? + !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i) end end end