rdoc 3.1 → 6.3.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (247) 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 +129 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +84 -81
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/{bin → exe}/rdoc +11 -2
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +1 -2
  19. data/lib/rdoc/anon_class.rb +3 -2
  20. data/lib/rdoc/any_method.rb +234 -40
  21. data/lib/rdoc/attr.rb +79 -11
  22. data/lib/rdoc/class_module.rb +443 -71
  23. data/lib/rdoc/code_object.rb +216 -20
  24. data/lib/rdoc/code_objects.rb +4 -21
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +110 -9
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +392 -172
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +83 -28
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +8 -3
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +507 -84
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +27 -74
  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 +8 -62
  42. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  43. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  57. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  58. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  59. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  60. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/index.rhtml +18 -60
  72. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -83
  73. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  74. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  75. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  76. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  77. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  78. data/lib/rdoc/generator/template/json_index/.document +1 -0
  79. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  80. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  81. data/lib/rdoc/generator.rb +24 -13
  82. data/lib/rdoc/ghost_method.rb +1 -2
  83. data/lib/rdoc/i18n/locale.rb +102 -0
  84. data/lib/rdoc/i18n/text.rb +126 -0
  85. data/lib/rdoc/i18n.rb +10 -0
  86. data/lib/rdoc/include.rb +5 -95
  87. data/lib/rdoc/known_classes.rb +5 -2
  88. data/lib/rdoc/markdown/entities.rb +2132 -0
  89. data/lib/rdoc/markdown/literals.kpeg +23 -0
  90. data/lib/rdoc/markdown/literals.rb +416 -0
  91. data/lib/rdoc/markdown.kpeg +1237 -0
  92. data/lib/rdoc/markdown.rb +16684 -0
  93. data/lib/rdoc/markup/attr_changer.rb +23 -0
  94. data/lib/rdoc/markup/attr_span.rb +36 -0
  95. data/lib/rdoc/markup/attribute_manager.rb +135 -62
  96. data/lib/rdoc/markup/attributes.rb +71 -0
  97. data/lib/rdoc/markup/blank_line.rb +1 -0
  98. data/lib/rdoc/markup/block_quote.rb +15 -0
  99. data/lib/rdoc/markup/document.rb +96 -9
  100. data/lib/rdoc/markup/formatter.rb +138 -25
  101. data/lib/rdoc/markup/hard_break.rb +32 -0
  102. data/lib/rdoc/markup/heading.rb +61 -2
  103. data/lib/rdoc/markup/include.rb +43 -0
  104. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  105. data/lib/rdoc/markup/list.rb +25 -4
  106. data/lib/rdoc/markup/list_item.rb +18 -4
  107. data/lib/rdoc/markup/paragraph.rb +15 -0
  108. data/lib/rdoc/markup/parser.rb +180 -88
  109. data/lib/rdoc/markup/pre_process.rb +183 -38
  110. data/lib/rdoc/markup/raw.rb +6 -5
  111. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  112. data/lib/rdoc/markup/rule.rb +1 -0
  113. data/lib/rdoc/markup/table.rb +47 -0
  114. data/lib/rdoc/markup/to_ansi.rb +17 -7
  115. data/lib/rdoc/markup/to_bs.rb +5 -8
  116. data/lib/rdoc/markup/to_html.rb +238 -137
  117. data/lib/rdoc/markup/to_html_crossref.rb +125 -152
  118. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  119. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  120. data/lib/rdoc/markup/to_label.rb +75 -0
  121. data/lib/rdoc/markup/to_markdown.rb +192 -0
  122. data/lib/rdoc/markup/to_rdoc.rb +85 -15
  123. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  124. data/lib/rdoc/markup/to_test.rb +2 -4
  125. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  126. data/lib/rdoc/markup/verbatim.rb +39 -0
  127. data/lib/rdoc/markup.rb +388 -110
  128. data/lib/rdoc/meta_method.rb +1 -2
  129. data/lib/rdoc/method_attr.rb +87 -21
  130. data/lib/rdoc/mixin.rb +121 -0
  131. data/lib/rdoc/normal_class.rb +39 -10
  132. data/lib/rdoc/normal_module.rb +22 -7
  133. data/lib/rdoc/options.rb +613 -73
  134. data/lib/rdoc/parser/c.rb +621 -287
  135. data/lib/rdoc/parser/changelog.rb +335 -0
  136. data/lib/rdoc/parser/markdown.rb +24 -0
  137. data/lib/rdoc/parser/rd.rb +23 -0
  138. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  139. data/lib/rdoc/parser/ruby.rb +1368 -762
  140. data/lib/rdoc/parser/ruby_tools.rb +42 -35
  141. data/lib/rdoc/parser/simple.rb +23 -11
  142. data/lib/rdoc/parser/text.rb +12 -0
  143. data/lib/rdoc/parser.rb +162 -89
  144. data/lib/rdoc/rd/block_parser.rb +1056 -0
  145. data/lib/rdoc/rd/block_parser.ry +639 -0
  146. data/lib/rdoc/rd/inline.rb +72 -0
  147. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  148. data/lib/rdoc/rd/inline_parser.ry +593 -0
  149. data/lib/rdoc/rd.rb +100 -0
  150. data/lib/rdoc/rdoc.rb +208 -115
  151. data/lib/rdoc/require.rb +1 -2
  152. data/lib/rdoc/ri/driver.rb +734 -239
  153. data/lib/rdoc/ri/formatter.rb +1 -0
  154. data/lib/rdoc/ri/paths.rb +91 -48
  155. data/lib/rdoc/ri/store.rb +3 -261
  156. data/lib/rdoc/ri/task.rb +71 -0
  157. data/lib/rdoc/ri.rb +5 -2
  158. data/lib/rdoc/rubygems_hook.rb +246 -0
  159. data/lib/rdoc/servlet.rb +451 -0
  160. data/lib/rdoc/single_class.rb +14 -2
  161. data/lib/rdoc/stats/normal.rb +19 -12
  162. data/lib/rdoc/stats/quiet.rb +1 -0
  163. data/lib/rdoc/stats/verbose.rb +1 -0
  164. data/lib/rdoc/stats.rb +262 -104
  165. data/lib/rdoc/store.rb +979 -0
  166. data/lib/rdoc/task.rb +84 -44
  167. data/lib/rdoc/text.rb +117 -72
  168. data/lib/rdoc/token_stream.rb +73 -4
  169. data/lib/rdoc/tom_doc.rb +263 -0
  170. data/lib/rdoc/top_level.rb +111 -261
  171. data/lib/rdoc/version.rb +8 -0
  172. data/lib/rdoc.rb +127 -64
  173. data/man/ri.1 +247 -0
  174. data/rdoc.gemspec +249 -0
  175. metadata +171 -291
  176. data/.autotest +0 -16
  177. data/.document +0 -5
  178. data/History.txt +0 -594
  179. data/LICENSE.txt +0 -57
  180. data/Manifest.txt +0 -158
  181. data/README.txt +0 -45
  182. data/RI.txt +0 -58
  183. data/bin/ri +0 -5
  184. data/lib/rdoc/gauntlet.rb +0 -52
  185. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -296
  186. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  187. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -32
  188. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  189. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
  190. data/lib/rdoc/generator/template/darkfish/rdoc.css +0 -706
  191. data/lib/rdoc/markup/formatter_test_case.rb +0 -689
  192. data/lib/rdoc/markup/inline.rb +0 -137
  193. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -116
  194. data/lib/rdoc/ruby_lex.rb +0 -1291
  195. data/lib/rdoc/ruby_token.rb +0 -416
  196. data/test/README +0 -1
  197. data/test/binary.dat +0 -0
  198. data/test/hidden.zip.txt +0 -1
  199. data/test/test.ja.rdoc +0 -10
  200. data/test/test.ja.txt +0 -8
  201. data/test/test.txt +0 -1
  202. data/test/test_attribute_manager.rb +0 -120
  203. data/test/test_rdoc_alias.rb +0 -13
  204. data/test/test_rdoc_any_method.rb +0 -126
  205. data/test/test_rdoc_attr.rb +0 -61
  206. data/test/test_rdoc_class_module.rb +0 -233
  207. data/test/test_rdoc_code_object.rb +0 -165
  208. data/test/test_rdoc_constant.rb +0 -15
  209. data/test/test_rdoc_context.rb +0 -370
  210. data/test/test_rdoc_encoding.rb +0 -166
  211. data/test/test_rdoc_generator_darkfish.rb +0 -119
  212. data/test/test_rdoc_generator_ri.rb +0 -76
  213. data/test/test_rdoc_include.rb +0 -96
  214. data/test/test_rdoc_markup.rb +0 -37
  215. data/test/test_rdoc_markup_attribute_manager.rb +0 -240
  216. data/test/test_rdoc_markup_document.rb +0 -51
  217. data/test/test_rdoc_markup_paragraph.rb +0 -9
  218. data/test/test_rdoc_markup_parser.rb +0 -1395
  219. data/test/test_rdoc_markup_pre_process.rb +0 -185
  220. data/test/test_rdoc_markup_raw.rb +0 -27
  221. data/test/test_rdoc_markup_to_ansi.rb +0 -328
  222. data/test/test_rdoc_markup_to_bs.rb +0 -341
  223. data/test/test_rdoc_markup_to_html.rb +0 -335
  224. data/test/test_rdoc_markup_to_html_crossref.rb +0 -169
  225. data/test/test_rdoc_markup_to_rdoc.rb +0 -327
  226. data/test/test_rdoc_method_attr.rb +0 -122
  227. data/test/test_rdoc_normal_class.rb +0 -17
  228. data/test/test_rdoc_normal_module.rb +0 -31
  229. data/test/test_rdoc_options.rb +0 -342
  230. data/test/test_rdoc_parser.rb +0 -83
  231. data/test/test_rdoc_parser_c.rb +0 -912
  232. data/test/test_rdoc_parser_ruby.rb +0 -1754
  233. data/test/test_rdoc_parser_simple.rb +0 -99
  234. data/test/test_rdoc_rdoc.rb +0 -164
  235. data/test/test_rdoc_require.rb +0 -25
  236. data/test/test_rdoc_ri_driver.rb +0 -846
  237. data/test/test_rdoc_ri_paths.rb +0 -43
  238. data/test/test_rdoc_ri_store.rb +0 -352
  239. data/test/test_rdoc_ruby_lex.rb +0 -23
  240. data/test/test_rdoc_stats.rb +0 -38
  241. data/test/test_rdoc_task.rb +0 -92
  242. data/test/test_rdoc_text.rb +0 -251
  243. data/test/test_rdoc_top_level.rb +0 -120
  244. data/test/xref_data.rb +0 -62
  245. data/test/xref_test_case.rb +0 -61
  246. data.tar.gz.sig +0 -3
  247. metadata.gz.sig +0 -0
