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
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+ require 'cgi/escape'
3
+ require 'cgi/util' unless defined?(CGI::EscapeExt)
4
+
5
+ ##
6
+ # A section of documentation like:
7
+ #
8
+ # # :section: The title
9
+ # # The body
10
+ #
11
+ # Sections can be referenced multiple times and will be collapsed into a
12
+ # single section.
13
+
14
+ class RDoc::Context::Section
15
+
16
+ include RDoc::Text
17
+
18
+ MARSHAL_VERSION = 0 # :nodoc:
19
+
20
+ ##
21
+ # Section comments
22
+
23
+ attr_reader :comments
24
+
25
+ ##
26
+ # Context this Section lives in
27
+
28
+ attr_reader :parent
29
+
30
+ ##
31
+ # Section title
32
+
33
+ attr_reader :title
34
+
35
+ ##
36
+ # The RDoc::Store for this object.
37
+
38
+ attr_reader :store
39
+
40
+ ##
41
+ # Creates a new section with +title+ and +comment+
42
+
43
+ def initialize(parent, title, comment, store = nil)
44
+ @parent = parent
45
+ @title = title ? title.strip : title
46
+ @store = store
47
+
48
+ @comments = []
49
+
50
+ add_comment comment
51
+ end
52
+
53
+ ##
54
+ # Sections are equal when they have the same #title
55
+
56
+ def ==(other)
57
+ self.class === other and @title == other.title
58
+ end
59
+
60
+ alias eql? ==
61
+
62
+ ##
63
+ # Adds +comment+ to this section
64
+
65
+ def add_comment(comment)
66
+ Array(comment).each do |c|
67
+ next if c.nil?
68
+ raise TypeError, "unknown comment #{c.inspect}" unless RDoc::Comment === c
69
+ @comments << c unless c.empty?
70
+ end
71
+ end
72
+
73
+ ##
74
+ # Anchor reference for linking to this section using GitHub-style format.
75
+ #
76
+ # Examples:
77
+ # "Section" -> "section"
78
+ # "One Two" -> "one-two"
79
+ # "[untitled]" -> "untitled"
80
+
81
+ def aref
82
+ title = @title || '[untitled]'
83
+
84
+ RDoc::Text.to_anchor(title)
85
+ end
86
+
87
+ ##
88
+ # Legacy anchor reference for backward compatibility.
89
+ #
90
+ # Examples:
91
+ # "Section" -> "section"
92
+ # "One Two" -> "one+two"
93
+ # "[untitled]" -> "5Buntitled-5D"
94
+
95
+ def legacy_aref
96
+ title = @title || '[untitled]'
97
+
98
+ CGI.escape(title).gsub('%', '-').sub(/^-/, '')
99
+ end
100
+
101
+ def inspect # :nodoc:
102
+ "#<%s:0x%x %p>" % [self.class, object_id, title]
103
+ end
104
+
105
+ def hash # :nodoc:
106
+ @title.hash
107
+ end
108
+
109
+ ##
110
+ # The files comments in this section come from
111
+
112
+ def in_files
113
+ @comments.map(&:file)
114
+ end
115
+
116
+ ##
117
+ # Serializes this Section. The title and parsed comment are saved, but not
118
+ # the section parent which must be restored manually.
119
+
120
+ def marshal_dump
121
+ [
122
+ MARSHAL_VERSION,
123
+ @title,
124
+ to_document,
125
+ ]
126
+ end
127
+
128
+ ##
129
+ # De-serializes this Section. The section parent must be restored manually.
130
+
131
+ def marshal_load(array)
132
+ @parent = nil
133
+
134
+ @title = array[1]
135
+ @comments = array[2].parts.map { |doc| RDoc::Comment.from_document(doc) }
136
+ end
137
+
138
+ ##
139
+ # Parses +comment_location+ into an RDoc::Markup::Document composed of
140
+ # multiple RDoc::Markup::Documents with their file set.
141
+
142
+ def to_document
143
+ RDoc::Markup::Document.new(*@comments.map(&:parse))
144
+ end
145
+
146
+ ##
147
+ # The section's title, or 'Top Section' if the title is nil.
148
+ #
149
+ # This is used by the table of contents template so the name is silly.
150
+
151
+ def plain_html
152
+ @title || 'Top Section'
153
+ end
154
+
155
+ ##
156
+ # Section comment
157
+
158
+ def comment
159
+ return nil if @comments.empty?
160
+ RDoc::Comment.from_document(to_document)
161
+ end
162
+
163
+ def description
164
+ return '' if @comments.empty?
165
+ markup comment
166
+ end
167
+
168
+ def language
169
+ @comments.first&.language
170
+ end
171
+
172
+ ##
173
+ # Removes a comment from this section if it is from the same file as
174
+ # +comment+
175
+
176
+ def remove_comment(target_comment)
177
+ @comments.delete_if do |stored_comment|
178
+ stored_comment.file == target_comment.file
179
+ end
180
+ end
181
+
182
+ end
@@ -1,6 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'cgi'
3
-
4
2
  ##
