#!/usr/bin/env ruby $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require 'optparse' require 'rubygems' require 'gollum-site' help = < ( head = Grit::Repo.new('.').head ) ? head.name : 'master', # current branch 'base_path' => '/', 'output_path' => '_site', 'port' => 8000, 'include_default_layout' => true } opts = OptionParser.new do |opts| opts.banner = help opts.on("--ref [REF]", "Branch or commit to generate") do |ref| options['ref'] = ref end opts.on("--base_path [BASE_PATH]", "Prefix to apply to internal links") do |base_path| options['base_path'] = base_path end opts.on("--output_path [OUTPUT_PATH]", "Path to write generated site") do |output_path| options['output_path'] = output_path end opts.on("--port [PORT]", "Port to use when serving site (default 8000)") do |port| options['port'] = port end opts.on("--include_default_layout", "Include a default layout if one is not present") do |include_default_layout| options['include_default_layout'] = include_default_layout end opts.on_tail("--help", "Show this information") do puts opts exit end opts.on_tail("--version", "Display current version.") do require 'gollum-site/version' puts "Gollum Site " + Gollum::Site::VERSION exit 0 end end opts.parse! cmd = ARGV[0] case cmd when 'generate' wiki = Gollum::Wiki.new('.', {:base_path => options['base_path']}) site = Gollum::Site.new(wiki, { :output_path => options['output_path'], :include_default_layout => options['include_default_layout']}) site.generate(options['ref']) when 'serve' require 'webrick' include WEBrick mime_types = WEBrick::HTTPUtils::DefaultMimeTypes mime_types.store 'js', 'application/javascript' s = HTTPServer.new( :Port => options['port'], :DocumentRoot => options['output_path'], :MimeTypes => mime_types, :DirectoryIndex => 'Home.html' ) t = Thread.new { s.start } trap("INT") { s.shutdown } t.join() else puts opts exit end