lib/nanoc3/cli/commands/watch.rb in nanoc3-3.2.0a1 vs lib/nanoc3/cli/commands/watch.rb in nanoc3-3.2.0a2

- old
+ new

@@ -30,10 +30,15 @@ end def run(options, arguments) require 'fssm' + Signal.trap("INT") do + puts + exit + end + @notifier = Notifier.new # Define rebuilder rebuilder = lambda do |base, relative| # Determine filename @@ -51,21 +56,31 @@ end # Recompile start = Time.now site = Nanoc3::Site.new('.') - site.load_data begin - site.compiler.run + site.compile # TODO include icon (--image misc/success-icon.png) - @notifier.notify('Compilation complete') + notify_on_compilation_success = site.config.has_key?(:notify_on_compilation_success) ? + site.config[:notify_on_compilation_success] : + true + if notify_on_compilation_success + @notifier.notify('Compilation complete') + end - puts "done in #{((Time.now - start)*10000).round.to_f / 10}ms" + 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) - @notifier.notify('Compilation failed') + notify_on_compilation_failure = site.config.has_key?(:notify_on_compilation_failure) ? + site.config[:notify_on_compilation_failure] : + true + if notify_on_compilation_failure + @notifier.notify('Compilation failed') + end puts @base.print_error(e) puts end @@ -94,39 +109,19 @@ # Allows sending user notifications in a cross-platform way. class Notifier # A list of commandline tool names that can be used to send notifications - TOOLS = %w( growlnotify notify_send ) + TOOLS = %w( growlnotify notify-send ) - # Error that is raised when no notifier can be found. - class NoNotifierFound < ::StandardError - - def initialize - super("Could not find a notifier that works on this system. I tried to find #{CrossPlatformNotifier::TOOLS.join(', ')} but found nothing.") - end - - end - - # Send a notification. + # Send a notification. If no notifier is found, no notification will be + # created. # # @param [String] message The message to include in the notification - # - # @option params [Boolean] :raise (true) true if this method should - # raise an exception if no notifier can be found, false otherwise - def notify(message, params={}) - params[:raise] = true if !params.has_key?(:raise) - - if tool.nil? - if params[:raise] - raise NoNotifierFound - else - return - end - end - - send(tool, message, params) + def notify(message) + return if tool.nil? + send(tool.tr('-', '_'), message, params) end private def tool @@ -136,10 +131,10 @@ def growlnotify(message, params={}) system('growlnotify', '-m', message) end def notify_send(message, params={}) - system('notify_send', messsage) + system('notify-send', message) end end end