5
3
  # A Context is something that can hold modules, classes, methods, attributes,
6
4
  # aliases, requires, and includes. Classes, modules, and files are all
@@ -182,7 +180,7 @@ class RDoc::Context < RDoc::CodeObject
182
180
  #
183
181
  # Currently only RDoc::Extend and RDoc::Include are supported.
184
182
 
185
- def add klass, name, comment
183
+ def add(klass, name, comment)
186
184
  if RDoc::Extend == klass then
187
185
  ext = RDoc::Extend.new name, comment
188
186
  add_extend ext
@@ -197,7 +195,7 @@ class RDoc::Context < RDoc::CodeObject
197
195
  ##
198
196
  # Adds +an_alias+ that is automatically resolved
199
197
 
200
- def add_alias an_alias
198
+ def add_alias(an_alias)
201
199
  return an_alias unless @document_self
202
200
 
203
201
  method_attr = find_method(an_alias.old_name, an_alias.singleton) ||
@@ -224,7 +222,7 @@ class RDoc::Context < RDoc::CodeObject
224
222
  # if method +foo+ exists, but <tt>attr_accessor :foo</tt> will be registered
225
223
  # if method +foo+ exists, but <tt>foo=</tt> does not.
226
224
 
227
- def add_attribute attribute
225
+ def add_attribute(attribute)
228
226
  return attribute unless @document_self
229
227
 
230
228
  # mainly to check for redefinition of an attribute as a method
@@ -287,7 +285,7 @@ class RDoc::Context < RDoc::CodeObject
287
285
  # unless it later sees <tt>class Container</tt>. +add_class+ automatically
288
286
  # upgrades +given_name+ to a class in this case.
289
287
 
290
- def add_class class_type, given_name, superclass = '::Object'
288
+ def add_class(class_type, given_name, superclass = '::Object')
291
289
  # superclass +nil+ is passed by the C parser in the following cases:
292
290
  # - registering Object in 1.8 (correct)
293
291
  # - registering BasicObject in 1.9 (correct)
@@ -315,13 +313,7 @@ class RDoc::Context < RDoc::CodeObject
315
313
  @store.modules_hash[given_name]
316
314
  return enclosing if enclosing
317
315
  # not found: create the parent(s)
318
- names = ename.split('::')
319
- enclosing = self
320
- names.each do |n|
321
- enclosing = enclosing.classes_hash[n] ||
322
- enclosing.modules_hash[n] ||
323
- enclosing.add_module(RDoc::NormalModule, n)
324
- end
316
+ enclosing = find_or_create_namespace_path ename
325
317
  end
326
318
  else
327
319
  name = full_name
@@ -403,7 +395,7 @@ class RDoc::Context < RDoc::CodeObject
403
395
  # unless #done_documenting is +true+. Sets the #parent of +mod+
