class Guard::Nanoc

Public Class Methods

live_cmd() click to toggle source
# File lib/guard/nanoc.rb, line 10
def self.live_cmd
  @_live_cmd ||= begin
    path = File.join(File.dirname(__FILE__), 'nanoc', 'live_command.rb')
    Cri::Command.load_file(path, infer_name: true)
  end
end
new(options = {}) click to toggle source
Calls superclass method
# File lib/guard/nanoc.rb, line 17
def initialize(options = {})
  @dir = options[:dir] || '.'
  super
end

Public Instance Methods

run_all() click to toggle source
# File lib/guard/nanoc.rb, line 27
def run_all
  recompile_in_subprocess
end
run_on_changes(_paths) click to toggle source
# File lib/guard/nanoc.rb, line 31
def run_on_changes(_paths)
  recompile_in_subprocess
end
run_on_removals(_paths) click to toggle source
# File lib/guard/nanoc.rb, line 35
def run_on_removals(_paths)
  recompile_in_subprocess
end
start() click to toggle source
# File lib/guard/nanoc.rb, line 22
def start
  setup_listeners
  recompile_in_subprocess
end

Protected Instance Methods

notify_failure() click to toggle source
# File lib/guard/nanoc.rb, line 77
def notify_failure
  Compat::UI.notify('Compilation FAILED', title: 'nanoc', image: :failed)
  Compat::UI.error 'Compilation failed!'
end
notify_success() click to toggle source
# File lib/guard/nanoc.rb, line 72
def notify_success
  Compat::UI.notify('Compilation succeeded', title: 'nanoc', image: :success)
  Compat::UI.info 'Compilation succeeded.'
end
recompile() click to toggle source
# File lib/guard/nanoc.rb, line 58
def recompile
  # Necessary, because forking and threading don’t work together.
  ::Nanoc::Core::NotificationCenter.force_reset

  Dir.chdir(@dir) do
    site = ::Nanoc::Core::SiteLoader.new.new_from_cwd
    ::Nanoc::Core::Compiler.compile(site)
  end
  notify_success
rescue => e
  notify_failure
  ::Nanoc::CLI::ErrorHandler.print_error(e)
end
recompile_in_subprocess() click to toggle source
# File lib/guard/nanoc.rb, line 49
def recompile_in_subprocess
  if Process.respond_to?(:fork)
    pid = Process.fork { recompile }
    Process.waitpid(pid)
  else
    recompile
  end
end
setup_listeners() click to toggle source
# File lib/guard/nanoc.rb, line 41
def setup_listeners
  ::Nanoc::CLI.setup

  ::Nanoc::CLI::CompileListeners::FileActionPrinter
    .new(reps: [])
    .start_safely
end