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
|
# File 'lib/okf/cli/render.rb', line 23
def call(argv)
require "okf/render/graph"
options = { output: nil, title: nil, link: nil, layout: "cose", map: false }
parser = OptionParser.new do |o|
o.banner = "Usage: okf render <dir|@slug> [-o FILE] [--layout NAME] [-t title] [-l url]"
o.on("-o", "--output FILE", "write to FILE instead of stdout") { |v| options[:output] = v }
o.on("-t", "--title TITLE", "graph title (default: parent/bundle dir name)") { |v| options[:title] = v }
o.on("-l", "--link URL", "source URL shown in the header") { |v| options[:link] = v }
o.on("--layout NAME", OKF::Render::Graph::LAYOUTS, "initial layout (#{OKF::Render::Graph::LAYOUTS.join(", ")})") { |v| options[:layout] = v }
o.on("--map", "open in the Map view: concepts boxed by directory, links on selection") { options[:map] = true }
help_flag(o)
end
dir = positional_dir(parser, argv) or return 2
folder = OKF::Bundle::Folder.load(dir)
report_skipped(folder)
html = OKF::Render::Graph.static(folder, title: options[:title], link: options[:link], layout: options[:layout], map: options[:map])
if options[:output]
begin
File.write(options[:output], html)
rescue SystemCallError => e
return usage_error("cannot write #{options[:output]}: #{e.message}")
end
count = folder.bundle.concepts.size
@out.puts "wrote #{count} #{pluralize(count, "concept")} to #{options[:output]}"
else
@out.print html
end
0
end
|