yard-markdown 0.7.3 → 0.9.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 +8 -0
- data/README.md +18 -4
- data/lib/yard/markdown/link_normalization_helper.rb +6 -13
- data/lib/yard/markdown/metadata_section_helper.rb +54 -0
- data/lib/yard/markdown/section_assembly_helper.rb +11 -0
- data/lib/yard/markdown/yardoc_extension.rb +30 -0
- data/lib/yard/markdown.rb +8 -0
- data/lib/yard-markdown.rb +4 -6
- data/templates/default/fulldoc/markdown/setup.rb +12 -2
- data/templates/default/module/markdown/setup.rb +6 -6
- metadata +4 -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: 756196562ff8a2cafba54128de039d2f10fffd93816a9fc0abdad8130805e124
|
|
4
|
+
data.tar.gz: 3a6f3bdfd92a9a95e632dac284f33151e89c26a1be283deac463f600971774a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 04ea8878df7097ebf384ae8c45110c01036af65ce2004710c3f0c40fc20eb4cc8ccabec5f0dd4877c5abbf8c3305f7b42caa66581c4f884848b389d9106218d8
|
|
7
|
+
data.tar.gz: ef8e21cb4d98c319f37eab85291ecd69e808c3c074909adee7376d0fb7ab79e3d62436d86b082c69ef6777fa1eb7706ce9088cd39d648e8fe53fa00daa1ee7f7
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
## 0.9.0
|
|
9
|
+
|
|
10
|
+
- Detect Markdown files, copy them into generated documentation, and include them in `index.csv`.
|
|
11
|
+
|
|
12
|
+
## 0.8.0
|
|
13
|
+
|
|
14
|
+
- Adding metadata section
|
|
15
|
+
|
|
8
16
|
## 0.7.2
|
|
9
17
|
|
|
10
18
|
### Changed
|
data/README.md
CHANGED
|
@@ -19,6 +19,20 @@ gem install yard-markdown
|
|
|
19
19
|
|
|
20
20
|
Run `yardoc --format=markdown` to generate markdown documentation.
|
|
21
21
|
|
|
22
|
+
Markdown files in the project tree are detected automatically, copied unchanged into the output, and listed in `index.csv`:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
yardoc --format=markdown
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Markdown files whose basename starts with `_` are ignored automatically.
|
|
29
|
+
|
|
30
|
+
Use YARD's `--exclude` option to omit a separate documentation tree:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yardoc --format=markdown --exclude '\Adocs/'
|
|
34
|
+
```
|
|
35
|
+
|
|
22
36
|
## FAQ
|
|
23
37
|
|
|
24
38
|
### Note on RDoc support
|
|
@@ -66,14 +80,14 @@ Validate generated markdown in sample docs:
|
|
|
66
80
|
bundle exec rake markdown:validate_examples
|
|
67
81
|
```
|
|
68
82
|
|
|
69
|
-
There is also a real-world validation harness for repositories with substantial YARD documentation (`
|
|
83
|
+
There is also a real-world validation harness for repositories with substantial YARD documentation (`faraday`, `sidekiq`):
|
|
70
84
|
|
|
71
85
|
```bash
|
|
72
86
|
bundle exec rake markdown:validate_real_world
|
|
73
87
|
```
|
|
74
88
|
|
|
75
|
-
This task validates generated
|
|
89
|
+
This task validates every generated Markdown file against CommonMark and GFM. Generated files must have valid local links and anchors; unresolved links and anchors in byte-identical Markdown copied from upstream are reported instead of failing validation.
|
|
76
90
|
|
|
77
|
-
GitHub Actions CI
|
|
91
|
+
GitHub Actions CI runs this task on every push/PR, so both real-world fixture gems are verified continuously.
|
|
78
92
|
|
|
79
|
-
For reproducible checks, the task clones pinned tags (`
|
|
93
|
+
For reproducible checks, the task clones pinned tags (`faraday` `v2.14.3`, `sidekiq` `v7.3.10`) into `tmp/real-world/repos` and honors each repository's `.yardopts` before generating output in `tmp/real-world/faraday` and `tmp/real-world/sidekiq`.
|
|
@@ -13,7 +13,6 @@ module YARD
|
|
|
13
13
|
output = content.instance_of?(Array) ? content.join("\n") : content
|
|
14
14
|
output = output.lines.map(&:rstrip).join("\n")
|
|
15
15
|
output = normalize_local_links(output, current_path)
|
|
16
|
-
output = normalize_malformed_local_links(output)
|
|
17
16
|
output = output.gsub(/\n{3,}/, "\n\n").strip
|
|
18
17
|
"#{output}\n"
|
|
19
18
|
end
|
|
@@ -83,12 +82,16 @@ module YARD
|
|
|
83
82
|
return relative_output_path(current_dir, object_path)
|
|
84
83
|
end
|
|
85
84
|
|
|
85
|
+
alias_path = Pathname.new(normalized.sub(/\.html\z/i, "")).cleanpath.to_s
|
|
86
|
+
copied_path = options.copied_file_aliases[alias_path]
|
|
87
|
+
return relative_output_path(current_dir, copied_path) if copied_path
|
|
88
|
+
|
|
86
89
|
if normalized.match?(/\.html\z/i)
|
|
87
90
|
normalized = normalized.sub(/\.html\z/i, ".md")
|
|
88
91
|
elsif File.extname(normalized).empty?
|
|
89
92
|
return nil if unresolved_identifier_target?(normalized)
|
|
90
93
|
|
|
91
|
-
normalized = "#{normalized}.md"
|
|
94
|
+
normalized = "#{normalized}.md"
|
|
92
95
|
end
|
|
93
96
|
|
|
94
97
|
relative_output_path(current_dir, normalized)
|
|
@@ -111,9 +114,7 @@ module YARD
|
|
|
111
114
|
# @return [Boolean] True when the target should be treated as unresolved.
|
|
112
115
|
def unresolved_identifier_target?(path)
|
|
113
116
|
cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, "")
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
cleaned.match?(/\A[a-z_]\w*\z/)
|
|
117
|
+
File.extname(cleaned).empty? && !cleaned.include?("/")
|
|
117
118
|
end
|
|
118
119
|
|
|
119
120
|
# Computes a relative path from the current output directory.
|
|
@@ -129,14 +130,6 @@ module YARD
|
|
|
129
130
|
rescue
|
|
130
131
|
target
|
|
131
132
|
end
|
|
132
|
-
|
|
133
|
-
# Replaces malformed local Markdown links with inline code.
|
|
134
|
-
#
|
|
135
|
-
# @param markdown [String] Markdown content to normalize.
|
|
136
|
-
# @return [String] Markdown with malformed local links replaced.
|
|
137
|
-
def normalize_malformed_local_links(markdown)
|
|
138
|
-
markdown.gsub(%r{\[([^\]]+)\]\((?!https?://|mailto:|#)(?:[^)\n]*['"][^)\n]*)\)}, '`\1`')
|
|
139
|
-
end
|
|
140
133
|
end
|
|
141
134
|
end
|
|
142
135
|
end
|
|
@@ -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::NamespaceObject) && 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.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module YARD
|
|
4
|
+
module Markdown
|
|
5
|
+
# Discovers Markdown pages before YARD generates documentation.
|
|
6
|
+
module YardocExtension
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
# Adds Markdown pages to the files rendered by the Markdown template.
|
|
10
|
+
#
|
|
11
|
+
# @param checksums [Hash, nil] Previously generated file checksums.
|
|
12
|
+
# @return [void]
|
|
13
|
+
def run_generate(checksums)
|
|
14
|
+
if options.format == :markdown
|
|
15
|
+
existing = options.files.map { |file| File.expand_path(file.filename) }
|
|
16
|
+
exclusions = excluded.map { |path| Regexp.new(path, Regexp::IGNORECASE) }
|
|
17
|
+
output = File.expand_path(options.serializer.basepath)
|
|
18
|
+
markdown_files = Dir.glob("**/*").grep(FILE_PATTERN)
|
|
19
|
+
.reject { |file| File.basename(file).start_with?("_") }
|
|
20
|
+
.reject { |file| exclusions.any? { |pattern| pattern.match?(file) } }
|
|
21
|
+
.reject { |file| File.expand_path(file).start_with?("#{output}/") }
|
|
22
|
+
.reject { |file| existing.include?(File.expand_path(file)) }
|
|
23
|
+
add_extra_files(markdown_files)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/yard-markdown.rb
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "yard"
|
|
4
|
+
require_relative "yard/markdown"
|
|
4
5
|
require_relative "yard/markdown/aref_helper"
|
|
5
6
|
require_relative "yard/markdown/collection_rendering_helper"
|
|
6
7
|
require_relative "yard/markdown/documentation_helper"
|
|
7
8
|
require_relative "yard/markdown/heading_helper"
|
|
8
9
|
require_relative "yard/markdown/link_normalization_helper"
|
|
10
|
+
require_relative "yard/markdown/metadata_section_helper"
|
|
9
11
|
require_relative "yard/markdown/method_presentation_helper"
|
|
10
12
|
require_relative "yard/markdown/object_listing_helper"
|
|
11
|
-
require_relative "yard/markdown/relationship_section_helper"
|
|
12
13
|
require_relative "yard/markdown/section_assembly_helper"
|
|
13
14
|
require_relative "yard/markdown/tag_formatting_helper"
|
|
14
|
-
|
|
15
|
-
module YARD
|
|
16
|
-
module Markdown
|
|
17
|
-
end
|
|
18
|
-
end
|
|
15
|
+
require_relative "yard/markdown/yardoc_extension"
|
|
19
16
|
|
|
20
17
|
YARD::Templates::Engine.register_template_path File.dirname(__FILE__) + "/../templates"
|
|
18
|
+
YARD::CLI::Yardoc.prepend(YARD::Markdown::YardocExtension)
|
|
@@ -11,12 +11,19 @@ include YARD::Markdown::ObjectListingHelper,
|
|
|
11
11
|
# @return [void]
|
|
12
12
|
def init
|
|
13
13
|
options.objects = objects = run_verifier(options.objects).reject { |item| item.name == :root }
|
|
14
|
+
files = Array(options.files).select { |file| file.filename.match?(YARD::Markdown::FILE_PATTERN) }
|
|
15
|
+
options.copied_file_aliases = files.to_h do |file|
|
|
16
|
+
path = Pathname.new(file.filename).cleanpath.to_s
|
|
17
|
+
[path.sub(YARD::Markdown::FILE_PATTERN, ""), path]
|
|
18
|
+
end
|
|
14
19
|
|
|
15
20
|
options.delete(:objects)
|
|
16
21
|
options.delete(:files)
|
|
17
22
|
|
|
18
23
|
options.serializer.extension = "md"
|
|
19
24
|
|
|
25
|
+
files.each { |file| options.serializer.serialize(file.filename, File.binread(file.filename)) }
|
|
26
|
+
|
|
20
27
|
objects.each do |object|
|
|
21
28
|
Templates::Engine.with_serializer(object, options.serializer) { serialize(object) }
|
|
22
29
|
rescue => e
|
|
@@ -25,7 +32,7 @@ def init
|
|
|
25
32
|
log.backtrace(e)
|
|
26
33
|
end
|
|
27
34
|
|
|
28
|
-
serialize_index(objects)
|
|
35
|
+
serialize_index(objects, files)
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
# Renders the markdown template for a single namespace object.
|
|
@@ -39,13 +46,16 @@ end
|
|
|
39
46
|
# Writes the CSV search index for all rendered objects.
|
|
40
47
|
#
|
|
41
48
|
# @param objects [Array<YARD::CodeObjects::NamespaceObject>] Verified objects included in the generated documentation.
|
|
49
|
+
# @param files [Array<YARD::CodeObjects::ExtraFileObject>] Markdown files included in the generated documentation.
|
|
42
50
|
# @return [void]
|
|
43
|
-
def serialize_index(objects)
|
|
51
|
+
def serialize_index(objects, files)
|
|
44
52
|
filepath = "#{options.serializer.basepath}/index.csv"
|
|
45
53
|
|
|
46
54
|
CSV.open(filepath, "wb") do |csv|
|
|
47
55
|
csv << %w[name type path]
|
|
48
56
|
|
|
57
|
+
files.each { |file| csv << [file.title, "File", file.filename] }
|
|
58
|
+
|
|
49
59
|
objects.each do |object|
|
|
50
60
|
next if object.name == :root
|
|
51
61
|
|
|
@@ -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.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stanislav (Stas) Katkov
|
|
@@ -62,16 +62,18 @@ files:
|
|
|
62
62
|
- LICENSE.txt
|
|
63
63
|
- README.md
|
|
64
64
|
- lib/yard-markdown.rb
|
|
65
|
+
- lib/yard/markdown.rb
|
|
65
66
|
- lib/yard/markdown/aref_helper.rb
|
|
66
67
|
- lib/yard/markdown/collection_rendering_helper.rb
|
|
67
68
|
- lib/yard/markdown/documentation_helper.rb
|
|
68
69
|
- lib/yard/markdown/heading_helper.rb
|
|
69
70
|
- lib/yard/markdown/link_normalization_helper.rb
|
|
71
|
+
- lib/yard/markdown/metadata_section_helper.rb
|
|
70
72
|
- lib/yard/markdown/method_presentation_helper.rb
|
|
71
73
|
- lib/yard/markdown/object_listing_helper.rb
|
|
72
|
-
- lib/yard/markdown/relationship_section_helper.rb
|
|
73
74
|
- lib/yard/markdown/section_assembly_helper.rb
|
|
74
75
|
- lib/yard/markdown/tag_formatting_helper.rb
|
|
76
|
+
- lib/yard/markdown/yardoc_extension.rb
|
|
75
77
|
- templates/default/fulldoc/markdown/setup.rb
|
|
76
78
|
- templates/default/module/markdown/setup.rb
|
|
77
79
|
homepage: https://poshtui.com
|
|
@@ -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
|