rdoc 6.3.4.1 → 8.0.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.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +195 -0
  3. data/History.rdoc +65 -63
  4. data/LEGAL.rdoc +7 -1
  5. data/LICENSE.rdoc +6 -0
  6. data/README.md +236 -0
  7. data/RI.md +842 -0
  8. data/TODO.rdoc +8 -7
  9. data/doc/markup_reference/markdown.md +659 -0
  10. data/doc/markup_reference/rdoc.rdoc +1169 -0
  11. data/exe/rdoc +0 -1
  12. data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -18
  13. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +50 -24
  14. data/lib/rdoc/{attr.rb → code_object/attr.rb} +16 -14
  15. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +225 -58
  16. data/lib/rdoc/{constant.rb → code_object/constant.rb} +44 -10
  17. data/lib/rdoc/code_object/context/section.rb +182 -0
  18. data/lib/rdoc/{context.rb → code_object/context.rb} +78 -106
  19. data/lib/rdoc/{extend.rb → code_object/extend.rb} +0 -1
  20. data/lib/rdoc/{include.rb → code_object/include.rb} +0 -1
  21. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +46 -48
  22. data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +6 -4
  23. data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +2 -3
  24. data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
  25. data/lib/rdoc/{require.rb → code_object/require.rb} +1 -2
  26. data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +5 -1
  27. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +60 -63
  28. data/lib/rdoc/code_object.rb +11 -39
  29. data/lib/rdoc/code_objects.rb +1 -2
  30. data/lib/rdoc/comment.rb +202 -99
  31. data/lib/rdoc/cross_reference.rb +75 -62
  32. data/lib/rdoc/encoding.rb +8 -24
  33. data/lib/rdoc/erb_partial.rb +1 -2
  34. data/lib/rdoc/erbio.rb +3 -8
  35. data/lib/rdoc/generator/aliki.rb +200 -0
  36. data/lib/rdoc/generator/darkfish.rb +156 -122
  37. data/lib/rdoc/generator/json_index.rb +8 -24
  38. data/lib/rdoc/generator/markup.rb +70 -34
  39. data/lib/rdoc/generator/pot/message_extractor.rb +7 -7
  40. data/lib/rdoc/generator/pot/po.rb +1 -1
  41. data/lib/rdoc/generator/pot/po_entry.rb +8 -8
  42. data/lib/rdoc/generator/pot.rb +1 -5
  43. data/lib/rdoc/generator/ri.rb +1 -2
  44. data/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
  45. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  46. data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  47. data/lib/rdoc/generator/template/aliki/_head.rhtml +163 -0
  48. data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  49. data/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
  50. data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
  51. data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
  52. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +27 -0
  53. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +27 -0
  54. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  55. data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
  56. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
  57. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  58. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
  59. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  60. data/lib/rdoc/generator/template/aliki/class.rhtml +230 -0
  61. data/lib/rdoc/generator/template/aliki/css/rdoc.css +2181 -0
  62. data/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
  63. data/lib/rdoc/generator/template/aliki/js/aliki.js +513 -0
  64. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  65. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  66. data/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
  67. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  68. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  69. data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  70. data/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
  71. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  72. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  73. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +3 -3
  74. data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -14
  75. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
  76. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +11 -9
  77. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +11 -9
  78. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +7 -6
  79. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +20 -11
  80. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +25 -5
  81. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
  82. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +2 -1
  83. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  84. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +28 -7
  85. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  86. data/lib/rdoc/generator/template/darkfish/class.rhtml +138 -90
  87. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +420 -358
  88. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  89. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  90. data/lib/rdoc/generator/template/darkfish/index.rhtml +14 -12
  91. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +59 -3
  92. data/lib/rdoc/generator/template/darkfish/js/search.js +15 -5
  93. data/lib/rdoc/generator/template/darkfish/page.rhtml +7 -6
  94. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +12 -9
  95. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +24 -21
  96. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +35 -21
  97. data/lib/rdoc/generator/template/json_index/js/navigation.js +8 -8
  98. data/lib/rdoc/generator/template/json_index/js/searcher.js +48 -6
  99. data/lib/rdoc/generator.rb +6 -5
  100. data/lib/rdoc/i18n/text.rb +3 -3
  101. data/lib/rdoc/i18n.rb +1 -1
  102. data/lib/rdoc/known_classes.rb +5 -4
  103. data/lib/rdoc/markdown/entities.rb +0 -1
  104. data/lib/rdoc/markdown/literals.kpeg +0 -2
  105. data/lib/rdoc/markdown/literals.rb +0 -1
  106. data/lib/rdoc/markdown.kpeg +140 -62
  107. data/lib/rdoc/markdown.rb +1015 -873
  108. data/lib/rdoc/markup/blank_line.rb +25 -24
  109. data/lib/rdoc/markup/block_quote.rb +1 -2
  110. data/lib/rdoc/markup/document.rb +10 -11
  111. data/lib/rdoc/markup/element.rb +21 -0
  112. data/lib/rdoc/markup/formatter.rb +134 -115
  113. data/lib/rdoc/markup/hard_break.rb +30 -28
  114. data/lib/rdoc/markup/heading.rb +163 -72
  115. data/lib/rdoc/markup/include.rb +3 -4
  116. data/lib/rdoc/markup/indented_paragraph.rb +4 -5
  117. data/lib/rdoc/markup/inline_parser.rb +312 -0
  118. data/lib/rdoc/markup/list.rb +6 -7
  119. data/lib/rdoc/markup/list_item.rb +6 -7
  120. data/lib/rdoc/markup/paragraph.rb +2 -3
  121. data/lib/rdoc/markup/parser.rb +29 -19
  122. data/lib/rdoc/markup/pre_process.rb +39 -18
  123. data/lib/rdoc/markup/raw.rb +52 -56
  124. data/lib/rdoc/markup/rule.rb +2 -3
  125. data/lib/rdoc/markup/table.rb +49 -32
  126. data/lib/rdoc/markup/to_ansi.rb +58 -8
  127. data/lib/rdoc/markup/to_bs.rb +47 -38
  128. data/lib/rdoc/markup/to_html.rb +343 -105
  129. data/lib/rdoc/markup/to_html_crossref.rb +143 -58
  130. data/lib/rdoc/markup/to_html_snippet.rb +78 -76
  131. data/lib/rdoc/markup/to_joined_paragraph.rb +3 -9
  132. data/lib/rdoc/markup/to_label.rb +34 -25
  133. data/lib/rdoc/markup/to_markdown.rb +74 -51
  134. data/lib/rdoc/markup/to_rdoc.rb +141 -82
  135. data/lib/rdoc/markup/to_table_of_contents.rb +4 -5
  136. data/lib/rdoc/markup/to_test.rb +10 -3
  137. data/lib/rdoc/markup/to_tt_only.rb +17 -31
  138. data/lib/rdoc/markup/verbatim.rb +5 -6
  139. data/lib/rdoc/markup.rb +59 -707
  140. data/lib/rdoc/options.rb +228 -101
  141. data/lib/rdoc/parser/c.rb +186 -184
  142. data/lib/rdoc/parser/changelog.rb +57 -13
  143. data/lib/rdoc/parser/markdown.rb +0 -2
  144. data/lib/rdoc/parser/rbs.rb +275 -0
  145. data/lib/rdoc/parser/rd.rb +0 -1
  146. data/lib/rdoc/parser/ruby.rb +963 -2024
  147. data/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  148. data/lib/rdoc/parser/simple.rb +6 -23
  149. data/lib/rdoc/parser/text.rb +0 -1
  150. data/lib/rdoc/parser.rb +35 -14
  151. data/lib/rdoc/rbs_helper.rb +186 -0
  152. data/lib/rdoc/rd/block_parser.rb +659 -11
  153. data/lib/rdoc/rd/block_parser.ry +13 -9
  154. data/lib/rdoc/rd/inline.rb +4 -5
  155. data/lib/rdoc/rd/inline_parser.rb +646 -2
  156. data/lib/rdoc/rd.rb +4 -5
  157. data/lib/rdoc/rdoc.rb +234 -90
  158. data/lib/rdoc/ri/driver.rb +172 -172
  159. data/lib/rdoc/ri/paths.rb +3 -3
  160. data/lib/rdoc/{servlet.rb → ri/servlet.rb} +28 -27
  161. data/lib/rdoc/ri/store.rb +0 -1
  162. data/lib/rdoc/ri/task.rb +3 -3
  163. data/lib/rdoc/ri.rb +5 -5
  164. data/lib/rdoc/rubygems_hook.rb +106 -25
  165. data/lib/rdoc/server.rb +460 -0
  166. data/lib/rdoc/stats/normal.rb +1 -1
  167. data/lib/rdoc/stats/quiet.rb +1 -2
  168. data/lib/rdoc/stats/verbose.rb +3 -5
  169. data/lib/rdoc/stats.rb +158 -136
  170. data/lib/rdoc/store.rb +267 -48
  171. data/lib/rdoc/task.rb +54 -28
  172. data/lib/rdoc/text.rb +60 -120
  173. data/lib/rdoc/token_stream.rb +30 -45
  174. data/lib/rdoc/tom_doc.rb +9 -15
  175. data/lib/rdoc/version.rb +3 -1
  176. data/lib/rdoc.rb +90 -52
  177. data/lib/rubygems_plugin.rb +14 -0
  178. data/man/ri.1 +2 -0
  179. data/rdoc-logo.svg +43 -0
  180. data/rdoc.gemspec +25 -200
  181. metadata +120 -53
  182. data/CONTRIBUTING.rdoc +0 -220
  183. data/ExampleMarkdown.md +0 -37
  184. data/ExampleRDoc.rdoc +0 -208
  185. data/Gemfile +0 -12
  186. data/README.rdoc +0 -129
  187. data/RI.rdoc +0 -57
  188. data/Rakefile +0 -101
  189. data/bin/console +0 -7
  190. data/bin/setup +0 -6
  191. data/lib/rdoc/anon_class.rb +0 -11
  192. data/lib/rdoc/context/section.rb +0 -232
  193. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  194. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  195. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  196. data/lib/rdoc/generator/template/json_index/.document +0 -1
  197. data/lib/rdoc/ghost_method.rb +0 -7
  198. data/lib/rdoc/markup/attr_changer.rb +0 -23
  199. data/lib/rdoc/markup/attr_span.rb +0 -36
  200. data/lib/rdoc/markup/attribute_manager.rb +0 -409
  201. data/lib/rdoc/markup/attributes.rb +0 -71
  202. data/lib/rdoc/markup/regexp_handling.rb +0 -41
  203. data/lib/rdoc/meta_method.rb +0 -7
  204. data/lib/rdoc/parser/ripper_state_lex.rb +0 -590
  205. data/lib/rdoc/parser/ruby_tools.rb +0 -167
