Last active
August 29, 2015 14:00
-
-
Save mloberg/11165632 to your computer and use it in GitHub Desktop.
guard-jekyll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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