Skip to content

Instantly share code, notes, and snippets.

@CarterA
Created October 2, 2011 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarterA/1257914 to your computer and use it in GitHub Desktop.
Save CarterA/1257914 to your computer and use it in GitHub Desktop.
Streamlined Yardwork
require "term/ansicolor"
include Term::ANSIColor
def printHeader headerText
print bold + blue + "==> " + reset
print bold + headerText + reset + "\n"
end
require 'webrick'
require 'directory_watcher'
require "jekyll"
include WEBrick
task :build do
printHeader "Compiling website..."
options = Jekyll.configuration({})
@site = Jekyll::Site.new(options)
@site.process
end
def globs(source)
Dir.chdir(source) do
dirs = Dir['*'].select { |x| File.directory?(x) }
dirs -= ['_site']
dirs = dirs.map { |x| "#{x}/**/*" }
dirs += ['*']
end
end
task :develop => :build do
printHeader "Auto-regenerating enabled."
directoryWatcher = DirectoryWatcher.new("./")
directoryWatcher.interval = 1
directoryWatcher.glob = globs(Dir.pwd)
directoryWatcher.add_observer do |*args| @site.process end
directoryWatcher.start
mimeTypes = WEBrick::HTTPUtils::DefaultMimeTypes
mimeTypes.store 'js', 'application/javascript'
server = HTTPServer.new(
:BindAddress => "localhost",
:Port => 4000,
:DocumentRoot => "_site",
:MimeTypes => mimeTypes,
:Logger => Log.new($stderr, Log::ERROR),
:AccessLog => [["/dev/null", AccessLog::COMBINED_LOG_FORMAT ]]
)
thread = Thread.new { server.start }
trap("INT") { server.shutdown }
printHeader "Development server started at http://localhost:4000/"
printHeader "Opening website in default web browser..."
%x[open http://localhost:4000/]
printHeader "Development mode entered."
thread.join()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment