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

  • Cri::Command
    • Nanoc3::CLI::Commands::Autocompile

Public Visibility

Public Instance Method Summary

#aliases
#long_desc
#name
#option_definitions
#run(options, arguments)
#short_desc
#usage

Public Instance Method Details

aliases

public aliases
[View source]


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

def aliases
  [ 'aco' ]
end

long_desc

public long_desc
[View source]


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

name

public name
[View source]


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

def name
  'autocompile'
end

option_definitions

public option_definitions
[View source]


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

def option_definitions
  [
    # --port
    {
      :long => 'port', :short => 'p', :argument => :required,
      :desc => 'specify a port number for the autocompiler'
    },
    # --server
    {
      :long => 'server', :short => 's', :argument => :required,
      :desc => 'specify the server 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

run

public run(options, arguments)
[View source]


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
82
83
84
85
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 54

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[:server])
    begin
      handler = Rack::Handler::Mongrel
    rescue LoadError => e
      handler = Rack::Handler::WEBrick
    end
  end

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

  # Run autocompiler
  handler.run(app, options_for_rack)
end

short_desc

public short_desc
[View source]


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

def short_desc
  'start the autocompiler'
end

usage

public usage
[View source]


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

def usage
  "nanoc3 autocompile [options]"
end
Generated on Sunday, August 09 2009 at 01:43:06 PM by YARD 0.2.3.2 (ruby-1.8.7).