rdoc 6.10.0 → 6.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59a2919a713acb30b6faff04d96186d25a5e7ab06b76fdfb0df2d42b086b4517
4
- data.tar.gz: 78cb25012a74e585bf9deb1cb0829404cd568d098eac337048a04170f3a7df61
3
+ metadata.gz: d7a81c2ecc4bf154e3dd627e46fb8128cd9b953b2d5108c95fab803049a45fe1
4
+ data.tar.gz: 6307f1c96724b63e01642814567c798f8a2f5e268c105429cf64c92581bec632
5
5
  SHA512:
6
- metadata.gz: 26d8df27e608c4f1d07d3c5f20996514523636447136ec9726ddd0cfdf64ee6c28cd9362e9b1c9747ba41076672c21a8e05c54d934de16f3bebed39bd95ebfc6
7
- data.tar.gz: bfb38f2b3baecd464e36da81caf477de2096ab7c5c059a52167dc0f84bc00b579261b37bf18f63a1ae34953ad1d10699043e1c881166e7c11f17736edb2627e8
6
+ metadata.gz: 3aa0ba6de344876c71c6a749795d81854718397741fe5c9c910b9f43da039cf383130451a6ea779575069b61c5b618f9dae40c8fdc9fddec7bc90a36e1ae8b55
7
+ data.tar.gz: ff19a385007977c9a7234e87181982d5a96c3c80bc5f8b79e5ae95aeda6a75348ece0a76c8d18ea21b55826a7c2471307bfd1eb4d6f15fcee49812ed3458b66d
@@ -198,7 +198,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr
198
198
  @full_name = array[2]
199
199
  @singleton = array[3]
200
200
  @visibility = array[4]
201
- @comment = array[5]
201
+ @comment = RDoc::Comment.from_document array[5]
202
202
  @call_seq = array[6]
203
203
  @block_params = array[7]
204
204
  # 8 handled below
@@ -210,8 +210,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
210
210
  @section_title = array[14]
211
211
  @is_alias_for = array[15]
212
212
 
213
- array[8].each do |new_name, comment|
214
- add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton)
213
+ array[8].each do |new_name, document|
214
+ add_alias RDoc::Alias.new(nil, @name, new_name, RDoc::Comment.from_document(document), @singleton)
215
215
  end
216
216
 
217
217
  @parent_name ||= if @full_name =~ /#/ then
@@ -136,7 +136,7 @@ class RDoc::Attr < RDoc::MethodAttr
136
136
  @full_name = array[2]
137
137
  @rw = array[3]
138
138
  @visibility = array[4]
139
- @comment = array[5]
139
+ @comment = RDoc::Comment.from_document array[5]
140
140
  @singleton = array[6] || false # MARSHAL_VERSION == 0
141
141
  # 7 handled below
142
142
  @parent_name = array[8]
@@ -359,12 +359,14 @@ class RDoc::ClassModule < RDoc::Context
359
359
  @name = array[1]
360
360
  @full_name = array[2]
361
361
  @superclass = array[3]
362
- @comment = array[4]
362
+ document = array[4]
363
363
 
364
- @comment_location = if RDoc::Markup::Document === @comment.parts.first then
365
- @comment
364
+ @comment = RDoc::Comment.from_document document
365
+
366
+ @comment_location = if RDoc::Markup::Document === document.parts.first then
367
+ document
366
368
  else
367
- RDoc::Markup::Document.new @comment
369
+ RDoc::Markup::Document.new document
368
370
  end
369
371
 
370
372
  array[5].each do |name, rw, visibility, singleton, file|
@@ -378,18 +380,18 @@ class RDoc::ClassModule < RDoc::Context
378
380
  attr.record_location RDoc::TopLevel.new file
379
381
  end
380
382
 
381
- array[6].each do |constant, comment, file|
383
+ array[6].each do |constant, document, file|
382
384
  case constant
383
385
  when RDoc::Constant then
384
386
  add_constant constant
385
387
  else
386
- constant = add_constant RDoc::Constant.new(constant, nil, comment)
388
+ constant = add_constant RDoc::Constant.new(constant, nil, RDoc::Comment.from_document(document))
387
389
  constant.record_location RDoc::TopLevel.new file
388
390
  end
389
391
  end
390
392
 
391
- array[7].each do |name, comment, file|
392
- incl = add_include RDoc::Include.new(name, comment)
393
+ array[7].each do |name, document, file|
394
+ incl = add_include RDoc::Include.new(name, RDoc::Comment.from_document(document))
393
395
  incl.record_location RDoc::TopLevel.new file
394
396
  end
395
397
 
@@ -406,8 +408,8 @@ class RDoc::ClassModule < RDoc::Context
406
408
  end
407
409
  end
408
410
 
409
- array[9].each do |name, comment, file|
410
- ext = add_extend RDoc::Extend.new(name, comment)
411
+ array[9].each do |name, document, file|
412
+ ext = add_extend RDoc::Extend.new(name, RDoc::Comment.from_document(document))
411
413
  ext.record_location RDoc::TopLevel.new file
412
414
  end if array[9] # Support Marshal version 1
413
415
 
@@ -444,7 +446,8 @@ class RDoc::ClassModule < RDoc::Context
444
446
 
445
447
  document = document.merge other_document
446
448
 
447
- @comment = @comment_location = document
449
+ @comment = RDoc::Comment.from_document(document)
450
+ @comment_location = document
448
451
  end
449
452
 
450
453
  cm = class_module
@@ -133,7 +133,7 @@ class RDoc::Constant < RDoc::CodeObject
133
133
  # * #parent_name
