Class: Nanoc::CLI::Commands::View

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

Constant Summary

DEFAULT_HANDLER_NAME =
:thin

Instance Method Summary collapse

Instance Method Details

#runObject



17
18
19
20
21
22
23
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
# File 'lib/nanoc/cli/commands/view.rb', line 17

def run
  load_adsf
  require 'rack'

  load_site

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

  # Get handler
  if options.key?(:handler)
    handler = Rack::Handler.get(options[:handler])
  else
    begin
      handler = Rack::Handler.get(DEFAULT_HANDLER_NAME)
    rescue LoadError
      handler = Rack::Handler::WEBrick
    end
  end

  # Build app
  site = self.site
  app = Rack::Builder.new do
    use Rack::CommonLogger
    use Rack::ShowExceptions
    use Rack::Lint
    use Rack::Head
    use Adsf::Rack::IndexFileFinder, root: site.config[:output_dir]
    run Rack::File.new(site.config[:output_dir])
  end.to_app

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