@@ -1,6 +1,4 @@
1
- require 'rdoc'
2
- require 'rdoc/text'
3
-
1
+ # frozen_string_literal: true
4
2
  ##
5
3
  # Base class for the RDoc code tree.
6
4
  #
@@ -23,8 +21,9 @@ require 'rdoc/text'
23
21
  # * RDoc::MetaMethod
24
22
  # * RDoc::Alias
25
23
  # * RDoc::Constant
26
- # * RDoc::Require
27
- # * RDoc::Include
24
+ # * RDoc::Mixin
25
+ # * RDoc::Require
26
+ # * RDoc::Include
28
27
 
29
28
  class RDoc::CodeObject
30
29
 
@@ -60,15 +59,20 @@ class RDoc::CodeObject
60
59
 
61
60
  attr_reader :force_documentation
62
61
 
62
+ ##
63
+ # Line in #file where this CodeObject was defined
64
+
65
+ attr_accessor :line
66
+
63
67
  ##
64
68
  # Hash of arbitrary metadata for this CodeObject
65
69
 
66
70
  attr_reader :metadata
67
71
 
68
72
  ##
69
- # Our parent CodeObject
73
+ # Sets the parent CodeObject
70
74
 
71
- attr_accessor :parent
75
+ attr_writer :parent
72
76
 