134
134
 
135
135
  def marshal_load array
136
- initialize array[1], nil, array[5]
136
+ initialize array[1], nil, RDoc::Comment.from_document(array[5])
137
137
 
138
138
  @full_name = array[2]
139
139
  @visibility = array[3] || :public
@@ -61,19 +61,10 @@ class RDoc::Context::Section
61
61
  # Adds +comment+ to this section
62
62
 
63
63
  def add_comment comment
64
- comment = extract_comment comment
65
-
66
- return if comment.empty?
67
-
68
- case comment
69
- when RDoc::Comment then
70
- @comments << comment
71
- when RDoc::Markup::Document then
72
- @comments.concat comment.parts
73
- when Array then
74
- @comments.concat comment
75
- else
76
- raise TypeError, "unknown comment type: #{comment.inspect}"
64
+ comments = Array(comment)
65
+ comments.each do |c|
66
+ extracted_comment = extract_comment(c)
67
+ @comments << extracted_comment unless extracted_comment.empty?
77
68
  end
78
69
  end
79
70
 
@@ -97,10 +88,6 @@ class RDoc::Context::Section
97
88
 
98
89
  def extract_comment comment
99
90
  case comment
100
- when Array then
101
- comment.map do |c|
102
- extract_comment c
103
- end
104
91
  when nil
105
92
  RDoc::Comment.new ''
106
93
  when RDoc::Comment then
@@ -115,8 +102,6 @@ class RDoc::Context::Section
115
102
  end
116
103
  end
117
104
 
118
- comment
119
- when RDoc::Markup::Document then
120
105
  comment
121
106
  else
122
107
  raise TypeError, "unknown comment #{comment.inspect}"
@@ -135,20 +120,7 @@ class RDoc::Context::Section
135
120
  # The files comments in this section come from
136
121
 
137
122
  def in_files
138
- return [] if @comments.empty?
139
-
140
- case @comments
141
- when Array then
142
- @comments.map do |comment|
143
- comment.file
144
- end
145
- when RDoc::Markup::Document then
146
- @comment.parts.map do |document|
147
- document.file
148
- end
149
- else
150
- raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
151
- end
123
+ @comments.map(&:file)
152
124
  end
153
125
 
154
126
  ##
@@ -170,7 +142,7 @@ class RDoc::Context::Section
170
142
  @parent = nil
171
143
 
172
144
  @title = array[1]
173
- @comments = array[2]
145
+ @comments = array[2].parts.map { |doc| RDoc::Comment.from_document(doc) }
174
146
  end
175
147
 
176
148
  ##
@@ -178,26 +150,7 @@ class RDoc::Context::Section
178
150
  # multiple RDoc::Markup::Documents with their file set.
179
151
 
180
152
  def parse
181
- case @comments
182
- when String then
183
- super
184
- when Array then
185
- docs = @comments.map do |comment, location|
186
- doc = super comment
187
- doc.file = location if location
188
- doc
189
- end
190
-
191
- RDoc::Markup::Document.new(*docs)
192
- when RDoc::Comment then
193
- doc = super @comments.text, comments.format
194
- doc.file = @comments.location
195
- doc
196
- when RDoc::Markup::Document then
197
- return @comments
198
- else
199
- raise ArgumentError, "unknown comment class #{comments.class}"
200
- end
153
+ RDoc::Markup::Document.new(*@comments.map(&:parse))
201
154
  end
202
155
 
203
156
  ##
@@ -213,20 +166,9 @@ class RDoc::Context::Section
213
166
  # Removes a comment from this section if it is from the same file as
214
167
  # +comment+
215
168
 
216
- def remove_comment comment
217
- return if @comments.empty?
218
-
219
- case @comments
220
- when Array then
221
- @comments.delete_if do |my_comment|
222
- my_comment.file == comment.file
223
- end
224
- when RDoc::Markup::Document then
225
- @comments.parts.delete_if do |document|
226
- document.file == comment.file.name
227
- end
228
- else
229
- raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
169
+ def remove_comment target_comment
170
+ @comments.delete_if do |stored_comment|
171
+ stored_comment.file == target_comment.file
230
172
  end
231
173
  end
232
174
 
@@ -214,7 +214,7 @@ class RDoc::TopLevel < RDoc::Context
214
214
  initialize array[1]
215
215
 
216
216
  @parser = array[2]
217
- @comment = array[3]
217
+ @comment = RDoc::Comment.from_document array[3]
218
218
 
219
219
  @file_stat = nil
220
220
  end
@@ -141,7 +141,6 @@ class RDoc::CodeObject
141
141
  def comment=(comment)
142
142
  @comment = case comment
143
143
  when NilClass then ''
144
- when RDoc::Markup::Document then comment
145
144
  when RDoc::Comment then comment.normalize
146
145
  else
147
146
  if comment and not comment.empty? then
data/lib/rdoc/comment.rb CHANGED
@@ -126,7 +126,7 @@ class RDoc::Comment
126
126
  # A comment is empty if its text String is empty.
127
127
 
128
128
  def empty?
129
- @text.empty?
129
+ @text.empty? && (@document.nil? || @document.empty?)
130
130
  end
131
131
 
132
132
  ##
@@ -226,4 +226,14 @@ class RDoc::Comment
226
226
  @format == 'tomdoc'
227
227
  end
228
228
 
