Class: Nanoc::CLI::Commands::AutoCompile

Inherits:
Nanoc::CLI::CommandRunner show all
Defined in:
lib/nanoc/cli/commands/autocompile.rb

Instance Method Summary (collapse)

Methods inherited from Nanoc::CLI::CommandRunner

#call, call, #debug?, #in_site_dir?, #load_site, #require_site, #site

Instance Method Details

- (Object) run



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nanoc/cli/commands/autocompile.rb', line 28

def run
  warn 'WARNING: The `autocompile` command is deprecated. Please consider using `guard-nanoc` instead (see https://github.com/nanoc/guard-nanoc).'

  require 'rack'

  # Make sure we are in a nanoc site directory
  require_site
  autocompile_config = site.config[:autocompile] || {}

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

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

  # Build app
  autocompiler = Nanoc::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