Instantly share code, notes, and snippets.

@mloberg /Guardfile
Last active Aug 29, 2015

Embed
What would you like to do?
guard-jekyll
require 'jekyll'
module ::Guard
class Jekyll < Guard
def start
puts "Starting Jekyll on port #{port}"
options = ::Jekyll.configuration({:serving => true, :watch => true, :port => port})
p = ::Process.fork do
::Jekyll::Commands::Build.process(options)
::Jekyll::Commands::Serve.process(options)
end
save_pid(p)
::Proccess.detach(p)
puts "Jekyll is running with pid #{p}"
end
def stop
if pid
puts "Sending INT signal to Jekyll (#{pid})"
::Process.kill("INT", pid)
true
end
end
def reload
stop
start
end
def run_all
true
end
def run_on_change(paths)
true
end
private
def save_pid(p)
File.open(pidfile_path, 'w') { |f| f.write(p) }
end
def pidfile_path
options.fetch(:pidfile) {
File.expand_path('tmp/jekyll.pid', File.dirname(__FILE__))
}
end
def pid
File.exist?(pidfile_path) && File.read(pidfile_path).to_i
end
def port
options.fetch(:port) { 4000 }
end
end
end
# Available options: :pidfile, :port
guard 'jekyll'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment