Module: Stack
- Defined in:
- lib/stack.rb,
lib/stack/runner.rb,
lib/stack/server.rb,
lib/stack/watcher.rb,
lib/stack/parsable.rb,
lib/stack/template.rb,
lib/stack/generator.rb,
lib/stack/configuration.rb,
lib/stack/filters/string.rb,
lib/stack/templates/page.rb,
lib/stack/filters/datetime.rb,
lib/stack/filters/register.rb,
lib/stack/filters/standard.rb,
lib/stack/templates/layout.rb,
lib/stack/filters/convertors.rb
Defined Under Namespace
Modules: Filters, Parsable, Template, Templates Classes: Configuration, Generator, Runner, Server, Watcher
Constant Summary collapse
- DEFAULTS =
Default options used by stack, overridden from the command line or YML configration file.
{ :source => '.', :target => File.join('.', '_stack') }.freeze
- COMMANDS =
Array of valid commands stack can use
%w(create generate server watch)
- EXTENSIONS =
Array of transformable extensions (these extensions go through the liquid transformer)
%w(.html .markdown .mdown .mkdn .md .textile .js .css)
Class Attribute Summary collapse
-
.runner ⇒ Object
Returns the value of attribute runner.
Class Method Summary collapse
-
.configuration(override) ⇒ Object
Merges the configuration from YAML file, command line and defaults.
-
.parse!(argv) ⇒ Object
Parses the options configuration from the command line.
-
.version ⇒ Object
Stacks current version.
Class Attribute Details
.runner ⇒ Object
Returns the value of attribute runner.
47 48 49 |
# File 'lib/stack.rb', line 47 def runner @runner end |
Class Method Details
.configuration(override) ⇒ Object
Merges the configuration from YAML file, command line and defaults
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/stack.rb', line 77 def self.configuration(override) config = { } source = File.join(override[:source] || Stack::DEFAULTS[:source]) config_file = File.join(source, "_stack.yml") begin yml = YAML.load_file(config_file) raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash) yml.each { |key, value| config[key.to_sym] = value } STDOUT.puts "Configuration loaded from #{config_file}" rescue => error STDERR.puts "WARNING: Could not read configuration. Using defaults (and options)." STDERR.puts "\t" + error.to_s end # Merge configuration with defaults Stack::DEFAULTS.deep_merge(override).deep_merge(config) end |
.parse!(argv) ⇒ Object
Parses the options configuration from the command line
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/stack.rb', line 51 def self.parse!(argv) config = { } parser = OptionParser.new do |opts| opts. = "Usage: stack [options] #{Stack::COMMANDS.join('|')}" 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" end end opts.on("-t", "--target [DIR]", "Directory to use as the target directory") do |l| config[:target] = l unless l.nil? end 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 parser.parse! argv = Stack::configuration(config) end |
.version ⇒ Object
Stacks current version
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/stack.rb', line 101 def self.version version_file = File.join(File.dirname(__FILE__), *%w[.. VERSION.yml]) if File.exist?(version_file) yml = YAML.load(File.read(version_file)) "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}" else "0.0.0" end end |