@@ -30,12 +30,23 @@ class RDoc::ClassModule < RDoc::Context
30
30
  attr_accessor :constant_aliases
31
31
 
32
32
  ##
33
- # Comment and the location it came from. Use #add_comment to add comments
33
+ # A hash of <tt>{ location => [comments] }</tt> documenting this class/module.
34
+ # Use #add_comment to add comments.
35
+ #
36
+ # Ruby hashes maintain insertion order, so comments render in the order
37
+ # they were first added. Each location maps to an array of comments,
38
+ # allowing a class reopened in the same file to accumulate multiple comments.
39
+ #
40
+ # Before marshalling:
41
+ # - +location+ is an RDoc::TopLevel
42
+ # - +comments+ are Strings
43
+ #
44
+ # After unmarshalling:
45
+ # - +location+ is a filename String
46
+ # - +comments+ are RDoc::Markup::Documents
34
47
 
35
48
  attr_accessor :comment_location
36
49
 
37
- attr_accessor :diagram # :nodoc:
38
-
39
50
  ##
40
51
  # Class or module this constant is an alias for
41
52
 
@@ -47,16 +58,15 @@ class RDoc::ClassModule < RDoc::Context
47
58
  #--
48
59
  # TODO move to RDoc::NormalClass (I think)
49
60
 
