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/utils/standard.rb,
lib/stack/filters/datetime.rb,
lib/stack/filters/register.rb,
lib/stack/filters/standard.rb,
lib/stack/templates/layout.rb,
lib/stack/templates/article.rb,
lib/stack/filters/convertors.rb

Defined Under Namespace

Modules: Filters, Parsable, Template, Templates, Utils 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'),
  :server => {
    :port => 4000,
    :watch => true
  }
}.freeze
COMMANDS =

Array of valid commands stack can use

%w(create generate gen server watch)
EXTENSIONS =

Array of transformable extensions (these extensions go through the liquid transformer)

%w(.html .markdown .mdown .mkdn .md .textile .js .less .css)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.runnerObject

Returns the value of attribute runner.



54
55
56
# File 'lib/stack.rb', line 54

def runner
  @runner
end

Class Method Details

.configuration(override) ⇒ Object

Merges the configuration from YAML file, command line and defaults



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/stack.rb', line 96

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/stack.rb', line 58

def self.parse!(argv)
  config = Stack::DEFAULTS.dup
  
  parser = OptionParser.new do |opts|
    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] = 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
  
  parser.parse! argv
  
  options = Stack::configuration(config)
  
  options
end

.versionObject

Stacks current version



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/stack.rb', line 120

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