rdoc-markdown 0.8.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35702d5815f56256651a8994111e772ee761a19a0df97052816431c15247b73b
4
- data.tar.gz: 3720a080b24825ea96ea487d5b264dcbe2cf2f4c5e8ea25be677e9c54a0b0f4e
3
+ metadata.gz: 56a6f33ad7581c2e300d358c58f4537c6154d064495600ea9bd1270116408073
4
+ data.tar.gz: 1a72d5f06233b6264138f9452a494cdada10e99dad50104c4c73473e450e347b
5
5
  SHA512:
6
- metadata.gz: de2608fb5a61247ef9fd33153a8ab75bbfb21b9e3200078a1d59237340a0511cbee0866e90dce2d4a6d73408aed16bd2bb53e09f3e78118c083dd388b411c366
7
- data.tar.gz: d5c8e5de4664c1300b8997c13948b296bd2ed39768396f5a5928cfea176f91130b51359f8ee982e24f2ef2a5284b10f53c2c4dbb6249d0e3726f9225a0e1212c
6
+ metadata.gz: 2abde2f7a06a945237f594f4bdb32c7103c51f7c3779b57e754f9cb58cca0c88252984547908ed6e201f3caacdf9e56e2d438602b8f6eee7beb8135754d4e563
7
+ data.tar.gz: a37cc849f3844ba85037b866939b0d3f1000293fa2c7c693745f99ba654244a4cbb1610fc8c0c804413a202a2a25d367dfd8954bb2178f03eb089560862783e9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rdoc-markdown (0.8.0)
4
+ rdoc-markdown (0.9.0)
5
5
  csv
6
6
  erb
7
7
  rdoc
@@ -112,6 +112,10 @@ GEM
112
112
  nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
113
113
  rainbow (3.1.1)
114
114
  rake (13.4.2)
115
+ rbs (4.0.2)
116
+ logger
117
+ prism (>= 1.6.0)
118
+ tsort
115
119
  rdiscount (2.2.7.4)
116
120
  rdoc (7.2.0)
117
121
  erb
@@ -193,6 +197,7 @@ DEPENDENCIES
193
197
  mutant-minitest
194
198
  mutex_m
195
199
  rake (~> 13.0)
200
+ rbs
196
201
  rdiscount (~> 2.0)
197
202
  rdoc-markdown!
198
203
  simplecov (~> 0.22)
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Optional lookup of method signatures parsed from RBS files.
4
+ class RDoc::Generator::Markdown::RbsSignatureIndex
5
+ # Builds a signature index from RBS files included in an RDoc run.
6
+ #
7
+ # @param files [Array<String>] Input files passed to RDoc.
8
+ #
9
+ # @return [RDoc::Generator::Markdown::RbsSignatureIndex] Signature index.
10
+ def self.build(files)
11
+ rbs_files = files.select { |file| File.extname(file) == ".rbs" }
12
+ new(signatures_from(rbs_files))
13
+ end
14
+
15
+ # Builds signatures by reusing RBS's own RDoc parser.
16
+ #
17
+ # @param files [Array<String>] RBS files to parse.
18
+ #
19
+ # @return [Hash{Array => String}] Signature lookup keyed by class and method.
20
+ def self.signatures_from(files)
21
+ files.each_with_object({}) do |file, signatures|
22
+ parsed_classes(file).each do |klass|
23
+ klass.method_list.each do |method|
24
+ add_method_signature(signatures, klass: klass, method: method)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ # Parses one RBS file into RDoc class/module objects.
31
+ #
32
+ # @param file [String] RBS file path.
33
+ #
34
+ # @return [Array<RDoc::Context>] Classes and modules parsed from RBS.
35
+ def self.parsed_classes(file)
36
+ store = RDoc::Store.new(RDoc::Options.new)
37
+ top_level = store.add_file(file)
38
+ parser = RDoc::Parser.for(top_level, File.read(file), store.options, nil)
39
+ parser.scan
40
+ store.all_classes_and_modules
41
+ end
42
+
43
+ # Adds one RBS-parsed method signature to the lookup.
44
+ #
45
+ # @param signatures [Hash{Array => String}] Signature lookup being populated.
46
+ # @param klass [RDoc::Context] Method owner.
47
+ # @param method [RDoc::AnyMethod] Method parsed by the RBS plugin.
48
+ #
49
+ # @return [void]
50
+ def self.add_method_signature(signatures, klass:, method:)
51
+ signatures[[klass.full_name, method.singleton, method.name]] = method.param_seq
52
+
53
+ return unless method.name == "initialize" && !method.singleton
54
+
55
+ signatures[[klass.full_name, true, "new"]] = method.param_seq
56
+ end
57
+
58
+ # @param signatures [Hash{Array => String}] Signature lookup.
59
+ def initialize(signatures)
60
+ @signatures = signatures
61
+ end
62
+
63
+ # Looks up the RBS signature for an RDoc method.
64
+ #
65
+ # @param method [RDoc::AnyMethod] Method object to render.
66
+ #
67
+ # @return [String, nil] RBS method type string when available.
68
+ def signature_for(method)
69
+ @signatures[[method.parent.full_name, method.singleton, method.name]]
70
+ end
71
+
72
+ # Checks whether any RBS signatures were parsed.
73
+ #
74
+ # @return [Boolean] True when type signatures are available.
75
+ def any?
76
+ @signatures.any?
77
+ end
78
+ end
@@ -12,6 +12,8 @@ require "optparse"
12
12
  class RDoc::Generator::Markdown
