gitlab-rdoc 6.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +220 -0
  3. data/CVE-2013-0256.rdoc +49 -0
  4. data/ExampleMarkdown.md +37 -0
  5. data/ExampleRDoc.rdoc +208 -0
  6. data/Gemfile +12 -0
  7. data/History.rdoc +1666 -0
  8. data/LEGAL.rdoc +50 -0
  9. data/LICENSE.rdoc +57 -0
  10. data/README.rdoc +133 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +101 -0
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/exe/rdoc +44 -0
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +112 -0
  19. data/lib/rdoc/anon_class.rb +11 -0
  20. data/lib/rdoc/any_method.rb +361 -0
  21. data/lib/rdoc/attr.rb +176 -0
  22. data/lib/rdoc/class_module.rb +802 -0
  23. data/lib/rdoc/code_object.rb +421 -0
  24. data/lib/rdoc/code_objects.rb +6 -0
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +187 -0
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +1266 -0
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +136 -0
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +42 -0
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +790 -0
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +160 -0
  37. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  38. data/lib/rdoc/generator/pot/po.rb +84 -0
  39. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  40. data/lib/rdoc/generator/pot.rb +98 -0
  41. data/lib/rdoc/generator/ri.rb +31 -0
  42. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  58. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  59. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  72. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  73. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  74. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  75. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  76. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  77. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  78. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  79. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  80. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  81. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  82. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  83. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  84. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  85. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  86. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  87. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  88. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  89. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  90. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  91. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  92. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
  93. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
  94. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  95. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  96. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  97. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  98. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  99. data/lib/rdoc/generator/template/json_index/.document +1 -0
  100. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  101. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  102. data/lib/rdoc/generator.rb +51 -0
  103. data/lib/rdoc/ghost_method.rb +7 -0
  104. data/lib/rdoc/i18n/locale.rb +102 -0
  105. data/lib/rdoc/i18n/text.rb +126 -0
  106. data/lib/rdoc/i18n.rb +10 -0
  107. data/lib/rdoc/include.rb +10 -0
  108. data/lib/rdoc/known_classes.rb +73 -0
  109. data/lib/rdoc/markdown/entities.rb +2132 -0
  110. data/lib/rdoc/markdown/literals.kpeg +23 -0
  111. data/lib/rdoc/markdown/literals.rb +417 -0
  112. data/lib/rdoc/markdown.kpeg +1237 -0
  113. data/lib/rdoc/markdown.rb +16685 -0
  114. data/lib/rdoc/markup/attr_changer.rb +23 -0
  115. data/lib/rdoc/markup/attr_span.rb +36 -0
  116. data/lib/rdoc/markup/attribute_manager.rb +409 -0
  117. data/lib/rdoc/markup/attributes.rb +71 -0
  118. data/lib/rdoc/markup/blank_line.rb +28 -0
  119. data/lib/rdoc/markup/block_quote.rb +15 -0
  120. data/lib/rdoc/markup/document.rb +165 -0
  121. data/lib/rdoc/markup/formatter.rb +266 -0
  122. data/lib/rdoc/markup/hard_break.rb +32 -0
  123. data/lib/rdoc/markup/heading.rb +79 -0
  124. data/lib/rdoc/markup/include.rb +43 -0
  125. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  126. data/lib/rdoc/markup/list.rb +102 -0
  127. data/lib/rdoc/markup/list_item.rb +100 -0
  128. data/lib/rdoc/markup/paragraph.rb +29 -0
  129. data/lib/rdoc/markup/parser.rb +575 -0
  130. data/lib/rdoc/markup/pre_process.rb +296 -0
  131. data/lib/rdoc/markup/raw.rb +70 -0
  132. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  133. data/lib/rdoc/markup/rule.rb +21 -0
  134. data/lib/rdoc/markup/table.rb +47 -0
  135. data/lib/rdoc/markup/to_ansi.rb +94 -0
  136. data/lib/rdoc/markup/to_bs.rb +77 -0
  137. data/lib/rdoc/markup/to_html.rb +444 -0
  138. data/lib/rdoc/markup/to_html_crossref.rb +176 -0
  139. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  140. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  141. data/lib/rdoc/markup/to_label.rb +75 -0
  142. data/lib/rdoc/markup/to_markdown.rb +192 -0
  143. data/lib/rdoc/markup/to_rdoc.rb +362 -0
  144. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  145. data/lib/rdoc/markup/to_test.rb +70 -0
  146. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  147. data/lib/rdoc/markup/verbatim.rb +84 -0
  148. data/lib/rdoc/markup.rb +867 -0
  149. data/lib/rdoc/meta_method.rb +7 -0
  150. data/lib/rdoc/method_attr.rb +419 -0
  151. data/lib/rdoc/mixin.rb +121 -0
  152. data/lib/rdoc/normal_class.rb +93 -0
  153. data/lib/rdoc/normal_module.rb +74 -0
  154. data/lib/rdoc/options.rb +1285 -0
  155. data/lib/rdoc/parser/c.rb +1225 -0
  156. data/lib/rdoc/parser/changelog.rb +335 -0
  157. data/lib/rdoc/parser/markdown.rb +24 -0
  158. data/lib/rdoc/parser/rd.rb +23 -0
  159. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  160. data/lib/rdoc/parser/ruby.rb +2327 -0
  161. data/lib/rdoc/parser/ruby_tools.rb +167 -0
  162. data/lib/rdoc/parser/simple.rb +61 -0
  163. data/lib/rdoc/parser/text.rb +12 -0
  164. data/lib/rdoc/parser.rb +277 -0
  165. data/lib/rdoc/rd/block_parser.rb +1056 -0
  166. data/lib/rdoc/rd/block_parser.ry +639 -0
  167. data/lib/rdoc/rd/inline.rb +72 -0
  168. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  169. data/lib/rdoc/rd/inline_parser.ry +593 -0
  170. data/lib/rdoc/rd.rb +100 -0
  171. data/lib/rdoc/rdoc.rb +579 -0
  172. data/lib/rdoc/require.rb +52 -0
  173. data/lib/rdoc/ri/driver.rb +1572 -0
  174. data/lib/rdoc/ri/formatter.rb +6 -0
  175. data/lib/rdoc/ri/paths.rb +171 -0
  176. data/lib/rdoc/ri/store.rb +7 -0
  177. data/lib/rdoc/ri/task.rb +71 -0
  178. data/lib/rdoc/ri.rb +21 -0
  179. data/lib/rdoc/rubygems_hook.rb +246 -0
  180. data/lib/rdoc/servlet.rb +451 -0
  181. data/lib/rdoc/single_class.rb +26 -0
  182. data/lib/rdoc/stats/normal.rb +58 -0
  183. data/lib/rdoc/stats/quiet.rb +60 -0
  184. data/lib/rdoc/stats/verbose.rb +46 -0
  185. data/lib/rdoc/stats.rb +462 -0
  186. data/lib/rdoc/store.rb +979 -0
  187. data/lib/rdoc/task.rb +329 -0
  188. data/lib/rdoc/text.rb +304 -0
  189. data/lib/rdoc/token_stream.rb +119 -0
  190. data/lib/rdoc/tom_doc.rb +263 -0
  191. data/lib/rdoc/top_level.rb +289 -0
  192. data/lib/rdoc/version.rb +8 -0
  193. data/lib/rdoc.rb +201 -0
  194. data/man/ri.1 +247 -0
  195. data/rdoc.gemspec +249 -0
  196. metadata +279 -0
