class Bolt::Bolt

Public Class Methods

new() click to toggle source
# File lib/bolt.rb, line 14
def initialize
  $config = OpenStruct.new
  @commands = {"create" => true,
               "build" => true,
               "serve" => true}
end

Public Instance Methods

run() click to toggle source

Parses command line options then runs the specified command

# File lib/bolt.rb, line 22
def run
  parse_options
  run_command
end

Private Instance Methods

build() click to toggle source

Creates a new build object and runs it resulting in building a bolt project and saving all files into the “out” directory.

# File lib/bolt.rb, line 42
def build
  require 'bolt/build'
  Build.new.run
end
create() click to toggle source

Creates a new project object and runs it resulting in creating all nessecary directories for a new bolt project

# File lib/bolt.rb, line 35
def create
  require 'bolt/project'
  Project.new.run
end
parse_options() click to toggle source

Parses command line options

# File lib/bolt.rb, line 53
def parse_options
  $config.resources = "resources"
  $config.lib = "lib"
  $config.views = "views"
  $config.out = "out"
  $config.pages = "pages"
  $config.config = "config.yml"
  $config.serve_host = "127.0.0.1"
  $config.serve_port = "2658"
  
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: bolt {create/build/serve} [options] [file]"

    opts.on("-r", "--resources [resource-dir]", "Resources directory") do |opts|
      $config.resources = opts
    end
    
    opts.on("-v", "--views [views-dir]", "Views directory") do |opts|
      $config.views = opts
    end
    
    opts.on("-l", "--lib [lib-dir]", "Library directory") do |opts|
      $config.lib = opts
    end
    
    opts.on("-p", "--pages [pages-dir]", "Pages directory") do |opts|
      $config.pages = opts
    end

    opts.on("-o", "--out [out-directory]", "Where to save HTML") do |opts|
      $config.out = opts
    end
    
    opts.on("-c", "--config [config-file.yml]", "Config file") do |opts|
      $config.config = opts
    end
    
    opts.on("-H", "--host [host]", "Serve development server host") do |opts|
      $config.serve_host = opts
    end
    
    opts.on("-P", "--port [port]", "Serve development server port") do |opts|
      $config.serve_port = opts
    end

    opts.on_tail("-h", "--help", "Show this help message") do
      puts opts
      exit        
    end

    opts.parse!(ARGV)  
  end

  if ARGV.empty? || ARGV.count > 2 || @commands[ARGV[0]].nil?
    puts opts.help
    exit
  else
    $config.command = ARGV[0]
    $config.base_dir = (ARGV.count == 2) ? ARGV[1] : "."
    $config.base_dir += '/' if $config.base_dir[-1..$config.base_dir.length] != '/'
  end
end
run_command() click to toggle source

Runs a command specified on the command line

# File lib/bolt.rb, line 29
def run_command
  self.send($config.command)
end
serve() click to toggle source
# File lib/bolt.rb, line 47
def serve
  require 'bolt/serve'
  Serve.new.run
end