404
396
  # to +self+, and its #section to #current_section. Returns +mod+.
405
397
 
406
- def add_class_or_module mod, self_hash, all_hash
398
+ def add_class_or_module(mod, self_hash, all_hash)
407
399
  mod.section = current_section # TODO declaring context? something is
408
400
  # wrong here...
409
401
  mod.parent = self
@@ -428,7 +420,7 @@ class RDoc::Context < RDoc::CodeObject
428
420
  # Adds +constant+ if not already there. If it is, updates the comment,
429
421
  # value and/or is_alias_for of the known constant if they were empty/nil.
430
422
 
431
- def add_constant constant
423
+ def add_constant(constant)
432
424
  return constant unless @document_self
433
425
 
434
426
  # HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
@@ -441,6 +433,7 @@ class RDoc::Context < RDoc::CodeObject
441
433
  known.value = constant.value if
442
434
  known.value.nil? or known.value.strip.empty?
443
435
 
436
+ constant.parent = self
444
437
  known.is_alias_for ||= constant.is_alias_for
445
438
  else
446
439
  @constants_hash[constant.name] = constant
@@ -453,7 +446,7 @@ class RDoc::Context < RDoc::CodeObject
453
446
  ##
454
447
  # Adds included module +include+ which should be an RDoc::Include
455
448
 
456
- def add_include include
449
+ def add_include(include)
457
450
  add_to @includes, include
458
451
 
459
452
  include
@@ -462,7 +455,7 @@ class RDoc::Context < RDoc::CodeObject
462
455
  ##
463
456
  # Adds extension module +ext+ which should be an RDoc::Extend
464
457
 
465
- def add_extend ext
458
+ def add_extend(ext)
466
459
  add_to @extends, ext
467
460
 
468
461
  ext
@@ -472,7 +465,7 @@ class RDoc::Context < RDoc::CodeObject
472
465
  # Adds +method+ if not already there. If it is (as method or attribute),
473
466
  # updates the comment if it was empty.
474
467
 
475
- def add_method method
468
+ def add_method(method)
476
469
  return method unless @document_self
477
470
 
478
471
  # HACK: avoid duplicate 'new' in io.c & struct.c (1.8.7 source code)
@@ -484,7 +477,7 @@ class RDoc::Context < RDoc::CodeObject
484
477
  known.comment = method.comment if known.comment.empty?
485
478
  previously = ", previously in #{known.file}" unless
486
479
  method.file == known.file
487
- @store.rdoc.options.warn \
480
+ @store.options.warn \
488
481
  "Duplicate method #{known.full_name} in #{method.file}#{previously}"
489
482
  end
490
483
  else
@@ -501,11 +494,44 @@ class RDoc::Context < RDoc::CodeObject
501
494
  method
502
495
  end
503
496
 
497
+ ##
498
+ # Returns the owner context and local name for +constant_path+, creating
499
+ # missing namespace modules. A leading +::+ resolves from the top-level.
500
+ # This only resolves explicit context-tree paths; RDoc::Parser::Ruby has
501
+ # parser-local lexical helpers for Ruby's nesting-dependent lookup.
502
+
503
+ def find_or_create_constant_owner_for_path(constant_path) # :nodoc:
504
+ constant_path = constant_path.to_s
505
+ owner = constant_path.start_with?('::') ? top_level : self
506
+ constant_path = constant_path.delete_prefix('::')
507
+
508
+ owner_path, separator, name = constant_path.rpartition('::')
509
+ owner = owner.find_or_create_namespace_path owner_path unless separator.empty?
510
+
511
+ [owner, name]
512
+ end
513
+
514
+ ##
515
+ # Finds or creates the module namespace path under this context.
516
+
517
+ def find_or_create_namespace_path(path) # :nodoc:
518
+ path.to_s.split('::').inject(self) do |owner, name|
519
+ owner.classes_hash[name] ||
520
+ owner.modules_hash[name] ||
521
+ owner.add_module(RDoc::NormalModule, name)
522
+ end
523
+ end
524
+
504
525
  ##
