yard-markdown 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.streerc +2 -0
- data/README.md +16 -9
- data/Rakefile +4 -2
- data/example/Bird.md +1 -1
- data/example/Duck.md +1 -1
- data/example/Waterfowl.md +1 -1
- data/example/index.csv +18 -0
- data/lib/yard-markdown.rb +1 -1
- data/templates/default/fulldoc/markdown/setup.rb +93 -32
- metadata +7 -6
- data/.standard.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45d1e77bad42779c78eb819361eeef638e1eb6a6b622ef7f850298258a4cbf14
|
4
|
+
data.tar.gz: 715a1015c9d12f9ccdd13e9afe20f70e3b566dc9996161b8cedfcc7eecbcc9bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c813cfeaad842d55c9b4573fa91f025ac07d78b8bb512a45f32af671a25c213d34e4291c6346ab0e43e141fab89dd82ba5ca279760e17b4ac06a1f042c39fd26
|
7
|
+
data.tar.gz: 4080476f10d33d9d98c39ca2d04e4834c2a1ef8308451ad102022991286f88e4f42bba1fbdf5ddac53a1c16ad3cb40fa53eb656b72d59d5155a6e6ea589db4d6
|
data/.streerc
ADDED
data/README.md
CHANGED
@@ -1,25 +1,32 @@
|
|
1
1
|
# Yard::Markdown
|
2
2
|
|
3
|
-
Yard
|
3
|
+
Yard plugin to generate markdown documentation
|
4
4
|
|
5
5
|
## Goals:
|
6
6
|
- Compatible with Github Flavored Markdown
|
7
|
-
- Mimick yard html layout
|
7
|
+
- Mimick yard html layout where it makes sense to maintain familiarity
|
8
8
|
- Produce .csv index file alonside markdown documentation to act as file index
|
9
|
+
- Include markdown files that are already present in source code.
|
9
10
|
|
10
11
|
## Usage
|
11
|
-
|
12
|
+
Yard doesn't load plugin by default, so you need to load plugin through `~/.yard/config`:
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
!!!yaml
|
16
|
+
load_plugins: true
|
17
|
+
autoload_plugins:
|
18
|
+
- markdown
|
19
|
+
```
|
20
|
+
|
21
|
+
Install a plugin
|
12
22
|
```
|
13
|
-
gem
|
23
|
+
gem install yard-markdown
|
14
24
|
```
|
15
|
-
And run `bundle install`
|
16
25
|
|
17
|
-
Run yardoc
|
26
|
+
Run `yardoc --format=markdown` to generate markdown documentation.
|
18
27
|
|
19
28
|
## Backstory
|
20
|
-
|
21
|
-
|
22
|
-
This gem is used by documentation reviewing tool called [POSH TUI](https://poshtui.com)
|
29
|
+
This is a successor to [rdoc-mardown gem](https://github.com/skatkov/rdoc-markdown/tree/main/example) with small differences in implementation. This gem was written to power API documentation browser CLI app for ruby developers called [POSH TUI](https://poshtui.com).
|
23
30
|
|
24
31
|
## Testing
|
25
32
|
Unit tests can't really test this gem properly. So it's semi-manual process of making changes and reviewing output.
|
data/Rakefile
CHANGED
@@ -9,6 +9,8 @@ Rake::TestTask.new(:test) do |t|
|
|
9
9
|
t.test_files = FileList["test/**/test_*.rb"]
|
10
10
|
end
|
11
11
|
|
12
|
-
require "
|
12
|
+
require "syntax_tree/rake_tasks"
|
13
|
+
SyntaxTree::Rake::CheckTask.new
|
14
|
+
SyntaxTree::Rake::WriteTask.new
|
13
15
|
|
14
|
-
task default: %i[test
|
16
|
+
task default: %i[test stree:write]
|
data/example/Bird.md
CHANGED
data/example/Duck.md
CHANGED
data/example/Waterfowl.md
CHANGED
data/example/index.csv
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
name,type,path
|
2
|
+
Waterfowl,Module,Waterfowl.md
|
3
|
+
DEFAULT_DUCK_VELOCITY,Constant,Waterfowl.md#constant-DEFAULT_DUCK_VELOCITY
|
4
|
+
swim,Method,Waterfowl.md#method-i-swim
|
5
|
+
Bird,Class,Bird.md
|
6
|
+
DEFAULT_DUCK_VELOCITY,Constant,Bird.md#constant-DEFAULT_DUCK_VELOCITY
|
7
|
+
_fly_impl,Method,Bird.md#method-i-_fly_impl
|
8
|
+
fly,Method,Bird.md#method-i-fly
|
9
|
+
speak,Method,Bird.md#method-i-speak
|
10
|
+
Duck,Class,Duck.md
|
11
|
+
DEFAULT_DUCK_VELOCITY,Constant,Duck.md#constant-DEFAULT_DUCK_VELOCITY
|
12
|
+
initialize,Method,Duck.md#method-i-initialize
|
13
|
+
speak,Method,Duck.md#method-i-speak
|
14
|
+
swim,Method,Duck.md#method-i-swim
|
15
|
+
useful?,Method,Duck.md#method-i-useful?
|
16
|
+
rubber_ducks,Method,Duck.md#method-c-rubber_ducks
|
17
|
+
domestic,Attribute,Duck.md#attribute-i-domestic
|
18
|
+
rubber,Attribute,Duck.md#attribute-i-rubber
|
data/lib/yard-markdown.rb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
# https://github.com/lsegal/yard/blob/2d197a381c5d4cc5c55b2c60fff992b31c986361/docs/CodeObjects.md
|
4
4
|
|
5
5
|
require "erb"
|
6
|
+
require "csv"
|
6
7
|
|
7
|
-
|
8
|
-
# here I need to copy README.md if there is one.
|
9
|
-
# I also need to write index.md files
|
8
|
+
include Helpers::ModuleHelper
|
10
9
|
|
10
|
+
def init
|
11
11
|
options.objects = objects = run_verifier(options.objects)
|
12
12
|
|
13
13
|
options.delete(:objects)
|
@@ -21,19 +21,79 @@ def init
|
|
21
21
|
next if object.name == :root
|
22
22
|
|
23
23
|
begin
|
24
|
-
Templates::Engine.with_serializer(object, options.serializer)
|
25
|
-
serialize(object)
|
26
|
-
end
|
24
|
+
Templates::Engine.with_serializer(object, options.serializer) { serialize(object) }
|
27
25
|
rescue => e
|
28
26
|
path = options.serializer.serialized_path(object)
|
29
27
|
log.error "Exception occurred while generating '#{path}'"
|
30
28
|
log.backtrace(e)
|
31
29
|
end
|
32
30
|
end
|
31
|
+
|
32
|
+
serialize_index(objects)
|
33
|
+
end
|
34
|
+
|
35
|
+
def serialize_index(objects)
|
36
|
+
filepath = "#{options.serializer.basepath}/index.csv"
|
37
|
+
|
38
|
+
CSV.open(filepath, "wb") do |csv|
|
39
|
+
csv << %w[name type path]
|
40
|
+
|
41
|
+
objects.each do |object|
|
42
|
+
next if object.name == :root
|
43
|
+
|
44
|
+
if object.type == :class
|
45
|
+
csv << [object.name, "Class", options.serializer.serialized_path(object)]
|
46
|
+
elsif object.type == :module
|
47
|
+
csv << [object.name, "Module", options.serializer.serialized_path(object)]
|
48
|
+
end
|
49
|
+
|
50
|
+
if constant_listing.size.positive?
|
51
|
+
constant_listing.each do |cnst|
|
52
|
+
csv << [
|
53
|
+
cnst.name(false),
|
54
|
+
"Constant",
|
55
|
+
(options.serializer.serialized_path(object) + "#" + aref(cnst)),
|
56
|
+
]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if (insmeths = public_instance_methods(object)).size > 0
|
61
|
+
insmeths.each do |item|
|
62
|
+
csv << [
|
63
|
+
item.name(false),
|
64
|
+
"Method",
|
65
|
+
options.serializer.serialized_path(object) + "#" + aref(item),
|
66
|
+
]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if (pubmeths = public_class_methods(object)).size > 0
|
71
|
+
pubmeths.each do |item|
|
72
|
+
csv << [
|
73
|
+
item.name(false),
|
74
|
+
"Method",
|
75
|
+
options.serializer.serialized_path(object) + "#" + aref(item),
|
76
|
+
]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
if (attrs = attr_listing(object)).size > 0
|
81
|
+
attrs.each do |item|
|
82
|
+
csv << [
|
83
|
+
item.name(false),
|
84
|
+
"Attribute",
|
85
|
+
options.serializer.serialized_path(object) + "#" + aref(item),
|
86
|
+
]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
33
91
|
end
|
34
92
|
|
35
93
|
def serialize(object)
|
36
|
-
template =
|
94
|
+
template =
|
95
|
+
ERB.new(
|
96
|
+
'# <%= format_object_title object %>
|
37
97
|
| | |
|
38
98
|
| -----------------: | :----- |
|
39
99
|
<% if CodeObjects::ClassObject === object && object.superclass %>
|
@@ -56,8 +116,8 @@ def serialize(object)
|
|
56
116
|
<% groups(constant_listing, "Constants") do |list, name| %>
|
57
117
|
# <%= name %>
|
58
118
|
<% list.each do |cnst| %>
|
59
|
-
## <%= cnst.name %> =
|
60
|
-
|
119
|
+
## <%= cnst.name %> = [](#<%=aref(cnst)%>)
|
120
|
+
<%= cnst.docstring %>
|
61
121
|
<% end %>
|
62
122
|
<% end %>
|
63
123
|
|
@@ -88,13 +148,17 @@ def serialize(object)
|
|
88
148
|
|
89
149
|
<% end %>
|
90
150
|
<% end %>
|
91
|
-
'.gsub(/^ /, ""),
|
151
|
+
'.gsub(/^ /, ""),
|
152
|
+
trim_mode: "%<>",
|
153
|
+
)
|
92
154
|
|
93
155
|
template.result(binding)
|
94
156
|
end
|
95
157
|
|
96
158
|
def aref(object)
|
97
|
-
if
|
159
|
+
if object.type == :constant
|
160
|
+
"constant-#{object.name(false)}"
|
161
|
+
elsif !object.attr_info.nil?
|
98
162
|
"attribute-#{object.scope[0]}-#{object.name(false)}"
|
99
163
|
else
|
100
164
|
"#{object.type}-#{object.scope[0]}-#{object.name(false)}"
|
@@ -103,15 +167,17 @@ end
|
|
103
167
|
|
104
168
|
def constant_listing
|
105
169
|
return @constants if defined?(@constants) && @constants
|
170
|
+
|
106
171
|
@constants = object.constants(included: false, inherited: false)
|
107
172
|
@constants += object.cvars
|
108
173
|
@constants
|
109
174
|
end
|
110
175
|
|
111
|
-
include Helpers::ModuleHelper
|
112
|
-
|
113
176
|
def public_method_list(object)
|
114
|
-
prune_method_listing(
|
177
|
+
prune_method_listing(
|
178
|
+
object.meths(inherited: false, visibility: [:public]),
|
179
|
+
included: false,
|
180
|
+
).sort_by { |m| m.name.to_s }
|
115
181
|
end
|
116
182
|
|
117
183
|
def public_class_methods(object)
|
@@ -124,18 +190,19 @@ end
|
|
124
190
|
|
125
191
|
def attr_listing(object)
|
126
192
|
@attrs = []
|
127
|
-
object
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
193
|
+
object
|
194
|
+
.inheritance_tree(true)
|
195
|
+
.each do |superclass|
|
196
|
+
next if superclass.is_a?(CodeObjects::Proxy)
|
197
|
+
next if !options.embed_mixins.empty? && !options.embed_mixins_match?(superclass)
|
198
|
+
%i[class instance].each do |scope|
|
199
|
+
superclass.attributes[scope].each do |_name, rw|
|
200
|
+
attr = prune_method_listing([rw[:read], rw[:write]].compact, false).first
|
201
|
+
@attrs << attr if attr
|
202
|
+
end
|
135
203
|
end
|
204
|
+
break if options.embed_mixins.empty?
|
136
205
|
end
|
137
|
-
break if options.embed_mixins.empty?
|
138
|
-
end
|
139
206
|
sort_listing @attrs
|
140
207
|
end
|
141
208
|
|
@@ -151,7 +218,7 @@ def generate_method_list
|
|
151
218
|
end
|
152
219
|
|
153
220
|
def sort_listing(list)
|
154
|
-
list.sort_by {|o| [o.scope.to_s, o.name.to_s.downcase] }
|
221
|
+
list.sort_by { |o| [o.scope.to_s, o.name.to_s.downcase] }
|
155
222
|
end
|
156
223
|
|
157
224
|
def groups(list, type = "Method")
|
@@ -166,13 +233,7 @@ def groups(list, type = "Method")
|
|
166
233
|
else
|
167
234
|
others = []
|
168
235
|
group_data = {}
|
169
|
-
list.each
|
170
|
-
if itm.group
|
171
|
-
(group_data[itm.group] ||= []) << itm
|
172
|
-
else
|
173
|
-
others << itm
|
174
|
-
end
|
175
|
-
end
|
236
|
+
list.each { |itm| itm.group ? (group_data[itm.group] ||= []) << itm : others << itm }
|
176
237
|
group_data.each { |group, items| yield(items, group) unless items.empty? }
|
177
238
|
end
|
178
239
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stanislav (Stas) Katkov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description: yard
|
27
|
+
description: yard plugin to generates markdown documentation for gems
|
28
28
|
email:
|
29
29
|
- yard-markdown@skatkov.com
|
30
30
|
executables: []
|
@@ -32,7 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".editorconfig"
|
35
|
-
- ".
|
35
|
+
- ".streerc"
|
36
36
|
- ".yardopts"
|
37
37
|
- LICENSE.txt
|
38
38
|
- README.md
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- example/Bird.md
|
42
42
|
- example/Duck.md
|
43
43
|
- example/Waterfowl.md
|
44
|
+
- example/index.csv
|
44
45
|
- lib/yard-markdown.rb
|
45
46
|
- sig/yard/markdown.rbs
|
46
47
|
- templates/default/fulldoc/markdown/setup.rb
|
@@ -65,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
- !ruby/object:Gem::Version
|
66
67
|
version: '0'
|
67
68
|
requirements: []
|
68
|
-
rubygems_version: 3.4
|
69
|
+
rubygems_version: 3.5.4
|
69
70
|
signing_key:
|
70
71
|
specification_version: 4
|
71
|
-
summary: yard
|
72
|
+
summary: yard plugin to generate markdown documentation
|
72
73
|
test_files: []
|
data/.standard.yml
DELETED