229
+ ##
230
+ # Create a new parsed comment from a document
231
+
232
+ def self.from_document(document) # :nodoc:
233
+ comment = RDoc::Comment.new('')
234
+ comment.document = document
235
+ comment.location = RDoc::TopLevel.new(document.file) if document.file
236
+ comment
237
+ end
238
+
229
239
  end
@@ -316,11 +316,14 @@ class RDoc::Generator::Darkfish
316
316
  asset_rel_prefix = rel_prefix + @asset_rel_path
317
317
 
318
318
  @title = @options.title
319
+ @main_page = @files.find { |f| f.full_name == @options.main_page }
319
320
 
320
321
  render_template template_file, out_file do |io|
321
322
  here = binding
322
323
  # suppress 1.9.3 warning
323
324
  here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
325
+ # some partials rely on the presence of current variable to render
326
+ here.local_variable_set(:current, @main_page) if @main_page
324
327
  here
325
328
  end
326
329
  rescue => e
@@ -780,20 +783,13 @@ class RDoc::Generator::Darkfish
780
783
  template
781
784
  end
782
785
 
783
- # Returns an excerpt of the content for usage in meta description tags
784
- def excerpt(content)
785
- text = case content
786
+ # Returns an excerpt of the comment for usage in meta description tags
787
+ def excerpt(comment)
788
+ text = case comment
786
789
  when RDoc::Comment
787
- content.text
788
- when RDoc::Markup::Document
789
- # This case is for page files that are not markdown nor rdoc
790
- # We convert them to markdown for now as it's easier to extract the text
791
- formatter = RDoc::Markup::ToMarkdown.new
792
- formatter.start_accepting
793
- formatter.accept_document(content)
794
- formatter.end_accepting
790
+ comment.text
795
791
  else
796
- content
792
+ comment
797
793
  end
798
794
 
799
795
  # Match from a capital letter to the first period, discarding any links, so
@@ -18,6 +18,7 @@
18
18
  solo = top.one? {|klass| klass.display?}
19
19
  traverse = proc do |klasses| -%>
20
20
  <ul class="link-list">
21
+ <%- klasses.uniq!(&:full_name) -%>
21
22
  <%- klasses.each do |index_klass| -%>
22
23
  <%- if children = all_classes[index_klass.full_name] -%>
23
24
  <li><details<% if solo; solo = false %> open<% end %>><summary><% link.call(index_klass) %></summary>
@@ -7,6 +7,7 @@
7
7
  <%= render '_sidebar_search.rhtml' %>
8
8
  </div>
9
9
 
10
+ <%= render '_sidebar_table_of_contents.rhtml' if defined?(current) %>
10
11
  <%= render '_sidebar_pages.rhtml' %>
11
12
  <%= render '_sidebar_classes.rhtml' %>
12
13
 
@@ -14,10 +15,9 @@
14
15
  </nav>
15
16
 
16
17
  <main role="main">
17
- <%- if @options.main_page and
18
- main_page = @files.find { |f| f.full_name == @options.main_page } then %>
19
- <%= main_page.description %>
18
+ <%- if @main_page %>
19
+ <%= @main_page.description %>
20
20
  <%- else -%>
21
- <p>This is the API documentation for <%= h @title %>.
21
+ <p>This is the API documentation for <%= h @title %>.
22
22
  <%- end -%>
23
23
  </main>
@@ -83,6 +83,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
83
83
  def handle_regexp_CROSSREF(target)
84
84
  name = target.text
85
85
 
86
+ return name if @options.autolink_excluded_words&.include?(name)
87
+
86
88
  return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
87
89
 
88
90
  unless @hyperlink_all then
data/lib/rdoc/options.rb CHANGED
@@ -355,18 +355,29 @@ class RDoc::Options
355
355
  # +--[no-]embed-mixins+ (Default is +false+.)
356
356
  attr_accessor :embed_mixins
357
357
 
358
+ ##
359
+ # Exclude the default patterns as well if true.
360
+ attr_reader :apply_default_exclude
361
+
362
+ ##
363
+ # Words to be ignored in autolink cross-references
364
+ attr_accessor :autolink_excluded_words
365
+
358
366
  def initialize loaded_options = nil # :nodoc:
359
367
  init_ivars
360
368
  override loaded_options if loaded_options
361
369
  end
362
370
 
371
+ DEFAULT_EXCLUDE = %w[
372
+ ~\z \.orig\z \.rej\z \.bak\z
373
+ \.gemspec\z
374
+ ]
375
+
363
376
  def init_ivars # :nodoc:
377
+ @autolink_excluded_words = []
364
378
  @dry_run = false
365
379
  @embed_mixins = false
366
- @exclude = %w[
367
- ~\z \.orig\z \.rej\z \.bak\z
368
- \.gemspec\z
369
- ]
380
+ @exclude = []
370
381
  @files = nil
371
382
  @force_output = false
372
383
  @force_update = true
@@ -399,12 +410,13 @@ class RDoc::Options
399
410
  @update_output_dir = true
400
411
  @verbosity = 1
401
412
  @visibility = :protected
402
- @warn_missing_rdoc_ref = false
413
+ @warn_missing_rdoc_ref = true
403
414
  @webcvs = nil
404
415
  @write_options = false
405
416
  @encoding = Encoding::UTF_8
406
417
  @charset = @encoding.name
407
418
  @skip_tests = true
419
+ @apply_default_exclude = true
408
420
  end
409
421
 
410
422
  def init_with map # :nodoc:
@@ -431,6 +443,9 @@ class RDoc::Options
431
443
  @visibility = map['visibility']
432
444
  @webcvs = map['webcvs']
433
445
 
