rdoc 6.11.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: 870fa0cb431cb2be4520001d6bceb293d36475e2d96e090d749a2ee7b91bb979
4
- data.tar.gz: ea650e35d6b2fe0a33a031e8df70be62742d9046cf9ad9aca8d7ead3cac67038
3
+ metadata.gz: d7a81c2ecc4bf154e3dd627e46fb8128cd9b953b2d5108c95fab803049a45fe1
4
+ data.tar.gz: 6307f1c96724b63e01642814567c798f8a2f5e268c105429cf64c92581bec632
5
5
  SHA512:
6
- metadata.gz: b3cc3a1797ce0a7538620e71b04f5db77eea9af380b6c8db05b283cc17f4b0504d096c33fac55f06c7004100a1d18217e154dcf4f24a7538167292746be9a16c
7
- data.tar.gz: 0f52da54649752c27b2b330e6cda90aa9c478b8f4fd068b291666771d55e84db67a6c57f5261b4678260b93726eb4ec21c2728e706be0bfb37d1ad3277188330
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
@@ -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>
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,12 +668,14 @@ 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)
677
+ return unless owner
678
+
644
679
  if is_class
645
680
  # RDoc::NormalClass resolves superclass name despite of the lack of module nesting information.
646
681
  # We need to fix it when RDoc::NormalClass resolved to a wrong constant name
@@ -648,13 +683,14 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
648
683
  superclass_full_path = resolve_constant_path(superclass_name)
649
684
  superclass = @store.find_class_or_module(superclass_full_path) if superclass_full_path
650
685
  superclass_full_path ||= superclass_name
686
+ superclass_full_path = superclass_full_path.sub(/^::/, '')
651
687
  end
652
688
  # add_class should be done after resolving superclass
653
- mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || '::Object')
689
+ mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || superclass_expr || '::Object')
654
690
  if superclass_name
655
691
  if superclass
656
692
  mod.superclass = superclass
657
- 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
658
694
  mod.superclass = superclass_full_path
659
695
  end
660
696
  end
@@ -678,6 +714,20 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
678
714
  @store = store
679
715
  end
680
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
+
681
731
  def visit_call_node(node)
682
732
  @scanner.process_comments_until(node.location.start_line - 1)
683
733
  if node.receiver.nil?
@@ -715,6 +765,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
715
765
  when :private_class_method
716
766
  _visit_call_public_private_class_method(node, :private) { super }
717
767
  else
768
+ node.arguments&.accept(self)
718
769
  super
719
770
  end
720
771
  else
@@ -722,6 +773,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
722
773
  end
723
774
  end
724
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
+
725
783
  def visit_alias_method_node(node)
726
784
  @scanner.process_comments_until(node.location.start_line - 1)
727
785
  return unless node.old_name.is_a?(Prism::SymbolNode) && node.new_name.is_a?(Prism::SymbolNode)
@@ -729,12 +787,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
729
787
  end
730
788
 
731
789
  def visit_module_node(node)
790
+ node.constant_path.accept(self)
732
791
  @scanner.process_comments_until(node.location.start_line - 1)
733
792
  module_name = constant_path_string(node.constant_path)
734
793
  mod = @scanner.add_module_or_class(module_name, node.location.start_line, node.location.end_line) if module_name
735
794
  if mod
736
795
  @scanner.with_container(mod) do
737
- super
796
+ node.body&.accept(self)
738
797
  @scanner.process_comments_until(node.location.end_line)
739
798
  end
740
799
  else
@@ -743,13 +802,16 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
743
802
  end
744
803
 
745
804
  def visit_class_node(node)
805
+ node.constant_path.accept(self)
806
+ node.superclass&.accept(self)
746
807
  @scanner.process_comments_until(node.location.start_line - 1)
747
808
  superclass_name = constant_path_string(node.superclass) if node.superclass
809
+ superclass_expr = node.superclass.slice if node.superclass && !superclass_name
748
810
  class_name = constant_path_string(node.constant_path)
749
- 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
750
812
  if klass
751
813
  @scanner.with_container(klass) do
752
- super
814
+ node.body&.accept(self)
753
815
  @scanner.process_comments_until(node.location.end_line)
754
816
  end
755
817
  else
@@ -760,6 +822,12 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
760
822
  def visit_singleton_class_node(node)
761
823
  @scanner.process_comments_until(node.location.start_line - 1)
762
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
+
763
831
  expression = node.expression
764
832
  expression = expression.body.body.first if expression.is_a?(Prism::ParenthesesNode) && expression.body&.body&.size == 1
765
833
 
@@ -774,9 +842,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
774
842
  when Prism::SelfNode
775
843
  mod = @scanner.container if @scanner.container != @top_level
776
844
  end
845
+ expression.accept(self)
777
846
  if mod
778
847
  @scanner.with_container(mod, singleton: true) do
779
- super
848
+ node.body&.accept(self)
780
849
  @scanner.process_comments_until(node.location.end_line)
781
850
  end
782
851
  else
@@ -786,6 +855,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
786
855
 
787
856
  def visit_def_node(node)
788
857
  start_line = node.location.start_line
858
+ args_end_line = node.parameters&.location&.end_line || start_line
789
859
  end_line = node.location.end_line
790
860
  @scanner.process_comments_until(start_line - 1)
791
861
 
@@ -836,6 +906,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
836
906
  calls_super: calls_super,
837
907
  tokens: tokens,
838
908
  start_line: start_line,
909
+ args_end_line: args_end_line,
839
910
  end_line: end_line
840
911
  )
841
912
  ensure
@@ -944,7 +1015,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
944
1015
  @scanner.visibility = visibility
945
1016
  else # `public :foo, :bar`, `private def foo; end`
946
1017
  yield
947
- names = visibility_method_arguments(call_node, singleton: @scanner.singleton)
1018
+ names = visibility_method_arguments(call_node, singleton: false)
948
1019
  @scanner.change_method_visibility(names, visibility) if names
949
1020
  end
950
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
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.11.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.11.0
4
+ version: 6.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -13,7 +13,7 @@ authors:
13
13
  - ITOYANAGI Sakura
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2025-01-16 00:00:00.000000000 Z
16
+ date: 2025-02-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: psych