50
- def self.from_module class_type, mod
61
+ def self.from_module(class_type, mod)
51
62
  klass = class_type.new mod.name
52
63
 
53
- mod.comment_location.each do |comment, location|
54
- klass.add_comment comment, location
64
+ mod.comment_location.each do |location, comments|
65
+ comments.each { |comment| klass.add_comment comment, location }
55
66
  end
56
67
 
57
68
  klass.parent = mod.parent
58
69
  klass.section = mod.section
59
- klass.viewer = mod.viewer
60
70
 
61
71
  klass.attributes.concat mod.attributes
62
72
  klass.method_list.concat mod.method_list
@@ -110,11 +120,10 @@ class RDoc::ClassModule < RDoc::Context
110
120
 
111
121
  def initialize(name, superclass = nil)
112
122
  @constant_aliases = []
113
- @diagram = nil
114
123
  @is_alias_for = nil
115
124
  @name = name
116
125
  @superclass = superclass
117
- @comment_location = [] # [[comment, location]]
126
+ @comment_location = {} # Hash of { location => [comments] }
118
127
 
119
128
  super()
120
129
  end
@@ -124,7 +133,7 @@ class RDoc::ClassModule < RDoc::Context
124
133
  # method is preferred over #comment= since it allows ri data to be updated
125
134
  # across multiple runs.
126
135
 
127
- def add_comment comment, location
136
+ def add_comment(comment, location)
128
137
  return unless document_self
129
138
 
130
139
  original = comment
@@ -136,16 +145,12 @@ class RDoc::ClassModule < RDoc::Context
136
145
  normalize_comment comment
137
146
  end
138
147
 
