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
|
# File 'lib/railroad_diagrams/command.rb', line 11
def run(argv)
OptionParser.new do |opts|
opts.banner = <<~BANNER
This is a test runner for railroad_diagrams:
Usage: railroad_diagrams [options] [files]
BANNER
opts.on('-f', '--format FORMAT', 'Output format (svg, ascii, unicode, standalone)') do |format|
@format = format
end
opts.on('-h', '--help', 'Print this help') do
puts opts
exit
end
opts.on('-v', '--version', 'Print version') do
puts "railroad_diagrams #{RailroadDiagrams::VERSION}"
exit 0
end
opts.parse!(argv)
end
@test_list = argv
puts <<~HTML
<!doctype html>
<html>
<head>
<title>Test</title>
HTML
case @format
when 'ascii'
TextDiagram.set_formatting(TextDiagram::PARTS_ASCII)
when 'unicode'
TextDiagram.set_formatting(TextDiagram::PARTS_UNICODE)
when 'svg', 'standalone'
TextDiagram.set_formatting(TextDiagram::PARTS_UNICODE)
puts <<~CSS
<style>
#{Style.default_style}
.blue text { fill: blue; }
</style>
CSS
end
puts '</head><body>'
File.open('test.rb', 'r:utf-8') do |fh|
eval(fh.read, binding, 'test.rb')
end
puts '</body></html>'
end
|