505
526
  # Adds a module named +name+. If RDoc already knows +name+ is a class then
506
527
  # that class is returned instead. See also #add_class.
507
528
 
508
529
  def add_module(class_type, name)
530
+ if name.to_s.include?('::')
531
+ owner, name = find_or_create_constant_owner_for_path name
532
+ return owner.add_module class_type, name unless owner == self
533
+ end
534
+
509
535
  mod = @classes[name] || @modules[name]
510
536
  return mod if mod
511
537
 
@@ -526,7 +552,7 @@ class RDoc::Context < RDoc::CodeObject
526
552
  # Adds an alias from +from+ (a class or module) to +name+ which was defined
527
553
  # in +file+.
528
554
 
529
- def add_module_alias from, from_name, to, file
555
+ def add_module_alias(from, from_name, to, file)
530
556
  return from if @done_documenting
531
557
 
532
558
  to_full_name = child_name to.name
@@ -545,6 +571,7 @@ class RDoc::Context < RDoc::CodeObject
545
571
  new_to = from.dup
546
572
  new_to.name = to.name
547
573
  new_to.full_name = nil
574
+ new_to.is_alias_for = from
548
575
 
549
576
  if new_to.module? then
550
577
  @store.modules_hash[to_full_name] = new_to
@@ -585,11 +612,11 @@ class RDoc::Context < RDoc::CodeObject
585
612
  #
586
613
  # See also RDoc::Context::Section
587
614
 
588
- def add_section title, comment = nil
615
+ def add_section(title, comment = nil)
589
616
  if section = @sections[title] then
590
617
  section.add_comment comment if comment
591
618
  else
592
- section = Section.new self, title, comment
619
+ section = Section.new self, title, comment, @store
593
620
  @sections[title] = section
594
621
  end
595
622
 
@@ -599,7 +626,7 @@ class RDoc::Context < RDoc::CodeObject
599
626
  ##
600
627
  # Adds +thing+ to the collection +array+
601
628
 
602
- def add_to array, thing
629
+ def add_to(array, thing)
603
630
  array << thing if @document_self
604
631
 
605
632
  thing.parent = self
@@ -631,7 +658,7 @@ class RDoc::Context < RDoc::CodeObject
631
658
  ##
632
659
  # Creates the full name for a child with +name+
633
660
 
634
- def child_name name
661
+ def child_name(name)
635
662
  if name =~ /^:+/
636
663
  $' #'
637
664
  elsif RDoc::TopLevel === self then
@@ -641,18 +668,11 @@ class RDoc::Context < RDoc::CodeObject
641
668
  end
642
669
  end
643
670
 
644
- ##
645
- # Class attributes
646
-
647
- def class_attributes
648
- @class_attributes ||= attributes.select { |a| a.singleton }
649
- end
650
-
651
671
  ##
652
672
  # Class methods
653
673
 
654
674
  def class_method_list
655
- @class_method_list ||= method_list.select { |a| a.singleton }
675
+ method_list.select { |a| a.singleton }
656
676
  end
657
677
 
658
678
  ##
@@ -690,13 +710,6 @@ class RDoc::Context < RDoc::CodeObject
690
710
  section
691
711
  end
692
712
 
693
- ##
694
- # Is part of this thing was defined in +file+?
695
-
696
- def defined_in?(file)
697
- @in_files.include?(file)
698
- end
699
-
700
713
  def display(method_attr) # :nodoc:
701
714
  if method_attr.is_a? RDoc::Attr
702
715
  "#{method_attr.definition} #{method_attr.pretty_name}"
@@ -712,14 +725,7 @@ class RDoc::Context < RDoc::CodeObject
712
725
  # This method exists to make it easy to work with Context subclasses that
713
726
  # aren't part of RDoc.
714
727
 