446
+ @apply_default_exclude = map['apply_default_exclude']
447
+ @autolink_excluded_words = map['autolink_excluded_words']
448
+
434
449
  @rdoc_include = sanitize_path map['rdoc_include']
435
450
  @static_path = sanitize_path map['static_path']
436
451
  end
@@ -463,6 +478,8 @@ class RDoc::Options
463
478
  @title = map['title'] if map.has_key?('title')
464
479
  @visibility = map['visibility'] if map.has_key?('visibility')
465
480
  @webcvs = map['webcvs'] if map.has_key?('webcvs')
481
+ @autolink_excluded_words = map['autolink_excluded_words'] if map.has_key?('autolink_excluded_words')
482
+ @apply_default_exclude = map['apply_default_exclude'] if map.has_key?('apply_default_exclude')
466
483
 
467
484
  @warn_missing_rdoc_ref = map['warn_missing_rdoc_ref'] if map.has_key?('warn_missing_rdoc_ref')
468
485
 
@@ -493,7 +510,9 @@ class RDoc::Options
493
510
  @template == other.template and
494
511
  @title == other.title and
495
512
  @visibility == other.visibility and
496
- @webcvs == other.webcvs
513
+ @webcvs == other.webcvs and
514
+ @apply_default_exclude == other.apply_default_exclude and
515
+ @autolink_excluded_words == other.autolink_excluded_words
497
516
  end
498
517
 
499
518
  ##
@@ -564,10 +583,12 @@ class RDoc::Options
564
583
  if @exclude.nil? or Regexp === @exclude then
565
584
  # done, #finish is being re-run
566
585
  @exclude
567
- elsif @exclude.empty? then
586
+ elsif !@apply_default_exclude and @exclude.empty? then
568
587
  nil
569
588
  else
570
- Regexp.new(@exclude.join("|"))
589
+ exclude = @exclude
590
+ exclude |= DEFAULT_EXCLUDE if @apply_default_exclude
591
+ Regexp.new(exclude.join("|"))
571
592
  end
572
593
  end
573
594
 
@@ -801,6 +822,11 @@ Usage: #{opt.program_name} [options] [names...]
801
822
  @exclude << value
802
823
  end
803
824
 
825
+ opt.on("--[no-]apply-default-exclude",
826
+ "Use default PATTERN to exclude.") do |value|
827
+ @apply_default_exclude = value
828
+ end
829
+
804
830
  opt.separator nil
805
831
 
