/
ptree.rb
65 lines (53 loc) · 1.45 KB
/
ptree.rb
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
$: << 'lib'
require 'json'
require 'flor/unit'
GURI = 'https://github.com/floraison/flor/blob/master/'
INDEX = (
[ Flor::Procedure, Flor::Macro ] +
Flor::Pro.constants.collect { |c| Flor::Pro.const_get(c) }
)
.inject({}) { |h, c|
next h unless c.respond_to?(:names)
as = (c.ancestors.select { |cl| cl.to_s.match(/^Flor::/) } - [ Flor::Node ])
ns = c.names
h[c] = { class: c, ancestors: as, names: c.names }
h }
INDEX
.each { |k, v|
v[:ancestors][1..-1].each { |a|
a = INDEX[a]
next unless a
(a[:children] ||= []) << k } }
Dir['lib/flor/{pcore,punit}/*.rb']
.each { |path|
m = File.read(path).match(/^class (Flor::.+) < /)
next unless m
k = Flor.const_lookup(m[1])
INDEX[k][:spath] = path }
Dir['doc/procedures/*.md']
.each { |path|
s = File.read(path)
m = s.match(/^# ([- ,_a-z0-9]+)/)
next unless m
names = m[1].split(/, */)
INDEX.values.each { |h|
hnames = (h[:names] || []).collect { |n| n.gsub(/\?/, '') }
next unless (hnames & names).any?
h[:dpath] = path } }
def render(level, klass)
d = INDEX[klass]
ns = d[:names]
dp = d[:dpath]
print "#{' ' * level}* [#{klass}](#{GURI}#{d[:spath]})"
if ns && dp
dp = dp.split('/').last
print " : [#{ns.join(', ')}](#{dp})"
elsif ns
print " : #{ns.join(', ')}"
end
puts
(d[:children] || [])
.sort_by { |c| c.to_s }
.each { |c| render(level + 1, c) }
end
render(0, Flor::Procedure)