yard-medoosa 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/yard-medoosa +4 -0
- data/lib/yard/medoosa.rb +71 -0
- data/lib/yard-medoosa.rb +22 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0a9aafb3def317dbf7e7f5259184d680c5f32b582f84d4c6ee93780b124b330f
|
4
|
+
data.tar.gz: 5ad2dc042c73e4f978fd5fce7d96cf8617ffb8580da6f2a0c19ae09d82796621
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f9cb843b309cb15f360ce9ae088b4bfd71207ce53516579d1e7f5b2e2b8c829ec65a147fbea7c7d85458e8b6db00bb244d30c9f669d463ddc4d5f9a62f6ea15
|
7
|
+
data.tar.gz: ddbca4431c1d454d161c1746a4e96c7b9a4a3acbb854afe7d85ccc66909f2ed1e4d53295d032cd2098977baaf9598f3ed9607c6b93f76471d3adea0d84085925
|
data/bin/yard-medoosa
ADDED
data/lib/yard/medoosa.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "yard"
|
2
|
+
require "fileutils"
|
3
|
+
require "graphviz"
|
4
|
+
|
5
|
+
module YARD
|
6
|
+
# Enhance YARD documentation by generating class diagrams
|
7
|
+
module Medoosa
|
8
|
+
def module_children(namespace)
|
9
|
+
namespace.children.find_all do |code_object|
|
10
|
+
case code_object
|
11
|
+
when YARD::CodeObjects::ModuleObject, YARD::CodeObjects::ClassObject
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param graph [Graphviz::Graph]
|
18
|
+
# @param all_nodes [Hash{String => Graphviz::Node}] (filled by the method)
|
19
|
+
# @param namespace [YARD::CodeObjects::NamespaceObject]
|
20
|
+
def add_clusters(graph, all_nodes, namespace)
|
21
|
+
children = module_children(namespace)
|
22
|
+
if children.empty?
|
23
|
+
href = namespace.path.gsub("::", "/") + ".html"
|
24
|
+
n = graph.add_node(namespace.path,
|
25
|
+
label: namespace.name, shape: "box", href: href)
|
26
|
+
all_nodes[namespace.path] = n
|
27
|
+
else
|
28
|
+
if namespace.is_a? YARD::CodeObjects::RootObject
|
29
|
+
sg = graph
|
30
|
+
else
|
31
|
+
sg = graph.add_subgraph(cluster: true)
|
32
|
+
sg.attributes[:name] = namespace.path
|
33
|
+
sg.attributes[:label] = namespace.name
|
34
|
+
end
|
35
|
+
children.each do |c|
|
36
|
+
add_clusters(sg, all_nodes, c)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param basepath Where the YARD output goes
|
42
|
+
def generate_medoosa(basepath)
|
43
|
+
YARD::Registry.load!
|
44
|
+
|
45
|
+
g = Graphviz::Graph.new
|
46
|
+
all_nodes = {}
|
47
|
+
add_clusters(g, all_nodes, YARD::Registry.root)
|
48
|
+
|
49
|
+
YARD::Registry.all(:class).each do |code_object|
|
50
|
+
sup = YARD::Registry.resolve(nil, code_object.superclass)
|
51
|
+
next if sup.nil?
|
52
|
+
|
53
|
+
n = all_nodes.fetch(code_object.path)
|
54
|
+
n_sup = all_nodes.fetch(sup.path)
|
55
|
+
n_sup.connect(n, arrowtail: "onormal", dir: "back")
|
56
|
+
end
|
57
|
+
|
58
|
+
base_fn = "#{basepath}/medoosa-nesting"
|
59
|
+
|
60
|
+
File.open("#{base_fn}.f.dot", "w") do |f|
|
61
|
+
g.dump_graph(f)
|
62
|
+
end
|
63
|
+
|
64
|
+
system "unflatten -l5 -c5 -o#{base_fn}.dot #{base_fn}.f.dot"
|
65
|
+
system "dot -Tpng -o#{base_fn}.png #{base_fn}.dot"
|
66
|
+
system "dot -Tsvg -o#{base_fn}.svg #{base_fn}.dot"
|
67
|
+
|
68
|
+
"#{base_fn}.svg"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/yard-medoosa.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "yard/medoosa"
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module CLI
|
5
|
+
# Monkey patch YARD to hook into `yard doc`
|
6
|
+
class Yardoc
|
7
|
+
include Medoosa
|
8
|
+
|
9
|
+
def run_generate_with_medoosa(*args)
|
10
|
+
run_generate_without_medoosa(*args)
|
11
|
+
fname = generate_medoosa(options.serializer.basepath)
|
12
|
+
options.files << CodeObjects::ExtraFileObject.new(fname)
|
13
|
+
# FIXME: what, do we really run it twice?!
|
14
|
+
# yes, until I figure out a better place to hook generate_medoosa in
|
15
|
+
run_generate_without_medoosa(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias run_generate_without_medoosa run_generate
|
19
|
+
alias run_generate run_generate_with_medoosa
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yard-medoosa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Vidner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: graphviz
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: Enhance YARD documentation by generating class diagrams.
|
28
|
+
email: martin@vidner.net
|
29
|
+
executables:
|
30
|
+
- yard-medoosa
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/yard-medoosa
|
35
|
+
- lib/yard-medoosa.rb
|
36
|
+
- lib/yard/medoosa.rb
|
37
|
+
homepage: https://rubygems.org/gems/yard-medoosa
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.7.6.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: YARD class diagrams
|
61
|
+
test_files: []
|