806
832
  opt.on("--no-skipping-tests", nil,
@@ -972,6 +998,13 @@ Usage: #{opt.program_name} [options] [names...]
972
998
 
973
999
  opt.separator nil
974
1000
 
1001
+ opt.on("--autolink-excluded-words=WORDS", Array,
1002
+ "Words to be ignored in autolink cross-references") do |value|
1003
+ @autolink_excluded_words.concat value
1004
+ end
1005
+
1006
+ opt.separator nil
1007
+
975
1008
  opt.on("--hyperlink-all", "-A",
976
1009
  "Generate hyperlinks for all words that",
977
1010
  "correspond to known methods, even if they",
data/lib/rdoc/parser/c.rb CHANGED
@@ -168,7 +168,7 @@ class RDoc::Parser::C < RDoc::Parser
168
168
  # Prepares for parsing a C file. See RDoc::Parser#initialize for details on
169
169
  # the arguments.
170
170
 
171
- def initialize top_level, file_name, content, options, stats
171
+ def initialize top_level, content, options, stats
172
172
  super
173
173
 
174
174
  @known_classes = RDoc::KNOWN_CLASSES.dup
@@ -210,8 +210,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
210
210
  grouped_entries = group_entries entries
211
211
 
212
212
  doc = create_document grouped_entries
213
-
214
- @top_level.comment = doc
213
+ comment = RDoc::Comment.new(@content)
214
+ comment.document = doc
215
+ @top_level.comment = comment
215
216
 
216
217
  @top_level
217
218
  end
@@ -18,7 +18,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
18
18
  attr_accessor :visibility
19
19
  attr_reader :container, :singleton
20
20
 
21
- def initialize(top_level, file_name, content, options, stats)
21
+ def initialize(top_level, content, options, stats)
22
22
  super
23
23
 
24
24
  content = handle_tab_width(content)
@@ -31,10 +31,21 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
31
31
  @track_visibility = :nodoc != @options.visibility
32
32
  @encoding = @options.encoding
33
33
 
34
- @module_nesting = [top_level]
34
+ @module_nesting = [[top_level, false]]
35
35
  @container = top_level
36
36
  @visibility = :public
37
37
  @singleton = false
38
+ @in_proc_block = false
39
+ end
40
+
41
+ # Suppress `extend` and `include` within block
42
+ # because they might be a metaprogramming block
43
+ # example: `Module.new { include M }` `M.module_eval { include N }`
44
+
45
+ def with_in_proc_block
46
+ @in_proc_block = true
47
+ yield
48
+ @in_proc_block = false
38
49
  end
39
50
 
40
51
  # Dive into another container
@@ -43,22 +54,24 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
43
54
  old_container = @container
44
55
  old_visibility = @visibility
45
56
  old_singleton = @singleton
57
+ old_in_proc_block = @in_proc_block
46
58
  @visibility = :public
47
59
  @container = container
48
60
  @singleton = singleton
61
+ @in_proc_block = false
49
62
  unless singleton
50
- @module_nesting.push container
51
-
52
63
  # Need to update module parent chain to emulate Module.nesting.
53
64
  # This mechanism is inaccurate and needs to be fixed.
54
65
  container.parent = old_container
55
66
  end
67
+ @module_nesting.push([container, singleton])
56
68
  yield container
57
69
  ensure
58
70
  @container = old_container
59
71
  @visibility = old_visibility
60
72
  @singleton = old_singleton
61
- @module_nesting.pop unless singleton
73
+ @in_proc_block = old_in_proc_block
74
+ @module_nesting.pop
62
75
  end
63
76
 
64
77
  # Records the location of this +container+ in the file for this parser and
@@ -204,6 +217,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
204
217
  @stats.add_method meth
205
218
  end
206
219
 
220
+ def has_modifier_nodoc?(line_no) # :nodoc:
221
+ @modifier_comments[line_no]&.text&.match?(/\A#\s*:nodoc:/)
222
+ end
223
+
207
224
  def handle_modifier_directive(code_object, line_no) # :nodoc:
208
225
  comment = @modifier_comments[line_no]
209
226
  @preprocess.handle(comment.text, code_object) if comment
@@ -467,6 +484,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
467
484
  end
468
485
 
469
486
  def add_includes_extends(names, rdoc_class, line_no) # :nodoc:
487
+ return if @in_proc_block
470
488
  comment = consecutive_comment(line_no)
471
489
  handle_consecutive_comment_directive(@container, comment)
472
490
  names.each do |name|
@@ -492,7 +510,9 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
492
510
 
493
511
  # Adds a method defined by `def` syntax
494
512
 
495
- def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, end_line:)
513
+ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, args_end_line:, end_line:)
514
+ return if @in_proc_block
515
+
496
516
  receiver = receiver_name ? find_or_create_module_path(receiver_name, receiver_fallback_type) : @container
497
517
  meth = RDoc::AnyMethod.new(nil, name)
498
518
  if (comment = consecutive_comment(start_line))
@@ -504,20 +524,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
504
524
  meth.comment = comment
505
525
  end
506
526
  handle_modifier_directive(meth, start_line)
527
+ handle_modifier_directive(meth, args_end_line)
507
528
  handle_modifier_directive(meth, end_line)
508
529
  return unless should_document?(meth)
509
530
 
510
-
511
- if meth.name == 'initialize' && !singleton
512
- if meth.dont_rename_initialize
513
- visibility = :protected
514
- else
515
- meth.name = 'new'
516
- singleton = true
517
- visibility = :public
518
- end
519
- end
520
-
521
531
  internal_add_method(
522
532
  receiver,
523
533
  meth,
@@ -529,6 +539,18 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
529
539
  block_params: block_params,
530
540
  tokens: tokens
531
541
  )
542
+
543
+ # Rename after add_method to register duplicated 'new' and 'initialize'
544
+ # defined in c and ruby just like the old parser did.
545
+ if meth.name == 'initialize' && !singleton
546
+ if meth.dont_rename_initialize
547
+ meth.visibility = :protected
548
+ else
549
+ meth.name = 'new'
550
+ meth.singleton = true
551
+ meth.visibility = :public
552
+ end
553
+ end
532
554
  end
533
555
 
534
556
  private def internal_add_method(container, meth, line_no:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:) # :nodoc:
@@ -565,12 +587,17 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
565
587
  if root_name.empty?
566
588
  mod = @top_level
567
589
  else
568
- @module_nesting.reverse_each do |nesting|
590
+ @module_nesting.reverse_each do |nesting, singleton|
591
+ next if singleton
569
592
  mod = nesting.find_module_named(root_name)
570
593
  break if mod
594
+ # If a constant is found and it is not a module or class, RDoc can't document about it.
595
+ # Return an anonymous module to avoid wrong document creation.
596
+ return RDoc::NormalModule.new(nil) if nesting.find_constant_named(root_name)
571
597
  end
572
- return mod || add_module.call(@top_level, root_name, create_mode) unless name
573
- mod ||= add_module.call(@top_level, root_name, :module)
598
+ last_nesting, = @module_nesting.reverse_each.find { |_, singleton| !singleton }
599
+ return mod || add_module.call(last_nesting, root_name, create_mode) unless name
600
+ mod ||= add_module.call(last_nesting, root_name, :module)
574
601
  end
575
602
  path.each do |name|
576
603
  mod = mod.find_module_named(name) || add_module.call(mod, name, :module)
@@ -584,7 +611,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
584
611
  owner_name, path = constant_path.split('::', 2)
585
612
  return constant_path if owner_name.empty? # ::Foo, ::Foo::Bar
586
613
  mod = nil
587
- @module_nesting.reverse_each do |nesting|
614
+ @module_nesting.reverse_each do |nesting, singleton|
615
+ next if singleton
588
616
  mod = nesting.find_module_named(owner_name)
589
617
  break if mod
590
618
  end
@@ -598,7 +626,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
598
626
  def find_or_create_constant_owner_name(constant_path)
599
627
  const_path, colon, name = constant_path.rpartition('::')
600
628
  if colon.empty? # class Foo
601
- [@container, name]
629
+ # Within `class C` or `module C`, owner is C(== current container)
630
+ # Within `class <<C`, owner is C.singleton_class
631
+ # but RDoc don't track constants of a singleton class of module
632
+ [(@singleton ? nil : @container), name]
602
633
  elsif const_path.empty? # class ::Foo
603
634
  [@top_level, name]
604
635
  else # `class Foo::Bar` or `class ::Foo::Bar`
@@ -612,6 +643,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
612
643
  comment = consecutive_comment(start_line)
613
644
  handle_consecutive_comment_directive(@container, comment)
614
645
  owner, name = find_or_create_constant_owner_name(constant_name)
646
+ return unless owner
647
+
615
648
  constant = RDoc::Constant.new(name, rhs_name, comment)
616
649
  constant.store = @store
617
650
  constant.line = start_line
@@ -635,24 +668,29 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
635
668
 
636
669
  # Adds module or class
637
670
 
638
- def add_module_or_class(module_name, start_line, end_line, is_class: false, superclass_name: nil)
671
+ def add_module_or_class(module_name, start_line, end_line, is_class: false, superclass_name: nil, superclass_expr: nil)
639
672
  comment = consecutive_comment(start_line)
640
673
  handle_consecutive_comment_directive(@container, comment)
641
674
  return unless @container.document_children
642
675
 
643
676
  owner, name = find_or_create_constant_owner_name(module_name)
644
- if is_class
645
- mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || '::Object')
677
+ return unless owner
646
678
 