139
- if location.parser == RDoc::Parser::C
140
- @comment_location.delete_if { |(_, l)| l == location }
141
- end
142
-
143
- @comment_location << [comment, location]
148
+ (@comment_location[location] ||= []) << comment
144
149
 
145
150
  self.comment = original
146
151
  end
147
152
 
148
- def add_things my_things, other_things # :nodoc:
153
+ def add_things(my_things, other_things) # :nodoc:
149
154
  other_things.each do |group, things|
150
155
  my_things[group].each { |thing| yield false, thing } if
151
156
  my_things.include? group
@@ -177,10 +182,26 @@ class RDoc::ClassModule < RDoc::Context
177
182
  end
178
183
 
179
184
  ##
180
- # HTML fragment reference for this module or class. See
181
- # RDoc::NormalClass#aref and RDoc::NormalModule#aref
185
+ # HTML fragment reference for this module or class using GitHub-style
186
+ # anchor format (lowercase, :: replaced with -).
187
+ #
188
+ # Examples:
189
+ # Foo -> class-foo
190
+ # Foo::Bar -> class-foo-bar
182
191
 
183
192
  def aref
193
+ "#{aref_prefix}-#{full_name.downcase.gsub('::', '-')}"
194
+ end
195
+
196
+ ##
197
+ # Legacy HTML fragment reference for backward compatibility.
198
+ # Returns the old RDoc-style anchor format.
199
+ #
200
+ # Examples:
201
+ # Foo -> class-Foo
202
+ # Foo::Bar -> class-Foo::Bar
203
+
204
+ def legacy_aref
184
205
  "#{aref_prefix}-#{full_name}"
185
206
  end
186
207
 
@@ -202,7 +223,7 @@ class RDoc::ClassModule < RDoc::Context
202
223
  # Appends +comment+ to the current comment, but separated by a rule. Works
203
224
  # more like <tt>+=</tt>.
204
225
 
205
- def comment= comment # :nodoc:
226
+ def comment=(comment) # :nodoc:
206
227
  comment = case comment
207
228
  when RDoc::Comment then
208
229
  comment.normalize
@@ -220,10 +241,12 @@ class RDoc::ClassModule < RDoc::Context
220
241
  #
221
242
  # See RDoc::Store#complete
222
243
 
223
- def complete min_visibility
244
+ def complete(min_visibility)
224
245
  update_aliases
225
246
  remove_nodoc_children
247
+ embed_mixins
226
248
  update_includes
249
+ update_extends
227
250
  remove_invisible min_visibility
228
251
  end
229
252
 
@@ -241,7 +264,7 @@ class RDoc::ClassModule < RDoc::Context
241
264
  def documented?
242
265
  return true if @received_nodoc
243
266
  return false if @comment_location.empty?
244
- @comment_location.any? { |comment, _| not comment.empty? }
267
+ @comment_location.each_value.any? { |comments| comments.any? { |c| not c.empty? } }
245
268
  end
246
269
 
247
270
  ##
@@ -261,7 +284,7 @@ class RDoc::ClassModule < RDoc::Context
261
284
  ##
262
285
  # Looks for a symbol in the #ancestors. See Context#find_local_symbol.
263
286
 
264
- def find_ancestor_local_symbol symbol
287
+ def find_ancestor_local_symbol(symbol)
265
288
  each_ancestor do |m|
266
289
  res = m.find_local_symbol(symbol)
267
290
  return res if res
@@ -273,7 +296,7 @@ class RDoc::ClassModule < RDoc::Context
273
296
  ##
274
297
  # Finds a class or module with +name+ in this namespace or its descendants
275
298
 
276
- def find_class_named name
299
+ def find_class_named(name)
277
300
  return self if full_name == name
278
301
  return self if @name == name
279
302
 
@@ -294,6 +317,25 @@ class RDoc::ClassModule < RDoc::Context
294
317
  end
295
318
  end
296
319
 
320
+ ##
321
+ # Return array of full_name splitted by +::+.
322
+
323
+ def nesting_namespaces
324
+ @namespaces ||= full_name.split("::").reject(&:empty?)
325
+ end
326
+
327
+ ##
328
+ # Return array of fully qualified nesting namespaces.
329
+ #
330
+ # For example, if full_name is +A::B::C+, this method returns <code>["A", "A::B", "A::B::C"]</code>
331
+
332
+ def fully_qualified_nesting_namespaces
333
+ return nesting_namespaces if nesting_namespaces.length < 2
334
+ @fqns ||= nesting_namespaces.inject([]) do |list, n|
335
+ list << (list.empty? ? n : "#{list.last}::#{n}")
336
+ end
337
+ end
338
+
297
339
  ##
298
340
  # TODO: filter included items by #display?
299
341
 
@@ -343,7 +385,7 @@ class RDoc::ClassModule < RDoc::Context
343
385
  ]
