rdoc-markdown 0.12.0 → 0.13.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 +16 -0
- data/Gemfile.lock +1 -1
- data/lib/rdoc/generator/markdown.rb +53 -40
- data/lib/rdoc/markdown/version.rb +1 -1
- data/lib/templates/classfile.md.erb +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7fb0eeb24c5e69e9a8cc6b5f41f9e83cc8669da4f7f3282c08a8347021536135
|
|
4
|
+
data.tar.gz: f36ab292793914871d6bc119493c02bbbe94cb90944ececa98be56b4db7f0446
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5430c965fb823c2e5c384e67d9cc8d9cd91a08749b089ee486d5868bd97d6a4aa9cad417c4ff03028c69ae2ebb5ccc62e50698490d8d6be8c3bd57049ebcb40a
|
|
7
|
+
data.tar.gz: e016dfb4a279a0c8283d3455098a84c9f68d4817fbb23cafdf3c1ed2f00b1de9683a2b6a81a161a47321692c07684c5b97c8658ec21cbac0f0647d3a51132137
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.13.0
|
|
6
|
+
|
|
7
|
+
- Adding metadata to classes/modules
|
|
8
|
+
- Fixed: cross-linking between markdown files
|
|
9
|
+
|
|
10
|
+
## 0.12.1
|
|
11
|
+
|
|
12
|
+
- simplification: automatic root-page inclusion hook.
|
|
13
|
+
- Explicit RDoc file lists are authoritative again; unlisted README, CHANGELOG, and similar files are not silently added.
|
|
14
|
+
|
|
15
|
+
## 0.12.0
|
|
16
|
+
|
|
17
|
+
- Indexing: Classifies root-level README and GUIDE pages as Readme.
|
|
18
|
+
- Indexing: Classifies root-level CHANGELOG and HISTORY pages as Changelog.
|
|
19
|
+
- Recognizes .rdoc, .md, and .markdown, case-insensitively by basename.
|
|
20
|
+
|
|
5
21
|
## 0.11.1
|
|
6
22
|
|
|
7
23
|
- Changed headings from standalone anchors to adjacent inline anchors:
|
data/Gemfile.lock
CHANGED
|
@@ -26,7 +26,7 @@ class RDoc::Generator::Markdown
|
|
|
26
26
|
"history" => "Changelog"
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
# Source page extensions
|
|
29
|
+
# Source page extensions eligible for root page classification.
|
|
30
30
|
ROOT_PAGE_EXTENSIONS = %w[.rdoc .md .markdown]
|
|
31
31
|
|
|
32
32
|
# Returns the configured search-index type for an eligible root text page path.
|
|
@@ -75,30 +75,6 @@ class RDoc::Generator::Markdown
|
|
|
75
75
|
super
|
|
76
76
|
@markdown_unknown_tags = map.fetch("markdown_unknown_tags") if map.key?("markdown_unknown_tags")
|
|
77
77
|
end
|
|
78
|
-
|
|
79
|
-
# Adds markdown root entry pages to explicit source files.
|
|
80
|
-
#
|
|
81
|
-
# @return [void]
|
|
82
|
-
def check_files
|
|
83
|
-
return super unless @generator == RDoc::Generator::Markdown
|
|
84
|
-
super
|
|
85
|
-
return if @files.empty?
|
|
86
|
-
|
|
87
|
-
root = Pathname(@root)
|
|
88
|
-
expanded_root = root.expand_path
|
|
89
|
-
expanded_files = @files.map { |file| Pathname(file).expand_path.to_s }
|
|
90
|
-
@files.concat(
|
|
91
|
-
Dir.children(expanded_root).filter_map do |name|
|
|
92
|
-
path = expanded_root.join(name)
|
|
93
|
-
next unless path.file?
|
|
94
|
-
next unless File.readable?(path)
|
|
95
|
-
next unless RDoc::Generator::Markdown.root_page_type_for(name)
|
|
96
|
-
next if expanded_files.include?(path.to_s)
|
|
97
|
-
|
|
98
|
-
root.join(name).to_s
|
|
99
|
-
end
|
|
100
|
-
)
|
|
101
|
-
end
|
|
102
78
|
end
|
|
103
79
|
|
|
104
80
|
# Registers markdown generator-specific RDoc options.
|
|
@@ -276,16 +252,17 @@ class RDoc::Generator::Markdown
|
|
|
276
252
|
template = ERB.new(template_content, trim_mode: "-")
|
|
277
253
|
|
|
278
254
|
@classes.each do |klass|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
255
|
+
content = template.result(binding)
|
|
256
|
+
output_path = output_path_for(klass)
|
|
257
|
+
|
|
258
|
+
([output_path] | legacy_paths_for(klass)).each do |destination_path|
|
|
259
|
+
out_file = Pathname.new("#{output_dir}/#{destination_path}")
|
|
260
|
+
out_file.dirname.mkpath
|
|
261
|
+
File.write(out_file, finalize_markdown(
|
|
262
|
+
content,
|
|
263
|
+
canonical_output_path: output_path,
|
|
264
|
+
current_output_path: destination_path
|
|
265
|
+
))
|
|
289
266
|
end
|
|
290
267
|
end
|
|
291
268
|
end
|
|
@@ -299,7 +276,11 @@ class RDoc::Generator::Markdown
|
|
|
299
276
|
out_file.dirname.mkpath
|
|
300
277
|
|
|
301
278
|
content = markdownify(page.description)
|
|
302
|
-
File.write(out_file, finalize_markdown(
|
|
279
|
+
File.write(out_file, finalize_markdown(
|
|
280
|
+
content,
|
|
281
|
+
canonical_output_path: page_output_path(page),
|
|
282
|
+
current_output_path: page_output_path(page)
|
|
283
|
+
))
|
|
303
284
|
end
|
|
304
285
|
end
|
|
305
286
|
|
|
@@ -374,6 +355,30 @@ class RDoc::Generator::Markdown
|
|
|
374
355
|
class_doc_for(code_object).fetch(:legacy_paths)
|
|
375
356
|
end
|
|
376
357
|
|
|
358
|
+
# Renders a class or module reference, linking it when its documentation is emitted.
|
|
359
|
+
#
|
|
360
|
+
# @param target [RDoc::ClassModule, String] Resolved RDoc object or unresolved name.
|
|
361
|
+
# @param label [String] Visible reference text.
|
|
362
|
+
#
|
|
363
|
+
# @return [String] Markdown text or link.
|
|
364
|
+
def metadata_reference(target, label)
|
|
365
|
+
class_doc = @class_docs_by_name[normalized_full_name(target.full_name)] if target.respond_to?(:full_name)
|
|
366
|
+
cell = metadata_table_cell(label)
|
|
367
|
+
return cell unless class_doc
|
|
368
|
+
|
|
369
|
+
"[#{cell}](#{class_doc.fetch(:output_path)})"
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
# Escapes text for a Markdown table cell.
|
|
373
|
+
#
|
|
374
|
+
# @param value [String] Metadata text.
|
|
375
|
+
#
|
|
376
|
+
# @return [String] GFM table-safe Markdown text.
|
|
377
|
+
def metadata_table_cell(value)
|
|
378
|
+
value.gsub(/[[:blank:]]*\R[[:blank:]]*/, " ")
|
|
379
|
+
.gsub(/[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]/) { |character| "\\#{character}" }
|
|
380
|
+
end
|
|
381
|
+
|
|
377
382
|
# Converts RDoc HTML into GitHub-flavored Markdown.
|
|
378
383
|
#
|
|
379
384
|
# @param input [String] RDoc HTML fragment.
|
|
@@ -612,12 +617,17 @@ class RDoc::Generator::Markdown
|
|
|
612
617
|
# Applies final whitespace and link normalization before writing Markdown.
|
|
613
618
|
#
|
|
614
619
|
# @param content [String] Markdown content.
|
|
620
|
+
# @param canonical_output_path [String] Canonical output path used to resolve links.
|
|
615
621
|
# @param current_output_path [String] Output path for the file being written.
|
|
616
622
|
#
|
|
617
623
|
# @return [String] Final Markdown ending with one newline.
|
|
618
|
-
def finalize_markdown(content, current_output_path:)
|
|
624
|
+
def finalize_markdown(content, canonical_output_path:, current_output_path:)
|
|
619
625
|
output = content.lines.map(&:rstrip).join("\n")
|
|
620
|
-
output = normalize_internal_links(
|
|
626
|
+
output = normalize_internal_links(
|
|
627
|
+
output,
|
|
628
|
+
canonical_output_path: canonical_output_path,
|
|
629
|
+
current_output_path: current_output_path
|
|
630
|
+
)
|
|
621
631
|
output = output.sub(/\n{3,}/, "\n\n")
|
|
622
632
|
"#{output}\n"
|
|
623
633
|
end
|
|
@@ -694,10 +704,12 @@ class RDoc::Generator::Markdown
|
|
|
694
704
|
# Rewrites local Markdown links relative to the current output file.
|
|
695
705
|
#
|
|
696
706
|
# @param markdown [String] Markdown content.
|
|
707
|
+
# @param canonical_output_path [String] Canonical output path used to resolve links.
|
|
697
708
|
# @param current_output_path [String] Output path for the file being written.
|
|
698
709
|
#
|
|
699
710
|
# @return [String] Markdown with normalized internal links.
|
|
700
|
-
def normalize_internal_links(markdown, current_output_path:)
|
|
711
|
+
def normalize_internal_links(markdown, canonical_output_path:, current_output_path:)
|
|
712
|
+
canonical_dir = Pathname.new(canonical_output_path).dirname
|
|
701
713
|
current_dir = Pathname.new(current_output_path).dirname
|
|
702
714
|
|
|
703
715
|
markdown.gsub(%r{\]\(([^)]+)\)}) do
|
|
@@ -705,7 +717,7 @@ class RDoc::Generator::Markdown
|
|
|
705
717
|
path = target.sub(/[?#].*\z/, "")
|
|
706
718
|
suffix = target[path.length..]
|
|
707
719
|
|
|
708
|
-
resolved = resolve_output_path(path,
|
|
720
|
+
resolved = resolve_output_path(path, canonical_dir)
|
|
709
721
|
rewritten = resolved ? Pathname.new(resolved).relative_path_from(current_dir) : path
|
|
710
722
|
"](#{rewritten}#{suffix})"
|
|
711
723
|
end
|
|
@@ -877,6 +889,7 @@ class RDoc::Generator::Markdown
|
|
|
877
889
|
|
|
878
890
|
@class_docs = build_class_docs(@store.all_classes_and_modules.sort)
|
|
879
891
|
@class_docs_by_object_id = @class_docs.to_h { |doc| [doc.fetch(:klass).object_id, doc] }
|
|
892
|
+
@class_docs_by_name = @class_docs.to_h { |doc| [doc.fetch(:display_name), doc] }
|
|
880
893
|
@classes = @class_docs.map { |doc| doc.fetch(:klass) }
|
|
881
894
|
@pages = @store.all_files.select(&:text?).select(&:display?).sort_by(&:base_name)
|
|
882
895
|
@rbs_method_signatures = RbsSignatureIndex.build(Array(@options.files), @base_dir, @store)
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
# <%= klass.type.capitalize %> <%= display_name(klass) %><%= anchor(klass.aref.strip) %>
|
|
2
|
+
<%- superclass = klass.superclass if klass.type == "class" -%>
|
|
3
|
+
<%- includes = klass.includes -%>
|
|
4
|
+
<%- source_files = klass.in_files -%>
|
|
5
|
+
<%- if superclass || !includes.empty? || !source_files.empty? -%>
|
|
6
|
+
|
|
7
|
+
| | |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
<%- if superclass -%>
|
|
10
|
+
| **Inherits** | <%= metadata_reference(superclass, superclass.respond_to?(:full_name) ? superclass.full_name : superclass) %> |
|
|
11
|
+
<%- end -%>
|
|
12
|
+
<%- unless includes.empty? -%>
|
|
13
|
+
| **Includes** | <%= includes.map { |mixin| metadata_reference(mixin.module, mixin.name) }.join(", ") %> |
|
|
14
|
+
<%- end -%>
|
|
15
|
+
<%- unless source_files.empty? -%>
|
|
16
|
+
| **Defined in** | <%= source_files.map { |file| metadata_table_cell(file.relative_name) }.join(", ") %> |
|
|
17
|
+
<%- end -%>
|
|
18
|
+
<%- end -%>
|
|
19
|
+
|
|
2
20
|
<%- class_description = describe(klass) -%>
|
|
3
21
|
<%- unless class_description.empty? -%>
|
|
4
22
|
<%= class_description %>
|