679
+ if is_class
647
680
  # RDoc::NormalClass resolves superclass name despite of the lack of module nesting information.
648
681
  # We need to fix it when RDoc::NormalClass resolved to a wrong constant name
649
682
  if superclass_name
650
683
  superclass_full_path = resolve_constant_path(superclass_name)
651
684
  superclass = @store.find_class_or_module(superclass_full_path) if superclass_full_path
652
685
  superclass_full_path ||= superclass_name
686
+ superclass_full_path = superclass_full_path.sub(/^::/, '')
687
+ end
688
+ # add_class should be done after resolving superclass
689
+ mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || superclass_expr || '::Object')
690
+ if superclass_name
653
691
  if superclass
654
692
  mod.superclass = superclass
655
- elsif mod.superclass.is_a?(String) && mod.superclass != superclass_full_path
693
+ elsif (mod.superclass.is_a?(String) || mod.superclass.name == 'Object') && mod.superclass != superclass_full_path
656
694
  mod.superclass = superclass_full_path
657
695
  end
658
696
  end
@@ -676,6 +714,20 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
676
714
  @store = store
677
715
  end
678
716
 
717
+ def visit_if_node(node)
718
+ if node.end_keyword
719
+ super
720
+ else
721
+ # Visit with the order in text representation to handle this method comment
722
+ # # comment
723
+ # def f
724
+ # end if call_node
725
+ node.statements.accept(self)
726
+ node.predicate.accept(self)
727
+ end
728
+ end
729
+ alias visit_unless_node visit_if_node
730
+
679
731
  def visit_call_node(node)
680
732
  @scanner.process_comments_until(node.location.start_line - 1)
681
733
  if node.receiver.nil?
@@ -713,6 +765,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
713
765
  when :private_class_method
714
766
  _visit_call_public_private_class_method(node, :private) { super }
715
767
  else
768
+ node.arguments&.accept(self)
716
769
  super
717
770
  end
718
771
  else
@@ -720,6 +773,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
720
773
  end
721
774
  end
722
775
 
776
+ def visit_block_node(node)
777
+ @scanner.with_in_proc_block do
778
+ # include, extend and method definition inside block are not documentable
779
+ super
780
+ end
781
+ end
782
+
723
783
  def visit_alias_method_node(node)
724
784
  @scanner.process_comments_until(node.location.start_line - 1)
725
785
  return unless node.old_name.is_a?(Prism::SymbolNode) && node.new_name.is_a?(Prism::SymbolNode)
@@ -727,12 +787,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
727
787
  end
728
788
 
729
789
  def visit_module_node(node)
790
+ node.constant_path.accept(self)
730
791
  @scanner.process_comments_until(node.location.start_line - 1)
731
792
  module_name = constant_path_string(node.constant_path)
732
793
  mod = @scanner.add_module_or_class(module_name, node.location.start_line, node.location.end_line) if module_name
733
794
  if mod
734
795
  @scanner.with_container(mod) do
735
- super
796
+ node.body&.accept(self)
736
797
  @scanner.process_comments_until(node.location.end_line)
737
798
  end
738
799
  else
@@ -741,13 +802,16 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
741
802
  end
742
803
 
743
804
  def visit_class_node(node)
805
+ node.constant_path.accept(self)
806
+ node.superclass&.accept(self)
744
807
  @scanner.process_comments_until(node.location.start_line - 1)
745
808
  superclass_name = constant_path_string(node.superclass) if node.superclass
809
+ superclass_expr = node.superclass.slice if node.superclass && !superclass_name
746
810
  class_name = constant_path_string(node.constant_path)
747
- klass = @scanner.add_module_or_class(class_name, node.location.start_line, node.location.end_line, is_class: true, superclass_name: superclass_name) if class_name
811
+ klass = @scanner.add_module_or_class(class_name, node.location.start_line, node.location.end_line, is_class: true, superclass_name: superclass_name, superclass_expr: superclass_expr) if class_name
748
812
  if klass
749
813
  @scanner.with_container(klass) do
750
- super
814
+ node.body&.accept(self)
751
815
  @scanner.process_comments_until(node.location.end_line)
752
816
  end
753
817
  else
@@ -758,6 +822,12 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
758
822
  def visit_singleton_class_node(node)
759
823
  @scanner.process_comments_until(node.location.start_line - 1)
760
824
 
825
+ if @scanner.has_modifier_nodoc?(node.location.start_line)
826
+ # Skip visiting inside the singleton class. Also skips creation of node.expression as a module
827
+ @scanner.skip_comments_until(node.location.end_line)
828
+ return
829
+ end
830
+
761
831
  expression = node.expression