344
386
  end
345
387
 
346
- def marshal_load array # :nodoc:
388
+ def marshal_load(array) # :nodoc:
347
389
  initialize_visibility
348
390
  initialize_methods_etc
349
391
  @current_section = nil
@@ -358,37 +400,39 @@ class RDoc::ClassModule < RDoc::Context
358
400
  @name = array[1]
359
401
  @full_name = array[2]
360
402
  @superclass = array[3]
361
- @comment = array[4]
403
+ document = array[4]
362
404
 
363
- @comment_location = if RDoc::Markup::Document === @comment.parts.first then
364
- @comment
405
+ @comment = RDoc::Comment.from_document document
406
+
407
+ @comment_location = if document.parts.first.is_a?(RDoc::Markup::Document)
408
+ document.parts.group_by(&:file)
365
409
  else
366
- RDoc::Markup::Document.new @comment
410
+ { document.file => [document] }
367
411
  end
368
412
 
369
413
  array[5].each do |name, rw, visibility, singleton, file|
370
414
  singleton ||= false
371
415
  visibility ||= :public
372
416
 
373
- attr = RDoc::Attr.new nil, name, rw, nil, singleton
417
+ attr = RDoc::Attr.new name, rw, nil, singleton: singleton
374
418
 
375
419
  add_attribute attr
376
420
  attr.visibility = visibility
377
421
  attr.record_location RDoc::TopLevel.new file
378
422
  end
379
423
 
380
- array[6].each do |constant, comment, file|
424
+ array[6].each do |constant, document, file|
381
425
  case constant
382
426
  when RDoc::Constant then
383
427
  add_constant constant
384
428
  else
385
- constant = add_constant RDoc::Constant.new(constant, nil, comment)
429
+ constant = add_constant RDoc::Constant.new(constant, nil, RDoc::Comment.from_document(document))
386
430
  constant.record_location RDoc::TopLevel.new file
387
431
  end
388
432
  end
389
433
 
390
- array[7].each do |name, comment, file|
391
- incl = add_include RDoc::Include.new(name, comment)
434
+ array[7].each do |name, document, file|
435
+ incl = add_include RDoc::Include.new(name, RDoc::Comment.from_document(document))
392
436
  incl.record_location RDoc::TopLevel.new file
393
437
  end
394
438
 
@@ -397,16 +441,15 @@ class RDoc::ClassModule < RDoc::Context
397
441
  @visibility = visibility
398
442
 
399
443
  methods.each do |name, file|
400
- method = RDoc::AnyMethod.new nil, name
401
- method.singleton = true if type == 'class'
444
+ method = RDoc::AnyMethod.new name, singleton: type == 'class'
402
445
  method.record_location RDoc::TopLevel.new file
403
446
  add_method method
404
447
  end
405
448
  end
406
449
  end
407
450
 
408
- array[9].each do |name, comment, file|
409
- ext = add_extend RDoc::Extend.new(name, comment)
451
+ array[9].each do |name, document, file|
452
+ ext = add_extend RDoc::Extend.new(name, RDoc::Comment.from_document(document))
410
453
  ext.record_location RDoc::TopLevel.new file
411
454
  end if array[9] # Support Marshal version 1
412
455
 
@@ -432,7 +475,7 @@ class RDoc::ClassModule < RDoc::Context
432
475
  #
433
476
  # The data in +class_module+ is preferred over the receiver.
434
477
 
435
- def merge class_module
478
+ def merge(class_module)
436
479
  @parent = class_module.parent
437
480
  @parent_name = class_module.parent_name
438
481
 
@@ -443,7 +486,13 @@ class RDoc::ClassModule < RDoc::Context
443
486
 
444
487
  document = document.merge other_document
445
488
 
446
- @comment = @comment_location = document
489
+ @comment = RDoc::Comment.from_document(document)
490
+
491
+ @comment_location = if document.parts.first.is_a?(RDoc::Markup::Document)
492
+ document.parts.group_by(&:file)
493
+ else
494
+ { document.file => [document] }
495
+ end
447
496
  end
448
497
 
449
498
  cm = class_module
@@ -516,7 +565,7 @@ class RDoc::ClassModule < RDoc::Context
516
565
  # end
517
566
  # end
518
567
 
519
- def merge_collections mine, other, other_files, &block # :nodoc:
568
+ def merge_collections(mine, other, other_files, &block) # :nodoc:
520
569
  my_things = mine. group_by { |thing| thing.file }
521
570
  other_things = other.group_by { |thing| thing.file }
522
571
 
@@ -528,7 +577,7 @@ class RDoc::ClassModule < RDoc::Context
528
577
  # Merges the comments in this ClassModule with the comments in the other
