yard-markdown 0.7.3 → 0.8.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/yard/markdown/metadata_section_helper.rb +54 -0
- data/lib/yard/markdown/section_assembly_helper.rb +11 -0
- data/lib/yard-markdown.rb +1 -1
- data/templates/default/module/markdown/setup.rb +6 -6
- metadata +2 -2
- data/lib/yard/markdown/relationship_section_helper.rb +0 -38
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9d0f4cb4021498fef4a2ae549af15357c6d2fa65e2099677e75d1b25920e680
|
|
4
|
+
data.tar.gz: 465def23d344679e869e776d856ce5a694e483d46dc5ab37fcf43eebe67f11cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2c2c4b64ea40ec28ab122d2398f2cfc72823e35fbb6a50a16146b5cb5199c44df4431cd568c00917d1011812afdb6c2c4d5862eaa8a2e66a3288bb9a901b731
|
|
7
|
+
data.tar.gz: 63d188cab16ac36c3200205a01a0dd8f902061db68d2fdbc0ab81357de96cb478e44ae066e2ecd439978cba25c9ab60576aa385c0c496e32e9b3eec142de5e26
|
data/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module YARD
|
|
4
|
+
module Markdown
|
|
5
|
+
# Renders namespace metadata summaries.
|
|
6
|
+
module MetadataSectionHelper
|
|
7
|
+
# Returns inheritance, mixins, and source files for an object.
|
|
8
|
+
#
|
|
9
|
+
# @param object [YARD::CodeObjects::NamespaceObject] Object being rendered.
|
|
10
|
+
# @return [String] Markdown table containing the object's metadata.
|
|
11
|
+
def object_metadata(object)
|
|
12
|
+
rows = []
|
|
13
|
+
|
|
14
|
+
if object.instance_of?(CodeObjects::ClassObject)
|
|
15
|
+
rows << ["Inherits", metadata_reference(object.superclass)]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
[[:class, "Extended by"], [:instance, "Includes"]].each do |scope, label|
|
|
19
|
+
mixins = run_verifier(object.mixins(scope)).sort_by { |item| item.path }
|
|
20
|
+
next if mixins.empty?
|
|
21
|
+
|
|
22
|
+
rows << [label, mixins.map { |mixin| metadata_reference(mixin) }.join(", ")]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
files = object.files.map(&:first).uniq
|
|
26
|
+
rows << ["Defined in", files.map { |file| metadata_table_cell(file) }.join(", ")] unless files.empty?
|
|
27
|
+
|
|
28
|
+
return "" if rows.empty?
|
|
29
|
+
|
|
30
|
+
(["| | |", "| --- | --- |"] + rows.map { |label, value| "| **#{label}** | #{value} |" }).join("\n")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns a table-safe namespace reference, linked when YARD will render it.
|
|
34
|
+
#
|
|
35
|
+
# @param target [YARD::CodeObjects::NamespaceObject, YARD::CodeObjects::Proxy] Referenced namespace.
|
|
36
|
+
# @return [String] Markdown link or plain table-cell text.
|
|
37
|
+
def metadata_reference(target)
|
|
38
|
+
label = metadata_table_cell(target.path)
|
|
39
|
+
return label unless target.is_a?(CodeObjects::Base) && run_verifier([target]).any?
|
|
40
|
+
|
|
41
|
+
"[#{label}](#{target.path})"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Escapes text for a Markdown table cell.
|
|
45
|
+
#
|
|
46
|
+
# @param value [String] Metadata text.
|
|
47
|
+
# @return [String] GFM table-safe Markdown text.
|
|
48
|
+
def metadata_table_cell(value)
|
|
49
|
+
value.gsub(/[[:blank:]]*\R[[:blank:]]*/, " ")
|
|
50
|
+
.gsub(/[\\|]/) { |character| "\\#{character}" }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -4,6 +4,17 @@ module YARD
|
|
|
4
4
|
module Markdown
|
|
5
5
|
# Assembles grouped content into ordered Markdown sections.
|
|
6
6
|
module SectionAssemblyHelper
|
|
7
|
+
# Returns section content with the expected trailing spacing.
|
|
8
|
+
#
|
|
9
|
+
# @param content [Object] Section content to render.
|
|
10
|
+
# @return [String] Section content followed by blank-line spacing.
|
|
11
|
+
def render_section_content(content)
|
|
12
|
+
text = content.to_s.strip
|
|
13
|
+
return "" if text.empty?
|
|
14
|
+
|
|
15
|
+
"#{text}\n\n"
|
|
16
|
+
end
|
|
17
|
+
|
|
7
18
|
# Groups items by their YARD group and orders them for rendering.
|
|
8
19
|
#
|
|
9
20
|
# @param items [Array<#group>] Renderable objects that expose a YARD group name.
|
data/lib/yard-markdown.rb
CHANGED
|
@@ -6,9 +6,9 @@ require_relative "yard/markdown/collection_rendering_helper"
|
|
|
6
6
|
require_relative "yard/markdown/documentation_helper"
|
|
7
7
|
require_relative "yard/markdown/heading_helper"
|
|
8
8
|
require_relative "yard/markdown/link_normalization_helper"
|
|
9
|
+
require_relative "yard/markdown/metadata_section_helper"
|
|
9
10
|
require_relative "yard/markdown/method_presentation_helper"
|
|
10
11
|
require_relative "yard/markdown/object_listing_helper"
|
|
11
|
-
require_relative "yard/markdown/relationship_section_helper"
|
|
12
12
|
require_relative "yard/markdown/section_assembly_helper"
|
|
13
13
|
require_relative "yard/markdown/tag_formatting_helper"
|
|
14
14
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
include YARD::Markdown::TagFormattingHelper,
|
|
4
4
|
YARD::Markdown::SectionAssemblyHelper,
|
|
5
|
-
YARD::Markdown::
|
|
5
|
+
YARD::Markdown::MetadataSectionHelper,
|
|
6
6
|
YARD::Markdown::ObjectListingHelper,
|
|
7
7
|
YARD::Markdown::MethodPresentationHelper,
|
|
8
8
|
YARD::Markdown::LinkNormalizationHelper,
|
|
@@ -16,7 +16,7 @@ include YARD::Markdown::TagFormattingHelper,
|
|
|
16
16
|
# @return [void]
|
|
17
17
|
def init
|
|
18
18
|
sections :header,
|
|
19
|
-
:
|
|
19
|
+
:metadata,
|
|
20
20
|
:docstring_section,
|
|
21
21
|
:tags_section,
|
|
22
22
|
:constants_section,
|
|
@@ -48,11 +48,11 @@ def header
|
|
|
48
48
|
render_section_content(heading_with_anchors("# #{object.type.to_s.capitalize} #{object.path}", object))
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
# Renders
|
|
51
|
+
# Renders metadata for the current object.
|
|
52
52
|
#
|
|
53
|
-
# @return [String] Markdown
|
|
54
|
-
def
|
|
55
|
-
render_section_content(
|
|
53
|
+
# @return [String] Markdown metadata section.
|
|
54
|
+
def metadata
|
|
55
|
+
render_section_content(object_metadata(object))
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
# Renders the object's docstring as markdown.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yard-markdown
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stanislav (Stas) Katkov
|
|
@@ -67,9 +67,9 @@ files:
|
|
|
67
67
|
- lib/yard/markdown/documentation_helper.rb
|
|
68
68
|
- lib/yard/markdown/heading_helper.rb
|
|
69
69
|
- lib/yard/markdown/link_normalization_helper.rb
|
|
70
|
+
- lib/yard/markdown/metadata_section_helper.rb
|
|
70
71
|
- lib/yard/markdown/method_presentation_helper.rb
|
|
71
72
|
- lib/yard/markdown/object_listing_helper.rb
|
|
72
|
-
- lib/yard/markdown/relationship_section_helper.rb
|
|
73
73
|
- lib/yard/markdown/section_assembly_helper.rb
|
|
74
74
|
- lib/yard/markdown/tag_formatting_helper.rb
|
|
75
75
|
- templates/default/fulldoc/markdown/setup.rb
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YARD
|
|
4
|
-
module Markdown
|
|
5
|
-
# Renders inheritance and mixin relationship summaries.
|
|
6
|
-
module RelationshipSectionHelper
|
|
7
|
-
# Returns section content with the expected trailing spacing.
|
|
8
|
-
#
|
|
9
|
-
# @param content [Object] Section content to render.
|
|
10
|
-
# @return [String] Section content followed by blank-line spacing.
|
|
11
|
-
def render_section_content(content)
|
|
12
|
-
text = content.to_s.strip
|
|
13
|
-
return "" if text.empty?
|
|
14
|
-
|
|
15
|
-
"#{text}\n\n"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Returns inheritance and mixin relationships for an object.
|
|
19
|
-
#
|
|
20
|
-
# @param object [YARD::CodeObjects::NamespaceObject] Object being rendered.
|
|
21
|
-
# @return [String] Markdown summary of the object's relationships.
|
|
22
|
-
def object_relationships(object)
|
|
23
|
-
lines = []
|
|
24
|
-
|
|
25
|
-
lines << "**Inherits:** `#{object.superclass}`" if object.instance_of?(CodeObjects::ClassObject)
|
|
26
|
-
|
|
27
|
-
[[:class, "Extended by"], [:instance, "Includes"]].each do |scope, label|
|
|
28
|
-
mixins = run_verifier(object.mixins(scope)).sort_by { |item| item.path }
|
|
29
|
-
next if mixins.empty?
|
|
30
|
-
|
|
31
|
-
lines << "**#{label}:** #{mixins.map { |mixin| "`#{mixin.path}`" }.join(", ")}"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
lines.join("\n")
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|