@@ -0,0 +1,421 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Base class for the RDoc code tree.
4
+ #
5
+ # We contain the common stuff for contexts (which are containers) and other
6
+ # elements (methods, attributes and so on)
7
+ #
8
+ # Here's the tree of the CodeObject subclasses:
9
+ #
10
+ # * RDoc::Context
11
+ # * RDoc::TopLevel
12
+ # * RDoc::ClassModule
13
+ # * RDoc::AnonClass (never used so far)
14
+ # * RDoc::NormalClass
15
+ # * RDoc::NormalModule
16
+ # * RDoc::SingleClass
17
+ # * RDoc::MethodAttr
18
+ # * RDoc::Attr
19
+ # * RDoc::AnyMethod
20
+ # * RDoc::GhostMethod
21
+ # * RDoc::MetaMethod
22
+ # * RDoc::Alias
23
+ # * RDoc::Constant
24
+ # * RDoc::Mixin
25
+ # * RDoc::Require
26
+ # * RDoc::Include
27
+
28
+ class RDoc::CodeObject
29
+
30
+ include RDoc::Text
31
+
32
+ ##
33
+ # Our comment
34
+
35
+ attr_reader :comment
36
+
37
+ ##
38
+ # Do we document our children?
39
+
40
+ attr_reader :document_children
41
+
42
+ ##
43
+ # Do we document ourselves?
44
+
45
+ attr_reader :document_self
46
+
47
+ ##
48
+ # Are we done documenting (ie, did we come across a :enddoc:)?
49
+
50
+ attr_reader :done_documenting
51
+
52
+ ##
53
+ # Which file this code object was defined in
54
+
55
+ attr_reader :file
56
+
57
+ ##
58
+ # Force documentation of this CodeObject
59
+
60
+ attr_reader :force_documentation
61
+
62
+ ##
63
+ # Line in #file where this CodeObject was defined
64
+
65
+ attr_accessor :line
66
+
67
+ ##
68
+ # Hash of arbitrary metadata for this CodeObject
69
+
70
+ attr_reader :metadata
71
+
72
+ ##
73
+ # Sets the parent CodeObject
74
+
75
+ attr_writer :parent
76
+
77
+ ##
78
+ # Did we ever receive a +:nodoc:+ directive?
79
+
80
+ attr_reader :received_nodoc
81
+
82
+ ##
83
+ # Set the section this CodeObject is in
84
+
85
+ attr_writer :section
86
+
87
+ ##
88
+ # The RDoc::Store for this object.
89
+
90
+ attr_reader :store
91
+
92
+ ##
93
+ # We are the model of the code, but we know that at some point we will be
94
+ # worked on by viewers. By implementing the Viewable protocol, viewers can
95
+ # associated themselves with these objects.
96
+
97
+ attr_accessor :viewer
98
+
99
+ ##
100
+ # Creates a new CodeObject that will document itself and its children
101
+
102
+ def initialize
103
+ @metadata = {}
104
+ @comment = ''
105
+ @parent = nil
106
+ @parent_name = nil # for loading
107
+ @parent_class = nil # for loading
108
+ @section = nil
109
+ @section_title = nil # for loading
110
+ @file = nil
111
+ @full_name = nil
112
+ @store = nil
113
+ @track_visibility = true
114
+
115
+ initialize_visibility
116
+ end
117
+
118
+ ##
119
+ # Initializes state for visibility of this CodeObject and its children.
120
+
121
+ def initialize_visibility # :nodoc:
122
+ @document_children = true
123
+ @document_self = true
124
+ @done_documenting = false
125
+ @force_documentation = false
126
+ @received_nodoc = false
127
+ @ignored = false
128
+ @suppressed = false
129
+ @track_visibility = true
130
+ end
131
+
132
+ ##
133
+ # Replaces our comment with +comment+, unless it is empty.
134
+
135
+ def comment=(comment)
136
+ @comment = case comment
137
+ when NilClass then ''
138
+ when RDoc::Markup::Document then comment
139
+ when RDoc::Comment then comment.normalize
140
+ else
141
+ if comment and not comment.empty? then
142
+ normalize_comment comment
143
+ else
144
+ # HACK correct fix is to have #initialize create @comment
145
+ # with the correct encoding
146
+ if String === @comment and @comment.empty? then
147
+ @comment = RDoc::Encoding.change_encoding @comment, comment.encoding
148
+ end
149
+ @comment
150
+ end
151
+ end
152
+ end
153
+
154
+ ##
155
+ # Should this CodeObject be displayed in output?
156
+ #
157
+ # A code object should be displayed if:
158
+ #
159
+ # * The item didn't have a nodoc or wasn't in a container that had nodoc
160
+ # * The item wasn't ignored
161
+ # * The item has documentation and was not suppressed
162
+
163
+ def display?
164
+ @document_self and not @ignored and
165
+ (documented? or not @suppressed)
166
+ end
167
+
168
+ ##
169
+ # Enables or disables documentation of this CodeObject's children unless it
170
+ # has been turned off by :enddoc:
171
+
172
+ def document_children=(document_children)
173
+ return unless @track_visibility
174
+
175
+ @document_children = document_children unless @done_documenting
176
+ end
177
+
178
+ ##
179
+ # Enables or disables documentation of this CodeObject unless it has been
180
+ # turned off by :enddoc:. If the argument is +nil+ it means the
181
+ # documentation is turned off by +:nodoc:+.
182
+
183
+ def document_self=(document_self)
184
+ return unless @track_visibility
185
+ return if @done_documenting
186
+
187
+ @document_self = document_self
188
+ @received_nodoc = true if document_self.nil?
189
+ end
190
+
191
+ ##
192
+ # Does this object have a comment with content or is #received_nodoc true?
193
+
194
+ def documented?
195
+ @received_nodoc or !@comment.empty?
196
+ end
197
+
198
+ ##
199
+ # Turns documentation on/off, and turns on/off #document_self
200
+ # and #document_children.
201
+ #
202
+ # Once documentation has been turned off (by +:enddoc:+),
203
+ # the object will refuse to turn #document_self or
204
+ # #document_children on, so +:doc:+ and +:start_doc:+ directives
205
+ # will have no effect in the current file.
206
+
207
+ def done_documenting=(value)
208
+ return unless @track_visibility
209
+ @done_documenting = value
210
+ @document_self = !value
211
+ @document_children = @document_self
212
+ end
213
+
214
+ ##
215
+ # Yields each parent of this CodeObject. See also
216
+ # RDoc::ClassModule#each_ancestor
217
+
218
+ def each_parent
219
+ code_object = self
220
+
221
+ while code_object = code_object.parent do
222
+ yield code_object
223
+ end
224
+
225
+ self
226
+ end
227
+
228
+ ##
229
+ # File name where this CodeObject was found.
230
+ #
231
+ # See also RDoc::Context#in_files
232
+
233
+ def file_name
234
+ return unless @file
235
+
236
+ @file.absolute_name
237
+ end
238
+
239
+ ##
240
+ # Force the documentation of this object unless documentation
241
+ # has been turned off by :enddoc:
242
+ #--
243
+ # HACK untested, was assigning to an ivar
244
+
245
+ def force_documentation=(value)
246
+ @force_documentation = value unless @done_documenting
247
+ end
248
+
249
+ ##
250
+ # Sets the full_name overriding any computed full name.
251
+ #
252
+ # Set to +nil+ to clear RDoc's cached value
253
+
254
+ def full_name= full_name
255
+ @full_name = full_name
256
+ end
257
+
258
+ ##
259
+ # Use this to ignore a CodeObject and all its children until found again
260
+ # (#record_location is called). An ignored item will not be displayed in
261
+ # documentation.
262
+ #
263
+ # See github issue #55
264
+ #
265
+ # The ignored status is temporary in order to allow implementation details
266
+ # to be hidden. At the end of processing a file RDoc allows all classes
267
+ # and modules to add new documentation to previously created classes.
268
+ #
269
+ # If a class was ignored (via stopdoc) then reopened later with additional
270
+ # documentation it should be displayed. If a class was ignored and never
271
+ # reopened it should not be displayed. The ignore flag allows this to
272
+ # occur.
273
+
274
+ def ignore
275
+ return unless @track_visibility
276
+
277
+ @ignored = true
278
+
279
+ stop_doc
280
+ end
281
+
282
+ ##
283
+ # Has this class been ignored?
284
+ #
285
+ # See also #ignore
286
+
287
+ def ignored?
288
+ @ignored
289
+ end
290
+
291
+ ##
292
+ # The options instance from the store this CodeObject is attached to, or a
293
+ # default options instance if the CodeObject is not attached.
294
+ #
295
+ # This is used by Text#snippet
296
+
297
+ def options
298
+ if @store and @store.rdoc then
299
+ @store.rdoc.options
300
+ else
301
+ RDoc::Options.new
302
+ end
303
+ end
304
+
305
+ ##
306
+ # Our parent CodeObject. The parent may be missing for classes loaded from
307
+ # legacy RI data stores.
308
+
309
+ def parent
310
+ return @parent if @parent
311
+ return nil unless @parent_name
312
+
313
+ if @parent_class == RDoc::TopLevel then
314
+ @parent = @store.add_file @parent_name
315
+ else
316
+ @parent = @store.find_class_or_module @parent_name
317
+
318
+ return @parent if @parent
319
+
320
+ begin
321
+ @parent = @store.load_class @parent_name
322
+ rescue RDoc::Store::MissingFileError
323
+ nil
324
+ end
325
+ end
326
+ end
327
+
328
+ ##
329
+ # File name of our parent
330
+
331
+ def parent_file_name
332
+ @parent ? @parent.base_name : '(unknown)'
333
+ end
334
+
335
+ ##
336
+ # Name of our parent
337
+
338
+ def parent_name
339
+ @parent ? @parent.full_name : '(unknown)'
340
+ end
341
+
342
+ ##
343
+ # Records the RDoc::TopLevel (file) where this code object was defined
344
+
345
+ def record_location top_level
346
+ @ignored = false
347
+ @suppressed = false
348
+ @file = top_level
349
+ end
350
+
351
+ ##
352
+ # The section this CodeObject is in. Sections allow grouping of constants,
353
+ # attributes and methods inside a class or module.
354
+
355
+ def section
356
+ return @section if @section
357
+
358
+ @section = parent.add_section @section_title if parent
359
+ end
360
+
361
+ ##
362
+ # Enable capture of documentation unless documentation has been
363
+ # turned off by :enddoc:
364
+
365
+ def start_doc
366
+ return if @done_documenting
367
+
368
+ @document_self = true
369
+ @document_children = true
370
+ @ignored = false
371
+ @suppressed = false
372
+ end
373
+
374
+ ##
375
+ # Disable capture of documentation
376
+
377
+ def stop_doc
378
+ return unless @track_visibility
379
+
380
+ @document_self = false
381
+ @document_children = false
382
+ end
383
+
384
+ ##
385
+ # Sets the +store+ that contains this CodeObject
386
+
387
+ def store= store
388
+ @store = store
389
+
390
+ return unless @track_visibility
391
+
392
+ if :nodoc == options.visibility then
393
+ initialize_visibility
394
+ @track_visibility = false
395
+ end
396
+ end
397
+
398
+ ##
399
+ # Use this to suppress a CodeObject and all its children until the next file
400
+ # it is seen in or documentation is discovered. A suppressed item with
401
+ # documentation will be displayed while an ignored item with documentation
402
+ # may not be displayed.
403
+
404
+ def suppress
405
+ return unless @track_visibility
406
+
407
+ @suppressed = true
408
+
409
+ stop_doc
410
+ end
411
+
412
+ ##
413
+ # Has this class been suppressed?
414
+ #
415
+ # See also #suppress
416
+
417
+ def suppressed?
418
+ @suppressed
419
+ end
420
+
421
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # This file was used to load all the RDoc::CodeObject subclasses at once. Now
3
+ # autoload handles this.
4
+
5
+ require 'rdoc'
6
+
@@ -0,0 +1,250 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # A comment holds the text comment for a RDoc::CodeObject and provides a
4
+ # unified way of cleaning it up and parsing it into an RDoc::Markup::Document.
5
+ #
6
+ # Each comment may have a different markup format set by #format=. By default
7
+ # 'rdoc' is used. The :markup: directive tells RDoc which format to use.
8
+ #
9
+ # See RDoc::Markup@Other+directives for instructions on adding an alternate
10
+ # format.
11
+
12
+ class RDoc::Comment
13
+
14
+ include RDoc::Text
15
+
16
+ ##
17
+ # The format of this comment. Defaults to RDoc::Markup
18
+
19
+ attr_reader :format
20
+
21
+ ##
22
+ # The RDoc::TopLevel this comment was found in
23
+
24
+ attr_accessor :location
25
+
26
+ ##
27
+ # Line where this Comment was written
28
+
29
+ attr_accessor :line
30
+
31
+ ##
32
+ # For duck-typing when merging classes at load time
33
+
34
+ alias file location # :nodoc:
35
+
36
+ ##
37
+ # The text for this comment
38
+
39
+ attr_reader :text
40
+
41
+ ##
42
+ # Alias for text
43
+
44
+ alias to_s text
45
+
46
+ ##
47
+ # Overrides the content returned by #parse. Use when there is no #text
48
+ # source for this comment
49
+
50
+ attr_writer :document
51
+
52
+ ##
53
+ # Creates a new comment with +text+ that is found in the RDoc::TopLevel
54
+ # +location+.
55
+
56
+ def initialize text = nil, location = nil, language = nil
57
+ @location = location
58
+ @text = text.nil? ? nil : text.dup
59
+ @language = language
60
+
61
+ @document = nil
62
+ @format = 'rdoc'
63
+ @normalized = false
64
+ end
65
+
66
+ ##
67
+ #--
68
+ # TODO deep copy @document
69
+
70
+ def initialize_copy copy # :nodoc:
71
+ @text = copy.text.dup
72
+ end
73
+
74
+ def == other # :nodoc:
75
+ self.class === other and
76
+ other.text == @text and other.location == @location
77
+ end
78
+
79
+ ##
80
+ # Look for a 'call-seq' in the comment to override the normal parameter
81
+ # handling. The :call-seq: is indented from the baseline. All lines of the
82
+ # same indentation level and prefix are consumed.
83
+ #
84
+ # For example, all of the following will be used as the :call-seq:
85
+ #
86
+ # # :call-seq:
87
+ # # ARGF.readlines(sep=$/) -> array
88
+ # # ARGF.readlines(limit) -> array
89
+ # # ARGF.readlines(sep, limit) -> array
90
+ # #
91
+ # # ARGF.to_a(sep=$/) -> array
92
+ # # ARGF.to_a(limit) -> array
93
+ # # ARGF.to_a(sep, limit) -> array
94
+
95
+ def extract_call_seq method
96
+ # we must handle situations like the above followed by an unindented first
97
+ # comment. The difficulty is to make sure not to match lines starting
98
+ # with ARGF at the same indent, but that are after the first description
99
+ # paragraph.
100
+ if @text =~ /^\s*:?call-seq:(.*?(?:\S).*?)^\s*$/m then
101
+ all_start, all_stop = $~.offset(0)
102
+ seq_start, seq_stop = $~.offset(1)
103
+
104
+ # we get the following lines that start with the leading word at the
105
+ # same indent, even if they have blank lines before
106
+ if $1 =~ /(^\s*\n)+^(\s*\w+)/m then
107
+ leading = $2 # ' * ARGF' in the example above
108
+ re = %r%
109
+ \A(
110
+ (^\s*\n)+
111
+ (^#{Regexp.escape leading}.*?\n)+
112
+ )+
113
+ ^\s*$
114
+ %xm
115
+
116
+ if @text[seq_stop..-1] =~ re then
117
+ all_stop = seq_stop + $~.offset(0).last
118
+ seq_stop = seq_stop + $~.offset(1).last
119
+ end
120
+ end
121
+
122
+ seq = @text[seq_start..seq_stop]
123
+ seq.gsub!(/^\s*(\S|\n)/m, '\1')
124
+ @text.slice! all_start...all_stop
125
+
126
+ method.call_seq = seq.chomp
127
+
128
+ else
129
+ regexp = /^\s*:?call-seq:(.*?)(^\s*$|\z)/m
130
+ if regexp =~ @text then
131
+ @text = @text.sub(regexp, '')
132
+ seq = $1
133
+ seq.gsub!(/^\s*/, '')
134
+ method.call_seq = seq
135
+ end
136
+ end
137
+
138
+ method
139
+ end
140
+
141
+ ##
142
+ # A comment is empty if its text String is empty.
143
+
144
+ def empty?
145
+ @text.empty?
146
+ end
147
+
148
+ ##
149
+ # HACK dubious
150
+
151
+ def encode! encoding
152
+ # TODO: Remove this condition after Ruby 2.2 EOL
153
+ if RUBY_VERSION < '2.3.0'
154
+ @text = @text.force_encoding encoding
155
+ else
156
+ @text = String.new @text, encoding: encoding
157
+ end
158
+ self
159
+ end
160
+
161
+ ##
162
+ # Sets the format of this comment and resets any parsed document
163
+
164
+ def format= format
165
+ @format = format
166
+ @document = nil
167
+ end
168
+
169
+ def inspect # :nodoc:
170
+ location = @location ? @location.relative_name : '(unknown)'
171
+
172
+ "#<%s:%x %s %p>" % [self.class, object_id, location, @text]
173
+ end
174
+
175
+ ##
176
+ # Normalizes the text. See RDoc::Text#normalize_comment for details
177
+
178
+ def normalize
179
+ return self unless @text
180
+ return self if @normalized # TODO eliminate duplicate normalization
181
+
182
+ @text = normalize_comment @text
183
+
184
+ @normalized = true
185
+
186
+ self
187
+ end
188
+
189
+ ##
190
+ # Was this text normalized?
191
+
192
+ def normalized? # :nodoc:
193
+ @normalized
194
+ end
195
+
196
+ ##
197
+ # Parses the comment into an RDoc::Markup::Document. The parsed document is
198
+ # cached until the text is changed.
199
+
200
+ def parse
201
+ return @document if @document
202
+
203
+ @document = super @text, @format
204
+ @document.file = @location
205
+ @document
206
+ end
207
+
208
+ ##
209
+ # Removes private sections from this comment. Private sections are flush to
210
+ # the comment marker and start with <tt>--</tt> and end with <tt>++</tt>.
211
+ # For C-style comments, a private marker may not start at the opening of the
212
+ # comment.
213
+ #
214
+ # /*
215
+ # *--
216
+ # * private
217
+ # *++
218
+ # * public
219
+ # */
220
+
221
+ def remove_private
222
+ # Workaround for gsub encoding for Ruby 1.9.2 and earlier
223
+ empty = ''
224
+ empty = RDoc::Encoding.change_encoding empty, @text.encoding
225
+
226
+ @text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
227
+ @text = @text.sub(%r%^\s*[#*]?--.*%m, '')
228
+ end
229
+
230
+ ##
231
+ # Replaces this comment's text with +text+ and resets the parsed document.
232
+ #
233
+ # An error is raised if the comment contains a document but no text.
234
+
235
+ def text= text
236
+ raise RDoc::Error, 'replacing document-only comment is not allowed' if
237
+ @text.nil? and @document
238
+
239
+ @document = nil
240
+ @text = text.nil? ? nil : text.dup
241
+ end
242
+
243
+ ##
244
+ # Returns true if this comment is in TomDoc format.
245
+
246
+ def tomdoc?
247
+ @format == 'tomdoc'
248
+ end
249
+
250
+ end