529
578
  # ClassModule +cm+.
530
579
 
531
- def merge_sections cm # :nodoc:
580
+ def merge_sections(cm) # :nodoc:
532
581
  my_sections = sections.group_by { |section| section.title }
533
582
  other_sections = cm.sections.group_by { |section| section.title }
534
583
 
@@ -576,7 +625,7 @@ class RDoc::ClassModule < RDoc::Context
576
625
  #
577
626
  # Used for modules and classes that are constant aliases.
578
627
 
579
- def name= new_name
628
+ def name=(new_name)
580
629
  @name = new_name
581
630
  end
582
631
 
@@ -584,15 +633,17 @@ class RDoc::ClassModule < RDoc::Context
584
633
  # Parses +comment_location+ into an RDoc::Markup::Document composed of
585
634
  # multiple RDoc::Markup::Documents with their file set.
586
635
 
587
- def parse comment_location
636
+ def parse(comment_location)
588
637
  case comment_location
589
638
  when String then
590
639
  super
591
- when Array then
592
- docs = comment_location.map do |comment, location|
593
- doc = super comment
594
- doc.file = location
595
- doc
640
+ when Hash then
641
+ docs = comment_location.flat_map do |location, comments|
642
+ comments.map do |comment|
643
+ doc = super comment
644
+ doc.file = location
645
+ doc
646
+ end
596
647
  end
597
648
 
598
649
  RDoc::Markup::Document.new(*docs)
@@ -611,7 +662,9 @@ class RDoc::ClassModule < RDoc::Context
611
662
  # Path to this class or module for use with HTML generator output.
612
663
 
613
664
  def path
614
- http_url @store.rdoc.generator.class_dir
665
+ prefix = options.class_module_path_prefix
666
+ return http_url unless prefix
667
+ File.join(prefix, http_url)
615
668
  end
616
669
 
617
670
  ##
@@ -620,7 +673,7 @@ class RDoc::ClassModule < RDoc::Context
620
673
  # module or class return the name of the latter.
621
674
 
622
675
  def name_for_path
623
- is_alias_for ? is_alias_for.full_name : full_name
676
+ is_alias_for ? is_alias_for.name_for_path : full_name
624
677
  end
625
678
 
626
679
  ##
@@ -654,7 +707,7 @@ class RDoc::ClassModule < RDoc::Context
654
707
  end
655
708
  end
656
709
 
657
- def remove_things my_things, other_files # :nodoc:
710
+ def remove_things(my_things, other_files) # :nodoc:
658
711
  my_things.delete_if do |file, things|
659
712
  next false unless other_files.include? file
660
713
 
@@ -668,6 +721,9 @@ class RDoc::ClassModule < RDoc::Context
668
721
 
669
722
  ##
670
723
  # Search record used by RDoc::Generator::JsonIndex
724
+ #
725
+ # TODO: Remove this method after dropping the darkfish theme and JsonIndex generator.
726
+ # Use #search_snippet instead for getting documentation snippets.
671
727
 
672
728
  def search_record
673
729
  [
@@ -681,10 +737,32 @@ class RDoc::ClassModule < RDoc::Context
681
737
  ]
682
738
  end
683
739
 
740
+ ##
741
+ # Returns an HTML snippet of the first comment for search results.
742
+
743
+ def search_snippet
744
+ first_comment = @comment_location.each_value.first&.first
745
+ return '' unless first_comment && !first_comment.empty?
746
+
747
+ snippet(first_comment)
748
+ end
749
+
750
+ ##
751
+ # Rebuilds +@comment+ from the current +@comment_location+ entries,
752
+ # skipping any empty placeholders.
753
+
754
+ def rebuild_comment_from_location
755
+ texts = @comment_location.each_value.flat_map { |comments|
756
+ comments.filter_map { |c| c.to_s unless c.empty? }
757
+ }
758
+ merged = texts.join("\n---\n")
759
+ @comment = merged.empty? ? '' : RDoc::Comment.new(merged)
760
+ end
761
+
684
762
  ##
685
763
  # Sets the store for this class or module and its contained code objects.
686
764
 
687
- def store= store
765
+ def store=(store)
688
766
  super
689
767
 
690
768
  @attributes .each do |attr| attr.store = store end
@@ -704,10 +782,37 @@ class RDoc::ClassModule < RDoc::Context
704
782
 
705
783
  ##
706
784
  # Set the superclass of this class to +superclass+
785
+ #
786
+ # where +superclass+ is one of:
787
+ #
788
+ # - +nil+
789
+ # - a String containing the full name of the superclass
790
+ # - the RDoc::ClassModule representing the superclass
707
791
 
