Class: Nanoc2::CLI::AutocompileCommand

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#aliasesObject



9
10
11
# File 'lib/nanoc2/cli/commands/autocompile.rb', line 9

def aliases
  [ 'aco', 'autocompile_site' ]
end

#long_descObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/nanoc2/cli/commands/autocompile.rb', line 17

def long_desc
  handler_names = Nanoc2::Extra::AutoCompiler::HANDLER_NAMES.join(', ')

  '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\'.' +
  "\n" +
  'Available handlers are (in order of preference): ' + handler_names +
  ' (default is ' + Nanoc2::Extra::AutoCompiler::HANDLER_NAMES[0].to_s + ').'
end

#nameObject



5
6
7
# File 'lib/nanoc2/cli/commands/autocompile.rb', line 5

def name
  'autocompile'
end

#option_definitionsObject



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

def option_definitions
  [
    # --all
    {
      :long => 'all', :short => 'a', :argument => :forbidden,
      :desc => 'compile all pages, even those that aren\'t outdated'
    },
    # --port
    {
      :long => 'port', :short => 'p', :argument => :required,
      :desc => 'specify a port number for the autocompiler'
    },
    # --handler
    {
      :long => 'handler', :short => 'H', :argument => :required,
      :desc => 'specify the handler to use'
    }
  ]
end

#run(options, arguments) ⇒ Object



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
# File 'lib/nanoc2/cli/commands/autocompile.rb', line 52

def run(options, arguments)
  # Check arguments
  if arguments.size != 0
    $stderr.puts "usage: #{usage}"
    exit 1
  end

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

  # Autocompile site
  begin
    autocompiler = Nanoc2::Extra::AutoCompiler.new(@base.site, options.has_key?(:all))
    autocompiler.start(
      options[:port],
      options[:handler]
    )
  rescue LoadError
    $stderr.puts "'mime/types' and 'rack' are required to autocompile sites. " +
                 "You may want to install the 'mime-types' and 'rack' gems by " +
                 "running 'gem install mime-types' and 'gem install rack'."
  rescue Nanoc2::Extra::AutoCompiler::UnknownHandlerError
    $stderr.puts "The requested handler, #{options[:handler]}, is not available."
  end
end

#short_descObject



13
14
15
# File 'lib/nanoc2/cli/commands/autocompile.rb', line 13

def short_desc
  'start the autocompiler'
end

#usageObject



28
29
30
# File 'lib/nanoc2/cli/commands/autocompile.rb', line 28

def usage
  "nanoc2 autocompile [options]"
end