1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
86
87
88
89
90
|
module Nanoc3::CLI::Commands
class View < Cri::Command
def name
'view'
end
def aliases
[]
end
def short_desc
'start the web server that serves static files'
end
def long_desc
'Start the static web server. Unless specified, the web server will run on port 3000 and listen on all IP addresses. Running the autocompiler requires \'adsf\' and \'rack\'.'
end
def usage
"nanoc3 view [options]"
end
def option_definitions
[
{
:long => 'port', :short => 'p', :argument => :required,
:desc => 'specify a port number for the autocompiler'
},
{
:long => 'handler', :short => 'h', :argument => :required,
:desc => 'specify the handler to use (webrick/mongrel/...)'
},
{
:long => 'host', :short => 'o', :argument => :required,
:desc => 'specify the host to listen on (default: 0.0.0.0)'
},
{
:long => 'port', :short => 'p', :argument => :required,
:desc => 'specify the port to listen on (default: 3000)'
}
]
end
def run(options, arguments)
require 'rack'
require 'adsf'
@base.require_site
options_for_rack = {
:Port => (options[:port] || 3000).to_i,
:Host => (options[:host] || '0.0.0.0')
}
unless handler = Rack::Handler.get(options[:handler])
begin
handler = Rack::Handler::Mongrel
rescue LoadError => e
handler = Rack::Handler::WEBrick
end
end
site = @base.site
app = Rack::Builder.new do
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::Lint
use Adsf::Rack::IndexFileFinder, :root => site.config[:output_dir]
run Rack::File.new(site.config[:output_dir])
end.to_app
handler.run(app, options_for_rack)
end
end
end
|