Module: YARD::Medoosa
- Included in:
- CLI::Yardoc
- Defined in:
- lib/yard/medoosa.rb
Overview
Enhance YARD documentation by generating class diagrams
Instance Method Summary collapse
- #add_clusters(graph, all_nodes, namespace) ⇒ Object
- #generate_medoosa(basepath) ⇒ Object
- #module_children(namespace) ⇒ Object
Instance Method Details
#add_clusters(graph, all_nodes, namespace) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yard/medoosa.rb', line 20 def add_clusters(graph, all_nodes, namespace) children = module_children(namespace) if children.empty? href = namespace.path.gsub("::", "/") + ".html" n = graph.add_node(namespace.path, label: namespace.name, shape: "box", href: href) all_nodes[namespace.path] = n else if namespace.is_a? YARD::CodeObjects::RootObject sg = graph else sg = graph.add_subgraph(cluster: true) sg.attributes[:name] = namespace.path sg.attributes[:label] = namespace.name end children.each do |c| add_clusters(sg, all_nodes, c) end end end |
#generate_medoosa(basepath) ⇒ Object
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 |
# File 'lib/yard/medoosa.rb', line 42 def generate_medoosa(basepath) YARD::Registry.load! g = Graphviz::Graph.new all_nodes = {} add_clusters(g, all_nodes, YARD::Registry.root) YARD::Registry.all(:class).each do |code_object| sup = YARD::Registry.resolve(nil, code_object.superclass) next if sup.nil? n = all_nodes.fetch(code_object.path) n_sup = all_nodes.fetch(sup.path) n_sup.connect(n, arrowtail: "onormal", dir: "back") end base_fn = "#{basepath}/medoosa-nesting" File.open("#{base_fn}.f.dot", "w") do |f| g.dump_graph(f) end system "unflatten -l5 -c5 -o#{base_fn}.dot #{base_fn}.f.dot" system "dot -Tpng -o#{base_fn}.png #{base_fn}.dot" system "dot -Tsvg -o#{base_fn}.svg #{base_fn}.dot" "#{base_fn}.svg" end |