#!/usr/bin/env ruby # For running when gem not installed $:.unshift File.dirname(File.dirname(__FILE__)) + "/lib" require "rubygems" require "optparse" require "guider/app" require "guider/social" GUIDER_VERSION = '0.0.8' def format_footer(text) guider = "Guider" date = Time.new.strftime('%a %d %b %Y %H:%M:%S') text.gsub(/\{VERSION\}/, GUIDER_VERSION).gsub(/\{GUIDER\}/, guider).gsub(/\{DATE\}/, date) end options = { :output => Dir.pwd + "/out", :title => "Guides", :footer => format_footer("Generated on {DATE} by {GUIDER} {VERSION}."), :link_url => "http://localhost/extjs/", :tpl_dir => File.dirname(File.dirname(__FILE__)) + "/template", :warnings => false, :social => [], :search => nil, :analytics => nil, } input_files = OptionParser.new do |opts| opts.banner = "Generates a guide.\n\n" + "Usage: guider \n\n" opts.on("-o", "--output=DIR", "Where to output the guides.", "Defaults to ./out") do |dir| options[:output] = File.expand_path(dir) end opts.on("--title=TEXT", "The title for the whole set of guides.", "Defaults to: Guides.") do |title| options[:title] = title end opts.on("--footer=TEXT", "The footer text.", "Defaults to: Generated on {DATE} by {GUIDER} {VERSION}.") do |footer| options[:footer] = format_footer(footer) end opts.on("--link-url=URL", "Base path for links created by {@link} tags.", "Defaults to http://localhost/extjs/") do |url| options[:link_url] = url end opts.on("--index=PATH", "The guides.json file to create index.html from.") do |path| options[:index] = path end opts.on("--social=google,twitter,facebook", Array, "Buttons to add to the page.") do |social| social = social.map {|t| t.to_sym } unsupported = social.find_all {|t| !Guider::Social.supported_types.include?(t) } if unsupported.length > 0 $stderr.puts "ERROR: Unsupported social button type: " + unsupported.join(" ") exit(1) end options[:social] = social end opts.on("--search=id", "ID of custom google search engine.") do |id| options[:search] = id end opts.on("--analytics=id", "ID for Google Analytics tracking.") do |id| options[:analytics] = id end opts.on("--warnings", "Enables warnings.") do options[:warnings] = true end opts.on("-h", "--help", "Show this help message") do puts opts exit end opts.on("--version", "Prints guider version number.") do puts "Guider #{GUIDER_VERSION}" exit end end.parse! if input_files.length == 1 options[:input] = File.expand_path(input_files[0]) else $stderr.puts "ERROR: Exactly one input directory must be specified." exit(1) end Guider::App.new(options).run