708
792
  def superclass=(superclass)
709
793
  raise NoMethodError, "#{full_name} is a module" if module?
710
- @superclass = superclass
794
+ case superclass
795
+ when RDoc::ClassModule
796
+ @superclass = superclass.full_name
797
+ when nil, String
798
+ @superclass = superclass
799
+ else
800
+ raise TypeError, "superclass must be a String or RDoc::ClassModule, not #{superclass.class}"
801
+ end
802
+ end
803
+
804
+ ##
805
+ # Get all super classes of this class in an array. The last element might be
806
+ # a string if the name is unknown.
807
+
808
+ def super_classes
809
+ result = []
810
+ parent = self
811
+ while parent = parent.superclass
812
+ result << parent
813
+ return result if parent.is_a?(String)
814
+ end
815
+ result
711
816
  end
712
817
 
713
818
  def to_s # :nodoc:
@@ -742,15 +847,39 @@ class RDoc::ClassModule < RDoc::Context
742
847
 
743
848
  def update_aliases
744
849
  constants.each do |const|
745
- next unless cm = const.is_alias_for
850
+ cm = const.is_alias_for
851
+ cm ||= const.resolved_alias_target if const.is_a?(RDoc::Constant)
852
+ next unless cm
853
+
854
+ # Resolve chained aliases (A = B = C) to the real class/module.
855
+ cm = @store.find_class_or_module(cm.full_name) || cm
856
+ while (target = cm.is_alias_for)
857
+ cm = target
858
+ end
859
+
746
860
  cm_alias = cm.dup
747
861
  cm_alias.name = const.name
748
862
 
749
- # Don't move top-level aliases under Object, they look ugly there
750
- unless RDoc::TopLevel === cm_alias.parent then
863
+ if full_name == 'Object'
864
+ # Don't move top-level aliases under Object, they look ugly there
865
+ cm_alias.parent = top_level
866
+ else
751
867
  cm_alias.parent = self
752
- cm_alias.full_name = nil # force update for new parent
753
868
  end
869
+ cm_alias.full_name = nil # force update for new parent
870
+
871
+ # Don't clobber a real (non-alias) class/module already living at this
872
+ # name. Mirrors the BasicObject = BlankSlate guard in
873
+ # Context#add_module_alias. Existing alias copies (set by
874
+ # add_module_alias or a previous update_aliases pass) carry is_alias_for,
875
+ # so they're still overwritable here.
876
+ existing = @store.find_class_or_module(cm_alias.full_name)
877
+ next if existing && !existing.is_alias_for
878
+
879
+ # Persist a lazy-resolved target so Stats#report_constants and
880
+ # Constant#marshal_dump observe the alias relationship. Skipped
881
+ # aliases (above) intentionally leave the constant unmarked.
882
+ const.is_alias_for ||= cm
754
883
 
755
884
  cm_alias.aliases.clear
756
885
  cm_alias.is_alias_for = cm
@@ -798,5 +927,43 @@ class RDoc::ClassModule < RDoc::Context
798
927
  extends.uniq!
799
928
  end
800
929
 
801
- end
930
+ def embed_mixins
931
+ return unless options.embed_mixins
932
+
933
+ includes.each do |include|
934
+ next if String === include.module
935
+ include.module.method_list.each do |code_object|
936
+ add_method(prepare_to_embed(code_object))
937
+ end
938
+ include.module.constants.each do |code_object|
939
+ add_constant(prepare_to_embed(code_object))
940
+ end
941
+ include.module.attributes.each do |code_object|
942
+ add_attribute(prepare_to_embed(code_object))
943
+ end
944
+ end
802
945
 
946
+ extends.each do |ext|
947
+ next if String === ext.module
948
+ ext.module.method_list.each do |code_object|
949
+ add_method(prepare_to_embed(code_object, true))
950
+ end
951
+ ext.module.attributes.each do |code_object|
952
+ add_attribute(prepare_to_embed(code_object, true))
953
+ end
954
+ end
955
+ end
956
+
957
+ private
958
+
959
+ def prepare_to_embed(code_object, singleton=false)
960
+ code_object = code_object.dup
961
+ code_object.mixin_from = code_object.parent
962
+ code_object.singleton = true if singleton
963
+ set_current_section(code_object.section.title, code_object.section.comment)
964
+ # add_method and add_attribute will reassign self's visibility back to the method/attribute
965
+ # so we need to sync self's visibility with the object's to properly retain that information
966
+ self.visibility = code_object.visibility
967
+ code_object
968
+ end
969
+ end
@@ -26,6 +26,14 @@ class RDoc::Constant < RDoc::CodeObject
26
26
 
27
27
  attr_accessor :visibility
28
28
 