715
- def each_ancestor # :nodoc:
716
- end
717
-
718
- ##
719
- # Iterator for attributes
720
-
721
- def each_attribute # :yields: attribute
722
- @attributes.each { |a| yield a }
728
+ def each_ancestor(&_) # :nodoc:
723
729
  end
724
730
 
725
731
  ##
@@ -729,27 +735,6 @@ class RDoc::Context < RDoc::CodeObject
729
735
  classes_and_modules.sort.each(&block)
730
736
  end
731
737
 
732
- ##
733
- # Iterator for constants
734
-
735
- def each_constant # :yields: constant
736
- @constants.each {|c| yield c}
737
- end
738
-
739
- ##
740
- # Iterator for included modules
741
-
742
- def each_include # :yields: include
743
- @includes.each do |i| yield i end
744
- end
745
-
746
- ##
747
- # Iterator for extension modules
748
-
749
- def each_extend # :yields: extend
750
- @extends.each do |e| yield e end
751
- end
752
-
753
738
  ##
754
739
  # Iterator for methods
755
740
 
@@ -822,7 +807,10 @@ class RDoc::Context < RDoc::CodeObject
822
807
  end
823
808
 
824
809
  ##
825
- # Find a module at a higher scope
810
+ # Tries to find a module at a higher scope.
811
+ # But parent is not always a higher module nesting scope, so the result is not correct.
812
+ # Parent chain can only represent last-opened nesting, and may be broken in some cases.
813
+ # The Ruby parser does not represent module nesting with the parent chain.
826
814
 
827
815
  def find_enclosing_module_named(name)
828
816
  parent && parent.find_module_named(name)
@@ -849,13 +837,6 @@ class RDoc::Context < RDoc::CodeObject
849
837
  end
850
838
  end
851
839
 
852
- ##
853
- # Finds a file with +name+ in this context
854
-
855
- def find_file_named name
856
- @store.find_file_named name
857
- end
858
-
859
840
  ##
860
841
  # Finds an instance method with +name+ in this context
861
842
 
@@ -873,7 +854,7 @@ class RDoc::Context < RDoc::CodeObject
873
854
  find_attribute_named(symbol) or
874
855
  find_external_alias_named(symbol) or
875
856
  find_module_named(symbol) or
876
- find_file_named(symbol)
857
+ @store.find_file_named(symbol)
877
858
  end
878
859
 
879
860
  ##
@@ -904,15 +885,23 @@ class RDoc::Context < RDoc::CodeObject
904
885
  end
905
886
 
906
887
  ##
907
- # Find a module with +name+ using ruby's scoping rules
888
+ # Find a module with +name+ trying to using ruby's scoping rules.
889
+ # find_enclosing_module_named cannot use ruby's scoping so the result is not correct.
908
890
 
909
891
  def find_module_named(name)
910
- res = @modules[name] || @classes[name]
892
+ res = get_module_named(name)
911
893
  return res if res
912
894
  return self if self.name == name
913
895
  find_enclosing_module_named name
914
896
  end
915
897
 
898
+ # Get a module named +name+ in this context
899
+ # Don't look up for higher module nesting scopes. RDoc::Context doesn't have that information.
900
+
901
+ def get_module_named(name)
902
+ @modules[name] || @classes[name]
903
+ end
904
+
916
905
  ##
917
906
  # Look up +symbol+, first as a module, then as a local symbol.
918
907
 
@@ -975,36 +964,19 @@ class RDoc::Context < RDoc::CodeObject
975
964
  ##
976
965
  # URL for this with a +prefix+
977
966
 
978
- def http_url(prefix)
967
+ def http_url
979
968
  path = name_for_path
980
969
  path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<</
981
- path = [prefix] + path.split('::')
970
+ path = path.split('::')
982
971
 
983
972
  File.join(*path.compact) + '.html'
984
973
  end
985
974
 
986
- ##
987
- # Instance attributes
988
-
989
- def instance_attributes
990
- @instance_attributes ||= attributes.reject { |a| a.singleton }
991
- end
992
-
993
975
  ##
