lib/stack.rb in stack-0.0.6 vs lib/stack.rb in stack-0.0.7

- old
+ new

@@ -8,10 +8,11 @@ require 'mash' require 'RedCloth' require 'less' require 'webrick' +require 'core_ext/string' require 'core_ext/hash' require 'stack/configuration' require 'stack/generator' require 'stack/runner' @@ -19,49 +20,67 @@ require 'stack/template' require 'stack/parsable' require 'stack/server' require 'stack/watcher' -require 'stack/templates/page' -require 'stack/templates/layout' - require 'stack/filters/register' require 'stack/filters/standard' require 'stack/filters/convertors' require 'stack/filters/datetime' require 'stack/filters/string' +require 'stack/templates/page' +require 'stack/templates/layout' + +require 'stack/utils/standard' + module Stack # Default options used by stack, overridden from the command line or YML configration file. DEFAULTS = { :source => '.', - :target => File.join('.', '_stack') + :target => File.join('.', '_stack'), + :server => { + :port => 4000, + :watch => true + } }.freeze # Array of valid commands stack can use - COMMANDS = %w(create generate server watch) + COMMANDS = %w(create generate gen server watch) # Array of transformable extensions (these extensions go through the liquid transformer) - EXTENSIONS = %w(.html .markdown .mdown .mkdn .md .textile .js .css) + EXTENSIONS = %w(.html .markdown .mdown .mkdn .md .textile .js .less .css) class << self attr_accessor :runner end # Parses the options configuration from the command line def self.parse!(argv) - config = { } + config = Stack::DEFAULTS.dup parser = OptionParser.new do |opts| - opts.banner = "Usage: stack [options] #{Stack::COMMANDS.join('|')}" + opts.banner = "Usage: stack #{Stack::COMMANDS.join('|')} [options...]" + opts.separator "" + opts.separator "Generator options:" + opts.on("-s", "--source [DIR]", "Directory to use as the source for generating a stack") do |l| if !l.nil? config[:source] = l - config[:target] = "#{config[:source]}_stack" + config[:target] = File.join(config[:source], "_stack") end end opts.on("-t", "--target [DIR]", "Directory to use as the target directory") do |l| config[:target] = l unless l.nil? end + + opts.separator "" + opts.separator "Server options:" + + opts.on("-p", "--port [PORT]", "Port number to use when serving content") do |l| config[:server][:port] = l unless l.nil? end + opts.on("--disable-watch", "--disable-watch", "Disables automatic transformation when serving content") do |l| config[:server][:watch] = false end + + opts.separator "" + opts.separator "Common options:" opts.on_tail("-h", "--help", "Show this message") { puts opts; exit } opts.on_tail("-v", "--version", "Show version") do puts "stack #{Stack::version}"; exit; end end \ No newline at end of file