73
77
  ##
74
78
  # Did we ever receive a +:nodoc:+ directive?
@@ -76,9 +80,14 @@ class RDoc::CodeObject
76
80
  attr_reader :received_nodoc
77
81
 
78
82
  ##
79
- # Which section are we in
83
+ # Set the section this CodeObject is in
84
+
85
+ attr_writer :section
86
+
87
+ ##
88
+ # The RDoc::Store for this object.
80
89
 
81
- attr_accessor :section
90
+ attr_reader :store
82
91
 
83
92
  ##
84
93
  # We are the model of the code, but we know that at some point we will be
@@ -91,17 +100,33 @@ class RDoc::CodeObject
91
100
  # Creates a new CodeObject that will document itself and its children
92
101
 
93
102
  def initialize
94
- @metadata = {}
95
- @comment = ''
96
- @parent = nil
97
- @file = nil
98
- @full_name = nil
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.
99
120
 
121
+ def initialize_visibility # :nodoc:
100
122
  @document_children = true
101
123
  @document_self = true
102
124
  @done_documenting = false
103
125
  @force_documentation = false
104
126
  @received_nodoc = false
127
+ @ignored = false
128
+ @suppressed = false
129
+ @track_visibility = true
105
130
  end
106
131
 
107
132
  ##
@@ -111,20 +136,42 @@ class RDoc::CodeObject
111
136
  @comment = case comment
