rdoc-markdown 0.16.1 → 0.17.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 +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/rdoc/generator/markdown.rb +49 -141
- data/lib/rdoc/markdown/version.rb +1 -1
- data/lib/templates/classfile.md.erb +1 -1
- 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: 6c8f2f083fa79cfc383a5de5efe80ed2ce86ca5c8820218ae57f9de9427f8e6e
|
|
4
|
+
data.tar.gz: b9380e6323ce669abc903f3fb29f598cd346f017c565ef4c7f8d48146124184a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7245acbe5230c82d9209a9203d9c86dfcd18416b1a60b56c574b5c59bbf81a752c388771e81e7cb135d9197620f2bc7f497db3ad33a0d7151ae1032b1f0b8115
|
|
7
|
+
data.tar.gz: 547ef3178aceffcf1e44ace777f18e97ed4ffc370ab3e99526ebbcebc053eca307c0c57e9f5d739ebc3b8156912c1b9dc13fbb08289408130c1bc38c92d87855
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
## Unreleased
|
|
5
5
|
|
|
6
|
+
## 0.17.0
|
|
7
|
+
|
|
8
|
+
- Remove fabricated external namespaces and preserve exact class and module identities across generated paths, index entries, metadata, and links.
|
|
9
|
+
- Avoid broken alias links when the target method is hidden or its owner page is not generated.
|
|
10
|
+
- Preserve localized section bodies, Markdown format, and source location when translating comments.
|
|
11
|
+
- Avoid duplicate unresolved cross-reference warnings during class and module selection.
|
|
12
|
+
|
|
13
|
+
## 0.16.1
|
|
14
|
+
|
|
6
15
|
- Fix copying Markdown pages when RDoc receives relative input paths.
|
|
7
16
|
|
|
8
17
|
## 0.16.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -123,7 +123,7 @@ rake vendor:setup:rails
|
|
|
123
123
|
bundle exec rake test
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
The rails harness validates alias rendering, preserved code blocks, file/page links rewritten to markdown, and
|
|
126
|
+
The rails harness validates alias rendering, preserved code blocks, file/page links rewritten to markdown, and omission of fabricated external namespaces.
|
|
127
127
|
|
|
128
128
|
### Generate vendored docs
|
|
129
129
|
Use rake tasks to generate markdown output for vendored projects:
|
|
@@ -152,14 +152,14 @@ class RDoc::Generator::Markdown
|
|
|
152
152
|
|
|
153
153
|
@classes.each do |klass|
|
|
154
154
|
csv << [
|
|
155
|
-
|
|
155
|
+
klass.full_name,
|
|
156
156
|
klass.type.capitalize,
|
|
157
157
|
output_path_for(klass)
|
|
158
158
|
]
|
|
159
159
|
|
|
160
160
|
klass.method_list.select(&:display?).each do |method|
|
|
161
161
|
csv << [
|
|
162
|
-
"#{
|
|
162
|
+
"#{klass.full_name}.#{method.name}",
|
|
163
163
|
"Method",
|
|
164
164
|
"#{output_path_for(klass)}##{method.aref}"
|
|
165
165
|
]
|
|
@@ -171,7 +171,7 @@ class RDoc::Generator::Markdown
|
|
|
171
171
|
.sort
|
|
172
172
|
.each do |const|
|
|
173
173
|
csv << [
|
|
174
|
-
"#{
|
|
174
|
+
"#{klass.full_name}.#{const.name}",
|
|
175
175
|
"Constant",
|
|
176
176
|
"#{output_path_for(klass)}##{const.name}"
|
|
177
177
|
]
|
|
@@ -183,7 +183,7 @@ class RDoc::Generator::Markdown
|
|
|
183
183
|
.sort
|
|
184
184
|
.each do |attr|
|
|
185
185
|
csv << [
|
|
186
|
-
"#{
|
|
186
|
+
"#{klass.full_name}.#{attr.name}",
|
|
187
187
|
"Attribute",
|
|
188
188
|
"#{output_path_for(klass)}##{attr.aref}"
|
|
189
189
|
]
|
|
@@ -260,22 +260,13 @@ class RDoc::Generator::Markdown
|
|
|
260
260
|
"#{dirname}/#{basename}"
|
|
261
261
|
end
|
|
262
262
|
|
|
263
|
-
# Returns the normalized display name for a class or module.
|
|
264
|
-
#
|
|
265
|
-
# @param code_object [RDoc::Context] Class or module object.
|
|
266
|
-
#
|
|
267
|
-
# @return [String] Display name used in headings and the index.
|
|
268
|
-
def display_name(code_object)
|
|
269
|
-
class_doc_for(code_object).fetch(:display_name)
|
|
270
|
-
end
|
|
271
|
-
|
|
272
263
|
# Returns the canonical Markdown path for a class or module.
|
|
273
264
|
#
|
|
274
265
|
# @param code_object [RDoc::Context] Class or module object.
|
|
275
266
|
#
|
|
276
267
|
# @return [String] Relative Markdown path.
|
|
277
268
|
def output_path_for(code_object)
|
|
278
|
-
|
|
269
|
+
turn_to_path(code_object.full_name)
|
|
279
270
|
end
|
|
280
271
|
|
|
281
272
|
# Renders a class or module reference, linking it when its documentation is emitted.
|
|
@@ -285,11 +276,11 @@ class RDoc::Generator::Markdown
|
|
|
285
276
|
#
|
|
286
277
|
# @return [String] Markdown text or link.
|
|
287
278
|
def metadata_reference(target, label)
|
|
288
|
-
|
|
279
|
+
output_path = @class_output_paths[target.full_name] if target.respond_to?(:full_name)
|
|
289
280
|
cell = metadata_table_cell(label)
|
|
290
|
-
return cell unless
|
|
281
|
+
return cell unless output_path
|
|
291
282
|
|
|
292
|
-
"[#{cell}](#{
|
|
283
|
+
"[#{cell}](#{output_path})"
|
|
293
284
|
end
|
|
294
285
|
|
|
295
286
|
# Escapes text for a Markdown table cell.
|
|
@@ -390,16 +381,31 @@ class RDoc::Generator::Markdown
|
|
|
390
381
|
#
|
|
391
382
|
# @param code_object [RDoc::CodeObject, RDoc::Context::Section] Object whose description is rendered.
|
|
392
383
|
#
|
|
393
|
-
# @return [String
|
|
384
|
+
# @return [String] HTML description.
|
|
394
385
|
def render_description(code_object)
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
386
|
+
section = RDoc::Context::Section === code_object
|
|
387
|
+
formatter = if section
|
|
388
|
+
code_object.parent.formatter.dup.tap { |copy| copy.code_object = code_object }
|
|
389
|
+
else
|
|
390
|
+
code_object.formatter
|
|
391
|
+
end
|
|
398
392
|
formatter.extend(CrossrefExtension)
|
|
399
393
|
begin
|
|
400
394
|
formatter.markdown_cross_reference = RDoc::CrossReference.new(formatter.context)
|
|
401
395
|
formatter.markdown_output_object_ids = @markdown_output_object_ids
|
|
402
|
-
|
|
396
|
+
if section
|
|
397
|
+
locale = options.locale
|
|
398
|
+
documents = code_object.comments.map do |comment|
|
|
399
|
+
next comment.parse unless locale && !comment.text.empty?
|
|
400
|
+
|
|
401
|
+
comment = comment.dup
|
|
402
|
+
comment.text = RDoc::I18n::Text.new(comment).translate(locale)
|
|
403
|
+
comment.parse
|
|
404
|
+
end
|
|
405
|
+
RDoc::Markup::Document.new(*documents).accept(formatter)
|
|
406
|
+
else
|
|
407
|
+
code_object.description
|
|
408
|
+
end
|
|
403
409
|
ensure
|
|
404
410
|
formatter.markdown_cross_reference = nil
|
|
405
411
|
end
|
|
@@ -585,7 +591,10 @@ class RDoc::Generator::Markdown
|
|
|
585
591
|
aliased_method = method.is_alias_for
|
|
586
592
|
return "Not documented." unless aliased_method
|
|
587
593
|
|
|
588
|
-
|
|
594
|
+
link = method_link(aliased_method, current_class: current_class)
|
|
595
|
+
return "Alias for: `#{aliased_method.name}`" unless link
|
|
596
|
+
|
|
597
|
+
"Alias for: [`#{aliased_method.name}`](#{link})"
|
|
589
598
|
end
|
|
590
599
|
|
|
591
600
|
# Applies final whitespace and link normalization before writing Markdown.
|
|
@@ -662,12 +671,16 @@ class RDoc::Generator::Markdown
|
|
|
662
671
|
# @param method [RDoc::AnyMethod] Target method.
|
|
663
672
|
# @param current_class [RDoc::Context] Class or module currently being rendered.
|
|
664
673
|
#
|
|
665
|
-
# @return [String] Anchor or relative Markdown link target.
|
|
674
|
+
# @return [String, nil] Anchor or relative Markdown link target, or nil when the target page is omitted.
|
|
666
675
|
def method_link(method, current_class:)
|
|
676
|
+
return unless method.display?
|
|
677
|
+
|
|
667
678
|
target_parent = method.parent
|
|
679
|
+
target_path = @class_output_paths[target_parent.full_name]
|
|
680
|
+
return unless target_path
|
|
668
681
|
return "##{method.aref}" if target_parent == current_class
|
|
669
682
|
|
|
670
|
-
"#{
|
|
683
|
+
"#{target_path}##{method.aref}"
|
|
671
684
|
end
|
|
672
685
|
|
|
673
686
|
# Rewrites local Markdown links relative to the current output file.
|
|
@@ -728,117 +741,6 @@ class RDoc::Generator::Markdown
|
|
|
728
741
|
normalized.sub(%r{\A#{Regexp.escape(root_basename)}/}, "")
|
|
729
742
|
end
|
|
730
743
|
|
|
731
|
-
# Looks up resolved class documentation metadata.
|
|
732
|
-
#
|
|
733
|
-
# @param code_object [RDoc::Context] Class or module object.
|
|
734
|
-
#
|
|
735
|
-
# @return [Hash{Symbol => Object}] Metadata for rendering the object.
|
|
736
|
-
def class_doc_for(code_object)
|
|
737
|
-
@class_docs_by_object_id.fetch(code_object.object_id)
|
|
738
|
-
end
|
|
739
|
-
|
|
740
|
-
# Builds canonical class documentation metadata from RDoc objects.
|
|
741
|
-
#
|
|
742
|
-
# @param classes [Array<RDoc::Context>] Classes and modules to normalize.
|
|
743
|
-
#
|
|
744
|
-
# @return [Array<Hash{Symbol => Object}>] Metadata ordered by display name.
|
|
745
|
-
def build_class_docs(classes)
|
|
746
|
-
docs_by_name = {}
|
|
747
|
-
|
|
748
|
-
classes.select(&:display?).each do |klass|
|
|
749
|
-
display_name = normalized_full_name(klass.full_name)
|
|
750
|
-
output_path = turn_to_path(display_name)
|
|
751
|
-
score = class_content_score(klass)
|
|
752
|
-
|
|
753
|
-
candidate = {
|
|
754
|
-
klass: klass,
|
|
755
|
-
display_name: display_name,
|
|
756
|
-
output_path: output_path,
|
|
757
|
-
score: score
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
existing = docs_by_name[display_name]
|
|
761
|
-
|
|
762
|
-
if existing.nil?
|
|
763
|
-
docs_by_name[display_name] = candidate
|
|
764
|
-
elsif candidate.fetch(:score) > existing.fetch(:score)
|
|
765
|
-
docs_by_name[display_name] = candidate
|
|
766
|
-
end
|
|
767
|
-
end
|
|
768
|
-
|
|
769
|
-
docs_by_name.values
|
|
770
|
-
.select do |doc|
|
|
771
|
-
klass = doc.fetch(:klass)
|
|
772
|
-
|
|
773
|
-
doc.fetch(:score).positive? ||
|
|
774
|
-
(!class_has_raw_members?(klass) && !synthetic_full_name?(klass.full_name))
|
|
775
|
-
end
|
|
776
|
-
.sort_by { |doc| doc.fetch(:display_name) }
|
|
777
|
-
end
|
|
778
|
-
|
|
779
|
-
# Collapses repeated namespace segments from synthetic vendored names.
|
|
780
|
-
#
|
|
781
|
-
# @param full_name [String] Full RDoc object name.
|
|
782
|
-
#
|
|
783
|
-
# @return [String] Normalized object name.
|
|
784
|
-
def normalized_full_name(full_name)
|
|
785
|
-
normalized = full_name
|
|
786
|
-
|
|
787
|
-
loop do
|
|
788
|
-
if normalized =~ /\A([^:]+)(?:::[^:]+)+::\1::(.+)\z/
|
|
789
|
-
normalized = "#{Regexp.last_match(1)}::#{Regexp.last_match(2)}"
|
|
790
|
-
end
|
|
791
|
-
|
|
792
|
-
if normalized =~ /\A(.+?)::\1\z/
|
|
793
|
-
normalized = Regexp.last_match(1)
|
|
794
|
-
end
|
|
795
|
-
|
|
796
|
-
break
|
|
797
|
-
end
|
|
798
|
-
|
|
799
|
-
normalized
|
|
800
|
-
end
|
|
801
|
-
|
|
802
|
-
# Scores how much owned content a class or module has.
|
|
803
|
-
#
|
|
804
|
-
# @param klass [RDoc::Context] Class or module object.
|
|
805
|
-
#
|
|
806
|
-
# @return [Integer] Content score used to choose duplicate docs.
|
|
807
|
-
def class_content_score(klass)
|
|
808
|
-
score = class_member_count(klass)
|
|
809
|
-
score += 1 unless klass.description.empty?
|
|
810
|
-
score
|
|
811
|
-
end
|
|
812
|
-
|
|
813
|
-
# Counts methods, constants, and attributes owned by a class or module.
|
|
814
|
-
#
|
|
815
|
-
# @param klass [RDoc::Context] Class or module object.
|
|
816
|
-
#
|
|
817
|
-
# @return [Integer] Number of owned members.
|
|
818
|
-
def class_member_count(klass)
|
|
819
|
-
klass.method_list.count(&:display?) + klass.constants.count(&:display?) + klass.attributes.count(&:display?)
|
|
820
|
-
end
|
|
821
|
-
|
|
822
|
-
# Checks whether a class or module owns any members before display filtering.
|
|
823
|
-
#
|
|
824
|
-
# @param klass [RDoc::Context] Class or module object.
|
|
825
|
-
#
|
|
826
|
-
# @return [Boolean] True when any owned member exists before display filtering.
|
|
827
|
-
def class_has_raw_members?(klass)
|
|
828
|
-
klass.method_list.any? || klass.constants.any? || klass.attributes.any?
|
|
829
|
-
end
|
|
830
|
-
|
|
831
|
-
# Checks whether a name appears to contain duplicated root namespaces.
|
|
832
|
-
#
|
|
833
|
-
# @param full_name [String] Full RDoc object name.
|
|
834
|
-
#
|
|
835
|
-
# @return [Boolean] True when the root namespace appears more than once.
|
|
836
|
-
def synthetic_full_name?(full_name)
|
|
837
|
-
parts = full_name.split("::")
|
|
838
|
-
root = parts.first
|
|
839
|
-
parts.count(root) > 1
|
|
840
|
-
end
|
|
841
|
-
|
|
842
744
|
# Prepares sorted objects and link lookup state for generation.
|
|
843
745
|
#
|
|
844
746
|
# @return [void]
|
|
@@ -848,13 +750,19 @@ class RDoc::Generator::Markdown
|
|
|
848
750
|
raise TypeError, "RDoc markdown output directory must be a String"
|
|
849
751
|
end
|
|
850
752
|
|
|
851
|
-
@
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
753
|
+
@classes = @store.unique_classes_and_modules.select(&:display?).select do |klass|
|
|
754
|
+
klass.in_files.any? ||
|
|
755
|
+
klass.documented? ||
|
|
756
|
+
klass.includes.any? ||
|
|
757
|
+
klass.method_list.any?(&:display?) ||
|
|
758
|
+
klass.constants.any?(&:display?) ||
|
|
759
|
+
klass.attributes.any?(&:display?) ||
|
|
760
|
+
klass.sections.any? { |section| section.title.to_s.match?(/\S/) || !section.to_document.empty? }
|
|
761
|
+
end.sort
|
|
762
|
+
@class_output_paths = @classes.to_h { |klass| [klass.full_name, output_path_for(klass)] }
|
|
855
763
|
@pages = @store.all_files.select(&:text?).select(&:display?).sort_by(&:base_name)
|
|
856
764
|
@markdown_output_object_ids = (@classes + @pages).map(&:object_id)
|
|
857
|
-
@known_output_paths = @
|
|
765
|
+
@known_output_paths = @class_output_paths.values
|
|
858
766
|
@pages.each { |page| @known_output_paths << page_output_path(page) }
|
|
859
767
|
|
|
860
768
|
@root_path_segment = Pathname.new(@options.root || ".").basename
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# <%= klass.type.capitalize %> <%=
|
|
1
|
+
# <%= klass.type.capitalize %> <%= klass.full_name %><%= anchor(klass.aref.strip) %>
|
|
2
2
|
<%- superclass = klass.superclass if klass.type == "class" -%>
|
|
3
3
|
<%- includes = klass.includes -%>
|
|
4
4
|
<%- source_files = klass.in_files -%>
|