Class: Nanoc3::CLI::Commands::Autocompile

Inherits:
Cri::Command
  • Object
show all
Defined in:
lib/nanoc3/cli/commands/autocompile.rb

Instance Method Summary

Instance Method Details

- (Object) aliases



11
12
13
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 11

def aliases
  [ 'aco' ]
end

- (Object) long_desc



19
20
21
22
23
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 19

def long_desc
  'Start the autocompiler web server. Unless specified, the web ' +
  'server will run on port 3000 and listen on all IP addresses. ' +
  'Running the autocompiler requires \'mime/types\' and \'rack\'.'
end

- (Object) name



7
8
9
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 7

def name
  'autocompile'
end

- (Object) option_definitions



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 29

def option_definitions
  [
    # --handler
    {
      :long => 'handler', :short => 'H', :argument => :required,
      :desc => 'specify the handler to use (webrick/mongrel/...)'
    },
    # --host
    {
      :long => 'host', :short => 'o', :argument => :required,
      :desc => 'specify the host to listen on (default: 0.0.0.0)'
    },
    # --port
    {
      :long => 'port', :short => 'p', :argument => :required,
      :desc => 'specify the port to listen on (default: 3000)'
    }
  ]
end

- (Object) run(options, arguments)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 49

def run(options, arguments)
  require 'rack'

  # Make sure we are in a nanoc site directory
  @base.require_site

  # Set options
  options_for_rack = {
    :Port      => (options[:port] || 3000).to_i,
    :Host      => (options[:host] || '0.0.0.0')
  }

  # Guess which handler we should use
  unless handler = Rack::Handler.get(options[:handler])
    begin
      handler = Rack::Handler::Mongrel
    rescue LoadError => e
      handler = Rack::Handler::WEBrick
    end
  end

  # Build app
  autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
  app = Rack::Builder.new do
    use Rack::CommonLogger, $stderr
    use Rack::ShowExceptions
    run autocompiler
  end.to_app

  # Run autocompiler
  puts "Running on http://#{options_for_rack[:Host]}:#{options_for_rack[:Port]}/"
  handler.run(app, options_for_rack)
end

- (Object) short_desc



15
16
17
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 15

def short_desc
  'start the autocompiler'
end

- (Object) usage



25
26
27
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 25

def usage
  "nanoc3 autocompile [options]"
end