112
137
  when NilClass then ''
113
138
  when RDoc::Markup::Document then comment
139
+ when RDoc::Comment then comment.normalize
114
140
  else
115
141
  if comment and not comment.empty? then
116
142
  normalize_comment comment
117
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
118
149
  @comment
119
150
  end
120
151
  end
121
152
  end
122
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
+
123
168
  ##
124
169
  # Enables or disables documentation of this CodeObject's children unless it
125
170
  # has been turned off by :enddoc:
126
171
 
127
172
  def document_children=(document_children)
173
+ return unless @track_visibility
174
+
128
175
  @document_children = document_children unless @done_documenting
129
176
  end
130
177
 
@@ -134,6 +181,7 @@ class RDoc::CodeObject
134
181
  # documentation is turned off by +:nodoc:+.
135
182
 
136
183
  def document_self=(document_self)
184
+ return unless @track_visibility
137
185
  return if @done_documenting
138
186
 
139
187
  @document_self = document_self
@@ -157,14 +205,40 @@ class RDoc::CodeObject
157
205
  # will have no effect in the current file.
158
206
 
159
207
  def done_documenting=(value)
160
- @done_documenting = value
161
- @document_self = !value
208
+ return unless @track_visibility
209
+ @done_documenting = value
210
+ @document_self = !value
162
211
  @document_children = @document_self
163
212
  end
164
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
+
165
239
  ##
166
240
  # Force the documentation of this object unless documentation
167
- # has been turned off by :endoc:
241
+ # has been turned off by :enddoc:
168
242
  #--
169
243
  # HACK untested, was assigning to an ivar
170
244
 
@@ -181,6 +255,76 @@ class RDoc::CodeObject
181
255
  @full_name = full_name
182
256
  end
183
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
+
184
328
  ##
185
329
  # File name of our parent
186
330
 
@@ -199,27 +343,79 @@ class RDoc::CodeObject
199
343
  # Records the RDoc::TopLevel (file) where this code object was defined
200
344
 
201
345
  def record_location top_level
202
- @file = 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
203
359
  end
204
360
 
205
361
  ##
206
362
  # Enable capture of documentation unless documentation has been
207
- # turned off by :endoc:
363
+ # turned off by :enddoc:
208
364
 
209
365
  def start_doc
210
366
  return if @done_documenting
211
367
 
212
368
  @document_self = true
213
369
  @document_children = true
370
+ @ignored = false
371
+ @suppressed = false
214
372
  end
215
373
 
216
374
  ##
217
375
  # Disable capture of documentation
218
376
 
219
377
  def stop_doc
378
+ return unless @track_visibility
379
+
220
380
  @document_self = false
221
381
  @document_children = false
222
382
  end
223
383
 
224
- end
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
225
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
@@ -1,23 +1,6 @@
1
- # We represent the various high-level code constructs that appear in Ruby
2
- # programs: classes, modules, methods, and so on.
1
+ # frozen_string_literal: true
2
+ # This file was used to load all the RDoc::CodeObject subclasses at once. Now
3
+ # autoload handles this.
3
4
 
4
- require 'rdoc/code_object'
5
- require 'rdoc/context'
6
- require 'rdoc/top_level'
7
-
8
- require 'rdoc/class_module'
9
- require 'rdoc/normal_class'
10
- require 'rdoc/normal_module'
11
- require 'rdoc/anon_class'
12
- require 'rdoc/single_class'
13
-
14
- require 'rdoc/any_method'
15
- require 'rdoc/alias'
16
- require 'rdoc/ghost_method'
17
- require 'rdoc/meta_method'
18
-
19
- require 'rdoc/attr'
20
- require 'rdoc/constant'
21
- require 'rdoc/require'
22
- require 'rdoc/include'
5
+ require 'rdoc'
23
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