762
832
  expression = expression.body.body.first if expression.is_a?(Prism::ParenthesesNode) && expression.body&.body&.size == 1
763
833
 
@@ -772,9 +842,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
772
842
  when Prism::SelfNode
773
843
  mod = @scanner.container if @scanner.container != @top_level
774
844
  end
845
+ expression.accept(self)
775
846
  if mod
776
847
  @scanner.with_container(mod, singleton: true) do
777
- super
848
+ node.body&.accept(self)
778
849
  @scanner.process_comments_until(node.location.end_line)
779
850
  end
780
851
  else
@@ -784,6 +855,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
784
855
 
785
856
  def visit_def_node(node)
786
857
  start_line = node.location.start_line
858
+ args_end_line = node.parameters&.location&.end_line || start_line
787
859
  end_line = node.location.end_line
788
860
  @scanner.process_comments_until(start_line - 1)
789
861
 
@@ -834,6 +906,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
834
906
  calls_super: calls_super,
835
907
  tokens: tokens,
836
908
  start_line: start_line,
909
+ args_end_line: args_end_line,
837
910
  end_line: end_line
838
911
  )
839
912
  ensure
@@ -942,7 +1015,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
942
1015
  @scanner.visibility = visibility
943
1016
  else # `public :foo, :bar`, `private def foo; end`
944
1017
  yield
945
- names = visibility_method_arguments(call_node, singleton: @scanner.singleton)
1018
+ names = visibility_method_arguments(call_node, singleton: false)
946
1019
  @scanner.change_method_visibility(names, visibility) if names
947
1020
  end
948
1021
  end
@@ -170,7 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
170
170
  ##
171
171
  # Creates a new Ruby parser.
172
172
 
173
- def initialize(top_level, file_name, content, options, stats)
173
+ def initialize(top_level, content, options, stats)
174
174
  super
175
175
 
176
176
  content = handle_tab_width(content)
@@ -14,7 +14,7 @@ class RDoc::Parser::Simple < RDoc::Parser
14
14
  ##
15
15
  # Prepare to parse a plain file
16
16
 
17
- def initialize(top_level, file_name, content, options, stats)
17
+ def initialize(top_level, content, options, stats)
18
18
  super
19
19
 
20
20
  preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
data/lib/rdoc/parser.rb CHANGED
@@ -191,7 +191,7 @@ class RDoc::Parser
191
191
 
192
192
  content = remove_modeline content
193
193
 
194
- parser.new top_level, file_name, content, options, stats
194
+ parser.new top_level, content, options, stats
195
195
  rescue SystemCallError
196
196
  nil
197
197
  end
@@ -252,12 +252,12 @@ class RDoc::Parser
252
252
  # RDoc::Markup::PreProcess object is created which allows processing of
253
253
  # directives.
254
254
 
255
- def initialize top_level, file_name, content, options, stats
255
+ def initialize top_level, content, options, stats
256
256
  @top_level = top_level
257
257
  @top_level.parser = self.class
258
258
  @store = @top_level.store
259
259
 
260
- @file_name = file_name
260
+ @file_name = top_level.absolute_name
261
261
  @content = content
262
262
  @options = options
263
263
  @stats = stats
@@ -518,7 +518,7 @@ or the PAGER environment variable.
518
518
  with.each do |incl|
519
519
  out << RDoc::Markup::Paragraph.new(incl.name)
520
520
  out << RDoc::Markup::BlankLine.new
521
- out << incl.comment
521
+ out << incl.comment.parse
522
522
  end
523
523
 
524
524
  unless wout.empty? then
@@ -542,7 +542,7 @@ or the PAGER environment variable.
542
542
 
543
543
  if include.comment then
544
544
  out << RDoc::Markup::BlankLine.new
545
- out << include.comment
545
+ out << include.comment.parse
546
546
  end
547
547
  end
548
548
 
@@ -657,12 +657,12 @@ or the PAGER environment variable.
657
657
  ##
658
658
  # Adds the class +comment+ to +out+.
659
659
 
660
- def class_document_comment out, comment # :nodoc:
661
- unless comment.empty? then
660
+ def class_document_comment out, document # :nodoc:
661
+ unless document.empty? then
662
662
  out << RDoc::Markup::Rule.new(1)
663
663
 
664
- if comment.merged? then
665
- parts = comment.parts
664
+ if document.merged? then
665
+ parts = document.parts
666
666
  parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length
667
667
  parts.flatten!
668
668
  parts.pop
@@ -687,7 +687,7 @@ or the PAGER environment variable.
687
687
  constants = klass.constants.sort_by { |constant| constant.name }
688
688
 