994
976
  # Instance methods
995
977
 
996
978
  def instance_methods
997
- @instance_methods ||= method_list.reject { |a| a.singleton }
998
- end
999
-
1000
- ##
1001
- # Instance methods
1002
- #--
1003
- # TODO remove this later
1004
-
1005
- def instance_method_list
1006
- warn '#instance_method_list is obsoleted, please use #instance_methods'
1007
- @instance_methods ||= method_list.reject { |a| a.singleton }
979
+ method_list.reject { |a| a.singleton }
1008
980
  end
1009
981
 
1010
982
  ##
@@ -1014,7 +986,7 @@ class RDoc::Context < RDoc::CodeObject
1014
986
  # If +section+ is provided only methods in that RDoc::Context::Section will
1015
987
  # be returned.
1016
988
 
1017
- def methods_by_type section = nil
989
+ def methods_by_type(section = nil)
1018
990
  methods = {}
1019
991
 
1020
992
  TYPES.each do |type|
@@ -1106,7 +1078,7 @@ class RDoc::Context < RDoc::CodeObject
1106
1078
  #--
1107
1079
  # TODO mark the visibility of attributes in the template (if not public?)
1108
1080
 
1109
- def remove_invisible min_visibility
1081
+ def remove_invisible(min_visibility)
1110
1082
  return if [:private, :nodoc].include? min_visibility
1111
1083
  remove_invisible_in @method_list, min_visibility
1112
1084
  remove_invisible_in @attributes, min_visibility
@@ -1116,7 +1088,7 @@ class RDoc::Context < RDoc::CodeObject
1116
1088
  ##
1117
1089
  # Only called when min_visibility == :public or :private
1118
1090
 
1119
- def remove_invisible_in array, min_visibility # :nodoc:
1091
+ def remove_invisible_in(array, min_visibility) # :nodoc:
1120
1092
  if min_visibility == :public then
1121
1093
  array.reject! { |e|
1122
1094
  e.visibility != :public and not e.force_documentation
@@ -1132,7 +1104,7 @@ class RDoc::Context < RDoc::CodeObject
1132
1104
  # Tries to resolve unmatched aliases when a method or attribute has just
1133
1105
  # been added.
1134
1106
 
1135
- def resolve_aliases added
1107
+ def resolve_aliases(added)
1136
1108
  # resolve any pending unmatched aliases
1137
1109
  key = added.pretty_name
1138
1110
  unmatched_alias_list = @unmatched_alias_lists[key]
@@ -1183,7 +1155,7 @@ class RDoc::Context < RDoc::CodeObject
1183
1155
  ##
1184
1156
  # Sets the current section to a section with +title+. See also #add_section
1185
1157
 
1186
- def set_current_section title, comment
1158
+ def set_current_section(title, comment)
1187
1159
  @current_section = add_section title, comment
1188
1160
  end
1189
1161
 
@@ -1248,7 +1220,7 @@ class RDoc::Context < RDoc::CodeObject
1248
1220
  ##
1249
1221
  # Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
1250
1222
 
1251
- def upgrade_to_class mod, class_type, enclosing
1223
+ def upgrade_to_class(mod, class_type, enclosing)
1252
1224
  enclosing.modules_hash.delete mod.name
1253
1225
 
1254
1226
  klass = RDoc::ClassModule.from_module class_type, mod
@@ -1261,6 +1233,6 @@ class RDoc::Context < RDoc::CodeObject
1261
1233
  klass
1262
1234
  end
1263
1235
 
1264
- autoload :Section, 'rdoc/context/section'
1236
+ autoload :Section, "#{__dir__}/context/section"
1265
1237
 
1266
1238
  end
@@ -7,4 +7,3 @@
7
7
  class RDoc::Extend < RDoc::Mixin
8
8
 
9
9
  end
10
-
@@ -7,4 +7,3 @@
7
7
  class RDoc::Include < RDoc::Mixin
8
8
 
9
9
  end
10
-