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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/fuse/main.rb', line 26
def self.main
options = {}
options_parser = OptionParser.new do |opts|
"
Usage: #{$0} command [options]
Commands:
server : Run a local testing server
compile : Compile the document and send to STDOUT
Options:
".strip.lines.each { |line| opts.separator line }
opts.on('-a',
'--addr',
wrap("Server binding address. Defaults to #{DEFAULTS[:server][:addr]}. Use 0.0.0.0 for access from other computers. Be careful; server will allow access to any locally accessible file of Fuse's supported types.")
) do |addr|
options[:addr] = addr
end
opts.on('-c',
'--[no-]compress-assets',
'Compress assets.'
) do |compress|
options[:compress_assets] = compress
end
opts.on('-e',
'--encoding CHARSET',
wrap("Output encoding. Default is #{DEFAULTS[:common][:encoding]}.")
) do |e|
options[:encoding] = e
end
opts.on('-m',
'--[no-]embed-assets',
'Embed assets.'
) do |embed|
options[:embed_assets] = embed
end
opts.on('-p',
'--port PORT',
Integer,
wrap("Port on which to listen (only with 'server' command). Default is #{DEFAULTS[:server][:port]}.")
) do |port|
options[:port] = port
end
opts.on('-s',
'--source [FILE|DIR]',
wrap('The source directory, or HTML or XML document. Default is current directory.')
) do |doc|
options[:source] = doc
end
opts.on('-t',
'--title TITLE',
'HTML document title.'
) do |t|
options[:title] = t
end
opts.on('-v',
'--version',
'Show Fuse version.'
) { abort Fuse::VERSION }
opts.on('-w',
'--[no-]preserve-white',
wrap("Preserve all white space in HTML. Default is #{DEFAULTS[:common][:preserve_white]}.")
) { |w| options[:preserve_white] = w }
opts.on('-x',
'--xsl FILE',
wrap('XSL transformation stylesheet. Default is current directory.')
) do |xsl|
abort "#{xsl} isn't a valid XSL stylesheet" unless xsl.match(/\.xsl$/i)
options[:xsl] = xsl
end
opts.on_tail('-h', '--help', 'Show this message.') { summary opts }
end
options_parser.parse!
options = merge_defaults(options)
case ARGV[0]
when 'server'
Thin::Server.start(options[:addr], options[:port]) do
use Rack::ShowExceptions
run Server.new(options)
end
when 'compile'
begin
doc = Document.new(options)
log "Compiling #{doc.source_path}"
out = doc.to_s
print out
log "Wrote #{out.bytesize} byte(s) to STDOUT.", :success
rescue Exception::SourceUnknown::TooManySources
log "Found more than one potential #{$!.option_name} document. Please specify one with --#{$!.option_name}.", :notice
log $!.options.join "\n"
rescue Exception
$!.message ? log($!.message, :error) : raise
end
else
summary options_parser
end
end
|