689
689
  list.items.concat constants.map { |constant|
690
- parts = constant.comment.parts if constant.comment
690
+ parts = constant.comment.parse.parts
691
691
  parts << RDoc::Markup::Paragraph.new('[not documented]') if
692
692
  parts.empty?
693
693
 
@@ -906,7 +906,7 @@ or the PAGER environment variable.
906
906
 
907
907
  page = store.load_page page_name
908
908
 
909
- display page.comment
909
+ display page.comment.parse
910
910
  end
911
911
 
912
912
  ##
@@ -1207,7 +1207,8 @@ or the PAGER environment variable.
1207
1207
 
1208
1208
  store.load_method klass, "#{type}#{method}"
1209
1209
  rescue RDoc::Store::MissingFileError => e
1210
- comment = RDoc::Comment.new("missing documentation at #{e.file}").parse
1210
+ comment = RDoc::Comment.new("missing documentation at #{e.file}")
1211
+ comment.parse
1211
1212
 
1212
1213
  method = RDoc::AnyMethod.new nil, name
1213
1214
  method.comment = comment
@@ -1367,13 +1368,13 @@ or the PAGER environment variable.
1367
1368
  # documentable items the class is added to +also_in+ instead.
1368
1369
 
1369
1370
  def render_class out, store, klass, also_in # :nodoc:
1370
- comment = klass.comment
1371
+ document = klass.comment.parse
1371
1372
  # TODO the store's cache should always return an empty Array
1372
1373
  class_methods = store.class_methods[klass.full_name] || []
1373
1374
  instance_methods = store.instance_methods[klass.full_name] || []
1374
1375
  attributes = store.attributes[klass.full_name] || []
1375
1376
 
1376
- if comment.empty? and
1377
+ if document.empty? and
1377
1378
  instance_methods.empty? and class_methods.empty? then
1378
1379
  also_in << store
1379
1380
  return
@@ -1381,7 +1382,7 @@ or the PAGER environment variable.
1381
1382
 
1382
1383
  add_from out, store
1383
1384
 
1384
- class_document_comment out, comment
1385
+ class_document_comment out, document
1385
1386
 
1386
1387
  if class_methods or instance_methods or not klass.constants.empty? then
1387
1388
  out << RDoc::Markup::Rule.new(1)
@@ -1429,16 +1430,16 @@ or the PAGER environment variable.
1429
1430
  if alias_for
1430
1431
  unless method.comment.nil? or method.comment.empty?
1431
1432
  out << RDoc::Markup::BlankLine.new
1432
- out << method.comment
1433
+ out << method.comment.parse
1433
1434
  end
1434
1435
  out << RDoc::Markup::BlankLine.new
1435
1436
  out << RDoc::Markup::Paragraph.new("(This method is an alias for #{alias_for.full_name}.)")
1436
1437
  out << RDoc::Markup::BlankLine.new
1437
- out << alias_for.comment
1438
+ out << alias_for.comment.parse
1438
1439
  out << RDoc::Markup::BlankLine.new
1439
1440
  else
1440
1441
  out << RDoc::Markup::BlankLine.new
1441
- out << method.comment
1442
+ out << method.comment.parse
1442
1443
  out << RDoc::Markup::BlankLine.new
1443
1444
  end
1444
1445
  end
@@ -1551,7 +1552,7 @@ or the PAGER environment variable.
1551
1552
  found_pages.each do |page|
1552
1553
  out << RDoc::Markup::Heading.new(4, "Expanded from #{page.full_name}")
1553
1554
  out << RDoc::Markup::BlankLine.new
1554
- out << page.comment
1555
+ out << page.comment.parse
1555
1556
  end
1556
1557
  end
1557
1558
  end
@@ -181,10 +181,10 @@ class RDoc::RubyGemsHook
181
181
  options = ::RDoc::Options.new
182
182
  options.default_title = "#{@spec.full_name} Documentation"
183
183
  options.parse args
184
+ options.quiet = !Gem.configuration.really_verbose
185
+ options.finish
184
186
  end
185
187
 
186
- options.quiet = !Gem.configuration.really_verbose
187
-
188
188
  @rdoc = new_rdoc
189
189
  @rdoc.options = options
190
190
 
@@ -310,5 +310,21 @@ module RDoc
310
310
  # Generate document for compatibility if this is a default gem.
311
311
  RubyGemsHook.generate(installer, specs)
312
312
  end
313
+
314
+ def self.load_rdoc
315
+ RubyGemsHook.load_rdoc
316
+ end
317
+
318
+ def self.rdoc_version
319
+ RubyGemsHook.rdoc_version
320
+ end
321
+
322
+ def rdoc_installed?
323
+ RubyGemsHook.new(@spec).rdoc_installed?
324
+ end
325
+
326
+ def ri_installed?
327
+ RubyGemsHook.new(@spec).ri_installed?
328
+ end
313
329
  end
314
330
  end
data/lib/rdoc/version.rb CHANGED
@@ -5,6 +5,6 @@ module RDoc
5
5
  ##
6
6
  # RDoc version you are using
7
7
 
8
- VERSION = '6.10.0'
8
+ VERSION = '6.12.0'
9
9
 
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.10.0
4
+ version: 6.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -11,10 +11,9 @@ authors:
11
11
  - Zachary Scott
12
12
  - Hiroshi SHIBATA
13
13
  - ITOYANAGI Sakura
14
- autorequire:
15
14
  bindir: exe
16
15
  cert_chain: []
17
- date: 2024-12-18 00:00:00.000000000 Z
16
+ date: 2025-02-06 00:00:00.000000000 Z
18
17
  dependencies:
19
18
  - !ruby/object:Gem::Dependency
20
19
  name: psych
@@ -254,7 +253,6 @@ metadata:
254
253
  homepage_uri: https://ruby.github.io/rdoc
255
254
  source_code_uri: https://github.com/ruby/rdoc
256
255
  changelog_uri: https://github.com/ruby/rdoc/releases
257
- post_install_message:
258
256
  rdoc_options:
259
257
  - "--main"
260
258
  - README.rdoc
@@ -271,8 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
269
  - !ruby/object:Gem::Version
272
270
  version: '2.2'
273
271
  requirements: []
274
- rubygems_version: 3.5.22
275
- signing_key:
272
+ rubygems_version: 3.6.2
276
273
  specification_version: 4
277
274
  summary: RDoc produces HTML and command-line documentation for Ruby projects
278
275
  test_files: []