13
13
  RDoc::RDoc.add_generator self
14
14
 
15
+ require_relative "markdown/rbs_signature_index"
16
+
15
17
  # Directory containing ERB templates.
16
18
  TEMPLATE_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "templates"))
17
19
 
@@ -384,7 +386,7 @@ class RDoc::Generator::Markdown
384
386
  #
385
387
  # @return [String] Normalized method signature.
386
388
  def method_signature(method)
387
- signature = method.param_seq
389
+ signature = @rbs_method_signatures.signature_for(method) || method.param_seq
388
390
  return "()" unless signature.match?(/\S/)
389
391
 
390
392
  signature = signature.gsub("->", " -> ")
@@ -393,6 +395,13 @@ class RDoc::Generator::Markdown
393
395
  merge_method_signature_arguments(signature, method.params)
394
396
  end
395
397
 
398
+ # Checks whether this documentation set has parsed RBS signatures.
399
+ #
400
+ # @return [Boolean] True when type signatures are available.
401
+ def types_available?
402
+ @rbs_method_signatures.any?
403
+ end
404
+
396
405
  # Merges RDoc parameter names into a type-only signature.
397
406
  #
398
407
  # @param signature [String] Method signature from RDoc call sequence.
@@ -813,6 +822,7 @@ class RDoc::Generator::Markdown
813
822
  @class_docs_by_object_id = @class_docs.to_h { |doc| [doc.fetch(:klass).object_id, doc] }
814
823
  @classes = @class_docs.map { |doc| doc.fetch(:klass) }
815
824
  @pages = @store.all_files.select(&:text?).select(&:display?).sort_by(&:base_name)
825
+ @rbs_method_signatures = RbsSignatureIndex.build(Array(@options.files))
816
826
 
817
827
  @known_output_paths = Set.new
818
828
  @class_docs.each do |doc|
@@ -5,6 +5,6 @@ module Rdoc
5
5
  # Version namespace for rdoc-markdown.
6
6
  module Markdown
7
7
  # Current gem version.
8
- VERSION = "0.8.0"
8
+ VERSION = "0.9.0"
9
9
  end
10
10
  end
@@ -1,5 +1,9 @@
1
1
  # <%= klass.type.capitalize %> <%= display_name(klass) %>
2
2
  <%= anchor(klass.aref.strip) %>
3
+ <%- if types_available? -%>
4
+
5
+ _Type signatures available._
6
+ <%- end -%>
3
7
  <%- class_description = describe(klass) -%>
4
8
  <%- unless class_description.empty? -%>
5
9
 
@@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency "minitest", "~> 5.0"
42
42
  spec.add_development_dependency "minitest-strict", "~> 1.0"
43
43
  spec.add_development_dependency "rake", "~> 13.0"
44
+ spec.add_development_dependency "rbs"
44
45
  spec.add_development_dependency "rdiscount", "~> 2.0"
45
46
  spec.add_development_dependency "simplecov", "~> 0.22"
46
47
  end
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.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov
@@ -135,6 +135,20 @@ dependencies:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
137
  version: '13.0'
138
+ - !ruby/object:Gem::Dependency
139
+ name: rbs
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
138
152
  - !ruby/object:Gem::Dependency
139
153
  name: rdiscount
140
154
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +220,7 @@ files:
206
220
  - lib/markdown.rb
207
221
  - lib/rdoc/discover.rb
208
222
  - lib/rdoc/generator/markdown.rb
223
+ - lib/rdoc/generator/markdown/rbs_signature_index.rb
209
224
  - lib/rdoc/markdown/version.rb
210
225
  - lib/templates/classfile.md.erb
211
226
  - mutant.yml