rdoc-markdown 0.12.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c69484c517e3582906e6847cbb162a7847ad29446856197a5f65972071c21d24
4
- data.tar.gz: f646046107985a70925df0794921c5451c514be069827762a296b9763a27bd81
3
+ metadata.gz: 7fb0eeb24c5e69e9a8cc6b5f41f9e83cc8669da4f7f3282c08a8347021536135
4
+ data.tar.gz: f36ab292793914871d6bc119493c02bbbe94cb90944ececa98be56b4db7f0446
5
5
  SHA512:
6
- metadata.gz: 79dce45ea46f3c5baa04488ea729e280196cb1b73cf48d1857c8227d67cf9d8ec2eb2d5d3dd69ced241d06c0b91ba91d817fcf4cbd0d7d6de22f05e709f3e0a0
7
- data.tar.gz: 44cd9cf4996a79fee5c56b19fa3779aed7e19a165a0576f350399560259b89f82e615c0911f7a1ce00087b860f1494499c7c00230dc486da11724502bc9a58fb
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rdoc-markdown (0.12.1)
4
+ rdoc-markdown (0.13.0)
5
5
  csv
6
6
  erb
7
7
  rdoc
@@ -75,7 +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
78
  end
80
79
 
81
80
  # Registers markdown generator-specific RDoc options.
@@ -253,16 +252,17 @@ class RDoc::Generator::Markdown
253
252
  template = ERB.new(template_content, trim_mode: "-")
254
253
 
255
254
  @classes.each do |klass|
256
- result = finalize_markdown(template.result(binding), current_output_path: output_path_for(klass))
257
-
258
- out_file = Pathname.new("#{output_dir}/#{output_path_for(klass)}")
259
- out_file.dirname.mkpath
260
- File.write(out_file, result)
261
-
262
- legacy_paths_for(klass).each do |legacy_path|
263
- legacy_file = Pathname.new("#{output_dir}/#{legacy_path}")
264
- legacy_file.dirname.mkpath
265
- File.write(legacy_file, result)
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
+ ))
266
266
  end
267
267
  end
268
268
  end
@@ -276,7 +276,11 @@ class RDoc::Generator::Markdown
276
276
  out_file.dirname.mkpath
277
277
 
278
278
  content = markdownify(page.description)
279
- File.write(out_file, finalize_markdown(content, current_output_path: page_output_path(page)))
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
+ ))
280
284
  end
281
285
  end
282
286
 
@@ -351,6 +355,30 @@ class RDoc::Generator::Markdown
351
355
  class_doc_for(code_object).fetch(:legacy_paths)
352
356
  end
353
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
+
354
382
  # Converts RDoc HTML into GitHub-flavored Markdown.
355
383
  #
356
384
  # @param input [String] RDoc HTML fragment.
@@ -589,12 +617,17 @@ class RDoc::Generator::Markdown
589
617
  # Applies final whitespace and link normalization before writing Markdown.
590
618
  #
591
619
  # @param content [String] Markdown content.
620
+ # @param canonical_output_path [String] Canonical output path used to resolve links.
592
621
  # @param current_output_path [String] Output path for the file being written.
593
622
  #
594
623
  # @return [String] Final Markdown ending with one newline.
595
- def finalize_markdown(content, current_output_path:)
624
+ def finalize_markdown(content, canonical_output_path:, current_output_path:)
596
625
  output = content.lines.map(&:rstrip).join("\n")
597
- output = normalize_internal_links(output, current_output_path: current_output_path)
626
+ output = normalize_internal_links(
627
+ output,
628
+ canonical_output_path: canonical_output_path,
629
+ current_output_path: current_output_path
630
+ )
598
631
  output = output.sub(/\n{3,}/, "\n\n")
599
632
  "#{output}\n"
600
633
  end
@@ -671,10 +704,12 @@ class RDoc::Generator::Markdown
671
704
  # Rewrites local Markdown links relative to the current output file.
672
705
  #
673
706
  # @param markdown [String] Markdown content.
707
+ # @param canonical_output_path [String] Canonical output path used to resolve links.
674
708
  # @param current_output_path [String] Output path for the file being written.
675
709
  #
676
710
  # @return [String] Markdown with normalized internal links.
677
- 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
678
713
  current_dir = Pathname.new(current_output_path).dirname
679
714
 
680
715
  markdown.gsub(%r{\]\(([^)]+)\)}) do
@@ -682,7 +717,7 @@ class RDoc::Generator::Markdown
682
717
  path = target.sub(/[?#].*\z/, "")
683
718
  suffix = target[path.length..]
684
719
 
685
- resolved = resolve_output_path(path, current_dir)
720
+ resolved = resolve_output_path(path, canonical_dir)
686
721
  rewritten = resolved ? Pathname.new(resolved).relative_path_from(current_dir) : path
687
722
  "](#{rewritten}#{suffix})"
688
723
  end
@@ -854,6 +889,7 @@ class RDoc::Generator::Markdown
854
889
 
855
890
  @class_docs = build_class_docs(@store.all_classes_and_modules.sort)
856
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] }
857
893
  @classes = @class_docs.map { |doc| doc.fetch(:klass) }
858
894
  @pages = @store.all_files.select(&:text?).select(&:display?).sort_by(&:base_name)
859
895
  @rbs_method_signatures = RbsSignatureIndex.build(Array(@options.files), @base_dir, @store)
@@ -5,6 +5,6 @@ module Rdoc
5
5
  # @private
6
6
  module Markdown
7
7
  # @private
8
- VERSION = "0.12.1"
8
+ VERSION = "0.13.0"
9
9
  end
10
10
  end
@@ -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 %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdoc-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov