Class: Nanoc3::CLI::Commands::AutoCompile

Inherits:
Nanoc3::CLI::Command show all
Defined in:
lib/nanoc3/cli/commands/autocompile.rb

Instance Attribute Summary

Attributes inherited from Nanoc3::CLI::Command

#arguments, #command, #options

Instance Method Summary collapse

Methods inherited from Nanoc3::CLI::Command

#call, call, #initialize, #site

Constructor Details

This class inherits a constructor from Nanoc3::CLI::Command

Instance Method Details

#runObject



24
25
26
27
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
# File 'lib/nanoc3/cli/commands/autocompile.rb', line 24

def run
  require 'rack'

  # Make sure we are in a nanoc site directory
  self.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