+ def run(options)
+ require 'webrick'
+ listener = options[:watch] && start_watcher
+
+ puts "Serving at http://localhost:8000/ ..."
+ server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => CONFIG[:output_dir]
+ trap 'INT' do
+ server.shutdown
+ end
+ server.start
+ listener.stop if listener
+ end
+end
+
+def main
+ Liquid::Template.register_tag('tree', Tag_tree)
+ Liquid::Template.register_tag('children', Tag_children)
+ Liquid::Template.register_tag('prevnext', Tag_prevnext)
+
+ if defined? Liquid::Template.error_mode
+ Liquid::Template.error_mode = :strict
+ end
+
+ options = {}
+ OptionParser.new do |opts|
+ opts.on("--watch", "Watch for changes") { options[:watch] = true }
+ end.parse!
+
+ Site.new.build
+
+ if ARGV == ['serve']
+ Server.new.run(options)
+ end
+end