yard-markdown 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6ff780c12b0efc36b1ba7c766ac4a8645d5fa9c5776e6ac1351a064b797e4fd1
4
+ data.tar.gz: fb42ed6ee07c97cd22af57267b0aed1570b7fb9fe89a4840a643fe4858d4a2a5
5
+ SHA512:
6
+ metadata.gz: d0ff4417bb45236c042daece82cf8442840d0f9c573a6be70e513c5c603ca813dc07ce8d30a5ddad0707463d95e9ac8a548f3f476bde5b777aaf4a27d16e91dd
7
+ data.tar.gz: 9687a9283bd08e6b5be2d00f0da4f2c41b997a71ef2875c0090aa15ccc78f0ea77d1710b9aba5b63775f2c34efe58dacc668adf9ded49453cbc9a1e575eb04ed
data/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # top-most EditorConfig file
2
+ root = true
3
+
4
+ # Unix-style newlines with a newline ending every file
5
+ # Two spaces for indenting
6
+ [*]
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ indent_style = space
10
+ indent_size = 2
11
+ charset = utf-8
12
+ trim_trailing_whitespace = true
13
+ max_line_length = 120
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/.yardopts ADDED
@@ -0,0 +1,8 @@
1
+ --load ./lib/yard/markdown.rb
2
+ --format markdown
3
+ --markup markdown
4
+ --output-dir example
5
+ --private
6
+ --protected
7
+ -
8
+ example.rb
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Stanislav Katkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Yard::Markdown
2
+
3
+ Yard-markdown produces markdown documents for ruby gems.
4
+
5
+ Goals:
6
+ - Compatible with Github Flavored Markdown
7
+ - Mimick yard html layout in markdown format as much as possible
8
+ - Produce .csv index file alonside markdown documentation
9
+
10
+ This is a successor to rdoc-mardown gem, so it will very likely be similar to this [example](https://github.com/skatkov/rdoc-markdown/tree/main/example).
11
+
12
+
13
+ Testing:
14
+ `yardoc example.rb` -> outputs everything into doc.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
data/example/Bird.md ADDED
@@ -0,0 +1,36 @@
1
+ # Class: Bird
2
+ | | |
3
+ | -----------------: | :----- |
4
+ | **Inherits:** | Object |
5
+ | **Defined in:** | example.rb |
6
+
7
+
8
+ The base class for all birds.
9
+
10
+ # Constants
11
+ ## DEFAULT_DUCK_VELOCITY =
12
+ (70) Default velocity for a flying duck.
13
+
14
+
15
+ # Public Instance Methods
16
+ ## _fly_impl(_direction , _velocity ) [](#method-i-_fly_impl)
17
+ :nodoc:
18
+ ## fly(direction , velocity ) [](#method-i-fly)
19
+ Fly somewhere.
20
+
21
+ Flying is the most critical feature of birds.
22
+
23
+ :args: direction, velocity
24
+
25
+ :call-seq:
26
+ Bird.fly(symbol, number) -> bool
27
+ Bird.fly(string, number) -> bool
28
+
29
+ = Example
30
+
31
+ fly(:south, 70)
32
+ ## speak() [](#method-i-speak)
33
+ Produce some noise.
34
+ --
35
+ FIXME: maybe extract this to a base class +Animal+?
36
+ ++
data/example/Duck.md ADDED
@@ -0,0 +1,48 @@
1
+ # Class: Duck
2
+ | | |
3
+ | -----------------: | :----- |
4
+ | **Inherits:** | Object |
5
+ | **Extended by:** | Animal |
6
+ | **Includes:** | Waterfowl |
7
+ | **Defined in:** | example.rb |
8
+ || |
9
+
10
+ A duck is a Waterfowl Bird.
11
+
12
+ Features:
13
+
14
+ bird::
15
+
16
+ * speak
17
+ * fly
18
+
19
+ waterfowl::
20
+
21
+ * swim
22
+
23
+ # Constants
24
+ ## DEFAULT_DUCK_VELOCITY =
25
+ (70) Default velocity for a flying duck.
26
+
27
+
28
+ # Public Instance Methods
29
+ ## initialize(domestic , rubber ) [](#method-i-initialize)
30
+ Creates a new duck.
31
+ ## speak() [](#method-i-speak)
32
+ Duck overrides generic implementation.
33
+ ## swim() [](#method-i-swim)
34
+ Swimming helper.
35
+ ## useful?() [](#method-i-useful?)
36
+ Checks if this duck is a useful one.
37
+
38
+ :call-seq:
39
+ Bird.useful? -> bool
40
+
41
+ # Public Class Methods
42
+ ## rubber_ducks() [](#method-c-rubber_ducks)
43
+
44
+ # Attributes
45
+ ## domestic[RW] [](#attribute-i-domestic)
46
+ True for domestic ducks.
47
+ ## rubber[RW] [](#attribute-i-rubber)
48
+ True for rubber ducks.
@@ -0,0 +1,17 @@
1
+ # Module: Waterfowl
2
+ | | |
3
+ | -----------------: | :----- |
4
+ | **Defined in:** | example.rb |
5
+
6
+
7
+ A mixin for waterfowl creatures.
8
+
9
+ # Constants
10
+ ## DEFAULT_DUCK_VELOCITY =
11
+ (70) Default velocity for a flying duck.
12
+
13
+
14
+ # Public Instance Methods
15
+ ## swim() [](#method-i-swim)
16
+ Swimming helper.
17
+
data/example.rb ADDED
@@ -0,0 +1,145 @@
1
+ ##
2
+ # === RDoc::Generator::Markdown example.
3
+ #
4
+ # This example employs various RDoc features to demonstrate
5
+ # generator output.
6
+ #
7
+ # ---
8
+ #
9
+ # Links:
10
+ #
11
+ # 1. {Project Home Page}[https://github.com/skatkov/rdoc-markdown)
12
+ # 2. {RDoc Documentation}[http://ruby-doc.org/stdlib-2.0.0/libdoc/rdoc/rdoc/RDoc/Markup.html]
13
+ #
14
+
15
+ ##
16
+ # A mixin for waterfowl creatures.
17
+ module Waterfowl
18
+ # Swimming helper.
19
+ def swim
20
+ puts "swimming around"
21
+ end
22
+ end
23
+
24
+ ##
25
+ # The base class for all birds.
26
+ class Bird
27
+ ##
28
+ # Produce some noise.
29
+ #--
30
+ # FIXME: maybe extract this to a base class +Animal+?
31
+ #++
32
+ def speak # :yields: text
33
+ puts "generic tweeting"
34
+ yield "tweet"
35
+ yield "tweet"
36
+ end
37
+
38
+ # Fly somewhere.
39
+ #
40
+ # Flying is the most critical feature of birds.
41
+ #
42
+ # :args: direction, velocity
43
+ #
44
+ # :call-seq:
45
+ # Bird.fly(symbol, number) -> bool
46
+ # Bird.fly(string, number) -> bool
47
+ #
48
+ # = Example
49
+ #
50
+ # fly(:south, 70)
51
+ def fly(direction, velocity)
52
+ _fly_impl(direction, velocity)
53
+ end
54
+
55
+ def _fly_impl(_direction, _velocity) # :nodoc:
56
+ puts "flying away: direction=#{direction}, velocity=#{velocity}"
57
+ end
58
+ end
59
+
60
+ ##
61
+ # A duck is a Waterfowl Bird.
62
+ #
63
+ # Features:
64
+ #
65
+ # bird::
66
+ #
67
+ # * speak
68
+ # * fly
69
+ #
70
+ # waterfowl::
71
+ #
72
+ # * swim
73
+ class Duck
74
+ extend Animal
75
+ include Waterfowl
76
+
77
+ # :section: Bird overrides
78
+
79
+ # Duck overrides generic implementation.
80
+ def speak
81
+ speech = quack
82
+ yield speech
83
+ end
84
+
85
+ # Implements quacking
86
+ def quack
87
+ "quack"
88
+ end
89
+
90
+ private :quack
91
+
92
+ # :section: Duck extensions
93
+
94
+ # True for domestic ducks.
95
+ attr_accessor :domestic
96
+
97
+ # True for rubber ducks.
98
+ attr_reader :rubber
99
+
100
+ MAX_VELOCITY = 130 # Maximum velocity for a flying duck.
101
+
102
+ ##
103
+ # Global list of all rubber ducks.
104
+ #
105
+ # Use when in trouble.
106
+ @@rubber_ducks = []
107
+
108
+ # @return [Array<Duck>] list of all rubber ducks
109
+ def self.rubber_ducks
110
+ @@rubber_ducks
111
+ end
112
+
113
+ # Creates a new duck.
114
+ #
115
+ # @param [Boolean] domestic
116
+ # @param [Boolean] rubber
117
+ def initialize(domestic, rubber)
118
+ @domestic = domestic
119
+ @rubber = rubber
120
+ @@rubber_ducks << self if rubber
121
+ end
122
+
123
+ # Checks if this duck is a useful one.
124
+ #
125
+ # :call-seq:
126
+ # Bird.useful? -> bool
127
+ def useful?
128
+ @domestic || @rubber
129
+ end
130
+ end
131
+
132
+ # Default velocity for a flying duck.
133
+ DEFAULT_DUCK_VELOCITY = 70
134
+
135
+ # Default rubber duck.
136
+ #
137
+ # *Note:*
138
+ # Global variables are evil, but rubber ducks are worth it.
139
+ $default_rubber_duck = Duck.new(false, true)
140
+
141
+ # Domestic rubber duck.
142
+ #
143
+ # *Note:*
144
+ # This is weird... Thus not making it global.
145
+ domestic_rubber_duck = Duck.new(true, true) # rubocop:disable Lint/UselessAssignment
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module Markdown
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yard"
4
+ require_relative "markdown/version"
5
+ require_relative "serializers/markdown_serializer"
6
+
7
+ module YARD
8
+ module Markdown
9
+ YARD::Templates::Engine.register_template_path "/../../templates"
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module Serializers
5
+ class MarkdownSerializer < YARD::Serializers::FileSystemSerializer
6
+ def initialize(opts = {})
7
+ super(opts.merge(extension: "md"))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Yard
2
+ module Markdown
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ # Test
2
+ <%= @object.docstring %>
@@ -0,0 +1,186 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://github.com/lsegal/yard/blob/2d197a381c5d4cc5c55b2c60fff992b31c986361/docs/CodeObjects.md
4
+
5
+ require_relative "../../../../lib/yard/serializers/markdown_serializer"
6
+ require "erb"
7
+
8
+ def init
9
+ # here I need to copy README.md if there is one.
10
+ # I also need to write index.md files
11
+
12
+ options.objects = objects = run_verifier(options.objects)
13
+
14
+ options.delete(:objects)
15
+ options.delete(:files)
16
+
17
+ options.serializer.extension = "md"
18
+
19
+ generate_method_list
20
+
21
+ objects.each do |object|
22
+ next if object.name == :root
23
+
24
+ begin
25
+ Templates::Engine.with_serializer(object, options.serializer) do
26
+ serialize(object)
27
+ end
28
+ rescue => e
29
+ path = options.serializer.serialized_path(object)
30
+ log.error "Exception occurred while generating '#{path}'"
31
+ log.backtrace(e)
32
+ end
33
+ end
34
+ end
35
+
36
+ def serialize(object)
37
+ template = ERB.new('# <%= format_object_title object %>
38
+ | | |
39
+ | -----------------: | :----- |
40
+ <% if CodeObjects::ClassObject === object && object.superclass %>
41
+ | **Inherits:** | <%= object.superclass %> |
42
+ <% end %>
43
+ <% [[:class, "Extended by"], [:instance, "Includes"]].each do |scope, name| %>
44
+ <% if (mix = run_verifier(object.mixins(scope))).size > 0 %>
45
+ | **<%= name %>:** | <%= mix.sort_by {|o| o.path }.join(", ") %> |
46
+ <% end %>
47
+ <% end %>
48
+ <% unless object.root? %>
49
+ | **Defined in:** | <%= object.file ? object.file : "(unknown)" %> |
50
+ <% end %>
51
+
52
+
53
+ <%= object.docstring %>
54
+
55
+
56
+ <% if constant_listing.size > 0 %>
57
+ <% groups(constant_listing, "Constants") do |list, name| %>
58
+ # <%= name %>
59
+ <% list.each do |cnst| %>
60
+ ## <%= cnst.name %> =
61
+ (<%= cnst.value %>) <%= cnst.docstring %>
62
+ <% end %>
63
+ <% end %>
64
+
65
+ <% end %>
66
+
67
+ <% if (insmeths = public_instance_methods(object)).size > 0 %>
68
+ # Public Instance Methods
69
+ <% insmeths.each do |item| %>
70
+ ## <%= item.name(false) %>(<%= item.parameters.map {|p| p.join(" ") }.join(", ")%>) [](#<%=aref(item)%>)
71
+ <%= item.docstring %>
72
+
73
+ <% end %>
74
+ <% end %>
75
+
76
+ <% if (pubmeths = public_class_methods(object)).size > 0 %>
77
+ # Public Class Methods
78
+ <% pubmeths.each do |item| %>
79
+ ## <%= item.name(false) %>(<%= item.parameters.map {|p| p.join(" ") }.join(", ") %>) [](#<%=aref(item)%>)
80
+ <%= item.docstring %>
81
+
82
+ <% end %>
83
+ <% end %>
84
+ <% if (attrs = attr_listing(object)).size > 0 %>
85
+ # Attributes
86
+ <% attrs.each do |item|%>
87
+ ## <%= item.name %><%= item.reader? ? "[RW]" : "[R]" %> [](#<%=aref(item)%>)
88
+ <%= item.docstring %>
89
+
90
+ <% end %>
91
+ <% end %>
92
+ '.gsub(/^ /, ""), trim_mode: "%<>")
93
+
94
+ template.result(binding)
95
+ end
96
+
97
+ def aref(object)
98
+ if !object.attr_info.nil?
99
+ "attribute-#{object.scope[0]}-#{object.name(false)}"
100
+ else
101
+ "#{object.type}-#{object.scope[0]}-#{object.name(false)}"
102
+ end
103
+ end
104
+
105
+ def constant_listing
106
+ return @constants if defined?(@constants) && @constants
107
+ @constants = object.constants(included: false, inherited: false)
108
+ @constants += object.cvars
109
+ @constants
110
+ end
111
+
112
+ include Helpers::ModuleHelper
113
+
114
+ def public_method_list(object)
115
+ prune_method_listing(object.meths(inherited: false, visibility: [:public]), included: false).sort_by { |m| m.name.to_s }
116
+ end
117
+
118
+ def public_class_methods(object)
119
+ public_method_list(object).select { |o| o.scope == :class }
120
+ end
121
+
122
+ def public_instance_methods(object)
123
+ public_method_list(object).select { |o| o.scope == :instance }
124
+ end
125
+
126
+ def attr_listing(object)
127
+ @attrs = []
128
+ object.inheritance_tree(true).each do |superclass|
129
+ next if superclass.is_a?(CodeObjects::Proxy)
130
+ next if !options.embed_mixins.empty? &&
131
+ !options.embed_mixins_match?(superclass)
132
+ [:class, :instance].each do |scope|
133
+ superclass.attributes[scope].each do |_name, rw|
134
+ attr = prune_method_listing([rw[:read], rw[:write]].compact, false).first
135
+ @attrs << attr if attr
136
+ end
137
+ end
138
+ break if options.embed_mixins.empty?
139
+ end
140
+ sort_listing @attrs
141
+ end
142
+
143
+ def generate_method_list
144
+ @items = prune_method_listing(Registry.all(:method), false)
145
+ @items = @items.reject { |m| m.name.to_s =~ /=$/ && m.is_attribute? }
146
+ @items = @items.sort_by { |m| m.name.to_s }
147
+
148
+ # @list_title = "Method List"
149
+ # @list_type = "method"
150
+ # generate_list_contents
151
+ # binding.irb
152
+ end
153
+
154
+ def sort_listing(list)
155
+ list.sort_by {|o| [o.scope.to_s, o.name.to_s.downcase] }
156
+ end
157
+
158
+ def groups(list, type = "Method")
159
+ groups_data = object.groups
160
+ if groups_data
161
+ list.each { |m| groups_data |= [m.group] if m.group && owner != m.namespace }
162
+ others = list.select { |m| !m.group || !groups_data.include?(m.group) }
163
+ groups_data.each do |name|
164
+ items = list.select { |m| m.group == name }
165
+ yield(items, name) unless items.empty?
166
+ end
167
+ else
168
+ others = []
169
+ group_data = {}
170
+ list.each do |itm|
171
+ if itm.group
172
+ (group_data[itm.group] ||= []) << itm
173
+ else
174
+ others << itm
175
+ end
176
+ end
177
+ group_data.each { |group, items| yield(items, group) unless items.empty? }
178
+ end
179
+
180
+ return if others.empty?
181
+ if others.first.respond_to?(:scope)
182
+ scopes(others) { |items, scope| yield(items, "#{scope.to_s.capitalize} #{type}") }
183
+ else
184
+ yield(others, type)
185
+ end
186
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stanislav (Stas) Katkov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: yard-markdown is a yard plugin template to generate markdown files
14
+ email:
15
+ - yard-markdown@skatkov.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".editorconfig"
21
+ - ".standard.yml"
22
+ - ".yardopts"
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - example.rb
27
+ - example/Bird.md
28
+ - example/Duck.md
29
+ - example/Waterfowl.md
30
+ - lib/yard/markdown.rb
31
+ - lib/yard/markdown/version.rb
32
+ - lib/yard/serializers/markdown_serializer.rb
33
+ - sig/yard/markdown.rbs
34
+ - templates/default/fulldoc/markdown/content.erb
35
+ - templates/default/fulldoc/markdown/setup.rb
36
+ homepage: https://poshtui.com
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://poshtui.com
41
+ source_code_uri: https://github.com/skatkov/yard-markdown
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.6.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.4.20
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: yard-markdown is a yard plugin template to generate markdown files
61
+ test_files: []