29
+ ##
30
+ # The constant path on the RHS when the RHS is a bare constant reference
31
+ # (+Foo = Bar+ or +Foo = Bar::Baz+). Captured at parse time so
32
+ # #resolved_alias_target doesn't have to re-derive it from the textual
33
+ # #value. nil for other RHS shapes.
34
+
35
+ attr_accessor :is_alias_for_path
36
+
29
37
  ##
30
38
  # Creates a new constant with +name+, +value+ and +comment+
31
39
 
@@ -35,8 +43,9 @@ class RDoc::Constant < RDoc::CodeObject
35
43
  @name = name
36
44
  @value = value
37
45
 
38
- @is_alias_for = nil
39
- @visibility = :public
46
+ @is_alias_for = nil
47
+ @is_alias_for_path = nil
48
+ @visibility = :public
40
49
 
41
50
  self.comment = comment
42
51
  end
@@ -44,7 +53,7 @@ class RDoc::Constant < RDoc::CodeObject
44
53
  ##
45
54
  # Constants are ordered by name
46
55
 
47
- def <=> other
56
+ def <=>(other)
48
57
  return unless self.class === other
49
58
 
50
59
  [parent_name, name] <=> [other.parent_name, other.name]
@@ -53,7 +62,7 @@ class RDoc::Constant < RDoc::CodeObject
53
62
  ##
54
63
  # Constants are equal when their #parent and #name is the same
55
64
 
56
- def == other
65
+ def ==(other)
57
66
  self.class == other.class and
58
67
  @parent == other.parent and
59
68
  @name == other.name
@@ -83,7 +92,10 @@ class RDoc::Constant < RDoc::CodeObject
83
92
  end
84
93
 
85
94
  ##
86
- # The module or class this constant is an alias for
95
+ # The module or class this constant is an alias for, when one was recorded
96
+ # explicitly (by RDoc::Context#add_module_alias, RDoc::ClassModule#update_aliases,
97
+ # or ri marshal load). Pure accessor; see #resolved_alias_target for the
98
+ # opportunistic lookup path.
87
99
 
88
100
  def is_alias_for
89
101
  case @is_alias_for
@@ -96,6 +108,20 @@ class RDoc::Constant < RDoc::CodeObject
96
108
  end
97
109
  end
98
110
 
111
+ ##
112
+ # Returns the class/module this constant *would* alias if #is_alias_for_path
113
+ # was set by the parser and that path resolves to a known class/module, or
114
+ # nil. Used to support `Const = RHS` parsed before `class RHS;end` is defined
115
+ # in another file. Pure lookup; does not mutate state. Honors :nodoc:
116
+ # (returns nil if document_self is false). Note that module nesting
117
+ # information is lost, so constant lookup is inaccurate.
118
+
119
+ def resolved_alias_target
120
+ return nil unless document_self
121
+ return nil unless @is_alias_for_path
122
+ parent.find_module_named(@is_alias_for_path)
123
+ end
124
+
99
125
  def inspect # :nodoc:
100
126
  "#<%s:0x%x %s::%s>" % [
101
127
  self.class, object_id,
@@ -132,8 +158,8 @@ class RDoc::Constant < RDoc::CodeObject
132
158
  # * #full_name
133
159
  # * #parent_name
134
160
 
135
- def marshal_load array
136
- initialize array[1], nil, array[5]
161
+ def marshal_load(array)
162
+ initialize array[1], nil, RDoc::Comment.from_document(array[5])
137
163
 
138
164
  @full_name = array[2]
139
165
  @visibility = array[3] || :public
@@ -154,7 +180,16 @@ class RDoc::Constant < RDoc::CodeObject
154
180
  "#{@parent.path}##{@name}"
155
181
  end
156
182
 
157
- def pretty_print q # :nodoc:
183
+ ##
184
+ # Returns an HTML snippet of the comment for search results.
185
+
186
+ def search_snippet
187
+ return '' if comment.empty?
188
+
189
+ snippet(comment)
190
+ end
191
+
192
+ def pretty_print(q) # :nodoc:
158
193
  q.group 2, "[#{self.class.name} #{full_name}", "]" do
159
194
  unless comment.empty? then
160
195
  q.breakable
@@ -168,7 +203,7 @@ class RDoc::Constant < RDoc::CodeObject
168
203
  ##
169
204
  # Sets the store for this class or module and its contained code objects.
170
205
 
171
- def store= store
206
+ def store=(store)
172
207
  super
173
208
 
174
209
  @file = @store.add_file @file.full_name if @file
@@ -184,4 +219,3 @@ class RDoc::Constant < RDoc::CodeObject
184
219
  end
185
220
 
186
221
  end
187
-