rdoc 3.12.2 → 4.0.0.preview2

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 (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -75,9 +75,9 @@ class RDoc::CodeObject
75
75
  attr_accessor :offset
76
76
 
77
77
  ##
78
- # Our parent CodeObject
78
+ # Sets the parent CodeObject
79
79
 
80
- attr_accessor :parent
80
+ attr_writer :parent
81
81
 
82
82
  ##
83
83
  # Did we ever receive a +:nodoc:+ directive?
@@ -85,9 +85,14 @@ class RDoc::CodeObject
85
85
  attr_reader :received_nodoc
86
86
 
87
87
  ##
88
- # Which section are we in
88
+ # Set the section this CodeObject is in
89
89
 
90
- attr_accessor :section
90
+ attr_writer :section
91
+
92
+ ##
93
+ # The RDoc::Store for this object.
94
+
95
+ attr_accessor :store
91
96
 
92
97
  ##
93
98
  # We are the model of the code, but we know that at some point we will be
@@ -100,11 +105,16 @@ class RDoc::CodeObject
100
105
  # Creates a new CodeObject that will document itself and its children
101
106
 
102
107
  def initialize
103
- @metadata = {}
104
- @comment = ''
105
- @parent = nil
106
- @file = nil
107
- @full_name = nil
108
+ @metadata = {}
109
+ @comment = ''
110
+ @parent = nil
111
+ @parent_name = nil # for loading
112
+ @parent_class = nil # for loading
113
+ @section = nil
114
+ @section_title = nil # for loading
115
+ @file = nil
116
+ @full_name = nil
117
+ @store = nil
108
118
 
109
119
  @document_children = true
110
120
  @document_self = true
@@ -126,7 +136,6 @@ class RDoc::CodeObject
126
136
  if comment and not comment.empty? then
127
137
  normalize_comment comment
128
138
  else
129
- # TODO is this sufficient?
130
139
  # HACK correct fix is to have #initialize create @comment
131
140
  # with the correct encoding
132
141
  if String === @comment and
@@ -214,7 +223,7 @@ class RDoc::CodeObject
214
223
 
215
224
  ##
216
225
  # Force the documentation of this object unless documentation
217
- # has been turned off by :endoc:
226
+ # has been turned off by :enddoc:
218
227
  #--
219
228
  # HACK untested, was assigning to an ivar
220
229
 
@@ -259,6 +268,29 @@ class RDoc::CodeObject
259
268
  @ignored
260
269
  end
261
270
 
271
+ ##
272
+ # Our parent CodeObject. The parent may be missing for classes loaded from
273
+ # legacy RI data stores.
274
+
275
+ def parent
276
+ return @parent if @parent
277
+ return nil unless @parent_name
278
+
279
+ if @parent_class == RDoc::TopLevel then
280
+ @parent = @store.add_file @parent_name
281
+ else
282
+ @parent = @store.find_class_or_module @parent_name
283
+
284
+ return @parent if @parent
285
+
286
+ begin
287
+ @parent = @store.load_class @parent_name
288
+ rescue RDoc::Store::MissingFileError
289
+ nil
290
+ end
291
+ end
292
+ end
293
+
262
294
  ##
263
295
  # File name of our parent
264
296
 
@@ -281,9 +313,19 @@ class RDoc::CodeObject
281
313
  @file = top_level
282
314
  end
283
315
 
316
+ ##
317
+ # The section this CodeObject is in. Sections allow grouping of constants,
318
+ # attributes and methods inside a class or module.
319
+
320
+ def section
321
+ return @section if @section
322
+
323
+ @section = parent.add_section @section_title if parent
324
+ end
325
+
284
326
  ##
285
327
  # Enable capture of documentation unless documentation has been
286
- # turned off by :endoc:
328
+ # turned off by :enddoc:
287
329
 
288
330
  def start_doc
289
331
  return if @done_documenting
@@ -22,6 +22,11 @@ class RDoc::Comment
22
22
 
23
23
  attr_accessor :location
24
24
 
25
+ ##
26
+ # For duck-typing when merging classes at load time
27
+
28
+ alias file location # :nodoc:
29
+
25
30
  ##
26
31
  # The text for this comment
27
32
 
@@ -143,7 +148,9 @@ class RDoc::Comment
143
148
  end
144
149
 
145
150
  def inspect # :nodoc:
146
- "#<%s:%x %s %p>" % [self.class, object_id, @location.absolute_name, @text]
151
+ location = @location ? @location.relative_name : '(unknown)'
152
+
153
+ "#<%s:%x %s %p>" % [self.class, object_id, location, @text]
147
154
  end
148
155
 
149
156
  ##
@@ -3,12 +3,12 @@
3
3
 
4
4
  class RDoc::Constant < RDoc::CodeObject
5
5
 
6
+ MARSHAL_VERSION = 0 # :nodoc:
7
+
6
8
  ##
7
- # If this constant is an alias for a module or class,
8
- # this is the RDoc::ClassModule it is an alias for.
9
- # +nil+ otherwise.
9
+ # Sets the module or class this is constant is an alias for.
10
10
 
11
- attr_accessor :is_alias_for
11
+ attr_writer :is_alias_for
12
12
 
13
13
  ##
14
14
  # The constant's name
@@ -20,14 +20,23 @@ class RDoc::Constant < RDoc::CodeObject
20
20
 
21
21
  attr_accessor :value
22
22
 
23
+ ##
24
+ # The constant's visibility
25
+
26
+ attr_accessor :visibility
27
+
23
28
  ##
24
29
  # Creates a new constant with +name+, +value+ and +comment+
25
30
 
26
31
  def initialize(name, value, comment)
27
32
  super()
28
- @name = name
33
+
34
+ @name = name
29
35
  @value = value
36
+
30
37
  @is_alias_for = nil
38
+ @visibility = nil
39
+
31
40
  self.comment = comment
32
41
  end
33
42
 
@@ -57,6 +66,27 @@ class RDoc::Constant < RDoc::CodeObject
57
66
  super or is_alias_for && is_alias_for.documented?
58
67
  end
59
68
 
69
+ ##
70
+ # Full constant name including namespace
71
+
72
+ def full_name
73
+ @full_name ||= "#{parent_name}::#{@name}"
74
+ end
75
+
76
+ ##
77
+ # The module or class this constant is an alias for
78
+
79
+ def is_alias_for
80
+ case @is_alias_for
81
+ when String then
82
+ found = @store.find_class_or_module @is_alias_for
83
+ @is_alias_for = found if found
84
+ @is_alias_for
85
+ else
86
+ @is_alias_for
87
+ end
88
+ end
89
+
60
90
  def inspect # :nodoc:
61
91
  "#<%s:0x%x %s::%s>" % [
62
92
  self.class, object_id,
@@ -65,12 +95,76 @@ class RDoc::Constant < RDoc::CodeObject
65
95
  end
66
96
 
67
97
  ##
68
- # Path to this constant
98
+ # Dumps this Constant for use by ri. See also #marshal_load
99
+
100
+ def marshal_dump
101
+ alias_name = case found = is_alias_for
102
+ when RDoc::CodeObject then found.full_name
103
+ else found
104
+ end
105
+
106
+ [ MARSHAL_VERSION,
107
+ @name,
108
+ full_name,
109
+ @visibility,
110
+ alias_name,
111
+ parse(@comment),
112
+ @file.relative_name,
113
+ parent.name,
114
+ parent.class,
115
+ section.title,
116
+ ]
117
+ end
118
+
119
+ ##
120
+ # Loads this Constant from +array+. For a loaded Constant the following
121
+ # methods will return cached values:
122
+ #
123
+ # * #full_name
124
+ # * #parent_name
125
+
126
+ def marshal_load array
127
+ initialize array[1], nil, array[5]
128
+
129
+ @full_name = array[2]
130
+ @visibility = array[3]
131
+ @is_alias_for = array[4]
132
+ # 5 handled above
133
+ # 6 handled below
134
+ @parent_name = array[7]
135
+ @parent_class = array[8]
136
+ @section_title = array[9]
137
+
138
+ @file = RDoc::TopLevel.new array[6]
139
+ end
140
+
141
+ ##
142
+ # Path to this constant for use with HTML generator output.
69
143
 
70
144
  def path
71
145
  "#{@parent.path}##{@name}"
72
146
  end
73
147
 
148
+ def pretty_print q # :nodoc:
149
+ q.group 2, "[#{self.class.name} #{full_name}", "]" do
150
+ unless comment.empty? then
151
+ q.breakable
152
+ q.text "comment:"
153
+ q.breakable
154
+ q.pp @comment
155
+ end
156
+ end
157
+ end
158
+
159
+ ##
160
+ # Sets the store for this class or module and its contained code objects.
161
+
162
+ def store= store
163
+ super
164
+
165
+ @file = @store.add_file @file.full_name if @file
166
+ end
167
+
74
168
  def to_s # :nodoc:
75
169
  parent_name = parent ? parent.full_name : '(unknown)'
76
170
  if is_alias_for
@@ -30,6 +30,11 @@ class RDoc::Context < RDoc::CodeObject
30
30
 
31
31
  attr_reader :attributes
32
32
 
33
+ ##
34
+ # Block params to be used in the next MethodAttr parsed under this context
35
+
36
+ attr_accessor :block_params
37
+
33
38
  ##
34
39
  # Constants defined
35
40
 
@@ -50,6 +55,11 @@ class RDoc::Context < RDoc::CodeObject
50
55
 
51
56
  attr_reader :includes
52
57
 
58
+ ##
59
+ # Modules this context is extended with
60
+
61
+ attr_reader :extends
62
+
53
63
  ##
54
64
  # Methods defined in this context
55
65
 
@@ -78,7 +88,7 @@ class RDoc::Context < RDoc::CodeObject
78
88
  attr_accessor :unmatched_alias_lists
79
89
 
80
90
  ##
81
- # Aliases that could not eventually be resolved.
91
+ # Aliases that could not be resolved.
82
92
 
83
93
  attr_reader :external_aliases
84
94
 
@@ -93,6 +103,11 @@ class RDoc::Context < RDoc::CodeObject
93
103
 
94
104
  attr_reader :methods_hash
95
105
 
106
+ ##
107
+ # Params to be used in the next MethodAttr parsed under this context
108
+
109
+ attr_accessor :params
110
+
96
111
  ##
97
112
  # Hash of registered constants.
98
113
 
@@ -129,6 +144,7 @@ class RDoc::Context < RDoc::CodeObject
129
144
  @aliases = []
130
145
  @requires = []
131
146
  @includes = []
147
+ @extends = []
132
148
  @constants = []
133
149
  @external_aliases = []
134
150
 
@@ -136,8 +152,12 @@ class RDoc::Context < RDoc::CodeObject
136
152
  # a method not yet encountered).
137
153
  @unmatched_alias_lists = {}
138
154
 
139
- @methods_hash = {}
155
+ @methods_hash = {}
140
156
  @constants_hash = {}
157
+
158
+ @params = nil
159
+
160
+ @store ||= nil
141
161
  end
142
162
 
143
163
  ##
@@ -260,12 +280,12 @@ class RDoc::Context < RDoc::CodeObject
260
280
  if full_name =~ /^(.+)::(\w+)$/ then
261
281
  name = $2
262
282
  ename = $1
263
- enclosing = RDoc::TopLevel.classes_hash[ename] ||
264
- RDoc::TopLevel.modules_hash[ename]
283
+ enclosing = @store.classes_hash[ename] || @store.modules_hash[ename]
265
284
  # HACK: crashes in actionpack/lib/action_view/helpers/form_helper.rb (metaprogramming)
266
285
  unless enclosing then
267
286
  # try the given name at top level (will work for the above example)
268
- enclosing = RDoc::TopLevel.classes_hash[given_name] || RDoc::TopLevel.modules_hash[given_name]
287
+ enclosing = @store.classes_hash[given_name] ||
288
+ @store.modules_hash[given_name]
269
289
  return enclosing if enclosing
270
290
  # not found: create the parent(s)
271
291
  names = ename.split('::')
@@ -304,7 +324,7 @@ class RDoc::Context < RDoc::CodeObject
304
324
  end
305
325
 
306
326
  # did we believe it was a module?
307
- mod = RDoc::TopLevel.modules_hash.delete superclass
327
+ mod = @store.modules_hash.delete superclass
308
328
 
309
329
  upgrade_to_class mod, RDoc::NormalClass, mod.parent if mod
310
330
 
@@ -312,7 +332,7 @@ class RDoc::Context < RDoc::CodeObject
312
332
  superclass = nil if superclass == full_name
313
333
  end
314
334
 
315
- klass = RDoc::TopLevel.classes_hash[full_name]
335
+ klass = @store.classes_hash[full_name]
316
336
 
317
337
  if klass then
318
338
  # if TopLevel, it may not be registered in the classes:
@@ -329,7 +349,7 @@ class RDoc::Context < RDoc::CodeObject
329
349
  end
330
350
  else
331
351
  # this is a new class
332
- mod = RDoc::TopLevel.modules_hash.delete full_name
352
+ mod = @store.modules_hash.delete full_name
333
353
 
334
354
  if mod then
335
355
  klass = upgrade_to_class mod, RDoc::NormalClass, enclosing
@@ -339,10 +359,12 @@ class RDoc::Context < RDoc::CodeObject
339
359
  klass = class_type.new name, superclass
340
360
 
341
361
  enclosing.add_class_or_module(klass, enclosing.classes_hash,
342
- RDoc::TopLevel.classes_hash)
362
+ @store.classes_hash)
343
363
  end
344
364
  end
345
365
 
366
+ klass.parent = self
367
+
346
368
  klass
347
369
  end
348
370
 
@@ -357,6 +379,7 @@ class RDoc::Context < RDoc::CodeObject
357
379
  mod.section = current_section # TODO declaring context? something is
358
380
  # wrong here...
359
381
  mod.parent = self
382
+ mod.store = @store
360
383
 
361
384
  unless @done_documenting then
362
385
  self_hash[mod.name] = mod
@@ -403,6 +426,15 @@ class RDoc::Context < RDoc::CodeObject
403
426
  include
404
427
  end
405
428
 
429
+ ##
430
+ # Adds extension module +ext+ which should be an RDoc::Extend
431
+
432
+ def add_extend ext
433
+ add_to @extends, ext
434
+
435
+ ext
436
+ end
437
+
406
438
  ##
407
439
  # Adds +method+ if not already there. If it is (as method or attribute),
408
440
  # updates the comment if it was empty.
@@ -416,6 +448,10 @@ class RDoc::Context < RDoc::CodeObject
416
448
 
417
449
  if known then
418
450
  known.comment = method.comment if known.comment.empty?
451
+ previously = ", previously in #{known.file}" unless
452
+ method.file == known.file
453
+ @store.rdoc.options.warn \
454
+ "Duplicate method #{known.full_name} in #{method.file}#{previously}"
419
455
  else
420
456
  @methods_hash[key] = method
421
457
  method.visibility = @visibility
@@ -435,9 +471,9 @@ class RDoc::Context < RDoc::CodeObject
435
471
  return mod if mod
436
472
 
437
473
  full_name = child_name name
438
- mod = RDoc::TopLevel.modules_hash[full_name] || class_type.new(name)
474
+ mod = @store.modules_hash[full_name] || class_type.new(name)
439
475
 
440
- add_class_or_module(mod, @modules, RDoc::TopLevel.modules_hash)
476
+ add_class_or_module mod, @modules, @store.modules_hash
441
477
  end
442
478
 
443
479
  ##
@@ -447,31 +483,34 @@ class RDoc::Context < RDoc::CodeObject
447
483
  def add_module_alias from, name, file
448
484
  return from if @done_documenting
449
485
 
450
- to_name = child_name(name)
486
+ to_name = child_name name
451
487
 
452
488
  # if we already know this name, don't register an alias:
453
489
  # see the metaprogramming in lib/active_support/basic_object.rb,
454
- # where we already know BasicObject as a class when we find
490
+ # where we already know BasicObject is a class when we find
455
491
  # BasicObject = BlankSlate
456
- return from if RDoc::TopLevel.find_class_or_module(to_name)
492
+ return from if @store.find_class_or_module to_name
457
493
 
458
- if from.module? then
459
- RDoc::TopLevel.modules_hash[to_name] = from
460
- @modules[name] = from
494
+ to = from.dup
495
+ to.name = name
496
+ to.full_name = nil
497
+
498
+ if to.module? then
499
+ @store.modules_hash[to_name] = to
500
+ @modules[name] = to
461
501
  else
462
- RDoc::TopLevel.classes_hash[to_name] = from
463
- @classes[name] = from
502
+ @store.classes_hash[to_name] = to
503
+ @classes[name] = to
464
504
  end
465
505
 
466
- # HACK: register a constant for this alias:
467
- # constant value and comment will be updated after,
468
- # when the Ruby parser adds the constant
469
- const = RDoc::Constant.new name, nil, ''
506
+ # Registers a constant for this alias. The constant value and comment
507
+ # will be updated later, when the Ruby parser adds the constant
508
+ const = RDoc::Constant.new name, nil, to.comment
470
509
  const.record_location file
471
510
  const.is_alias_for = from
472
511
  add_constant const
473
512
 
474
- from
513
+ to
475
514
  end
476
515
 
477
516
  ##
@@ -497,7 +536,7 @@ class RDoc::Context < RDoc::CodeObject
497
536
 
498
537
  def add_section title, comment = nil
499
538
  if section = @sections[title] then
500
- section.comment = comment if comment
539
+ section.add_comment comment if comment
501
540
  else
502
541
  section = Section.new self, title, comment
503
542
  @sections[title] = section
@@ -509,9 +548,11 @@ class RDoc::Context < RDoc::CodeObject
509
548
  ##
510
549
  # Adds +thing+ to the collection +array+
511
550
 
512
- def add_to(array, thing)
551
+ def add_to array, thing
513
552
  array << thing if @document_self
514
- thing.parent = self
553
+
554
+ thing.parent = self
555
+ thing.store = @store if @store
515
556
  thing.section = current_section
516
557
  end
517
558
 
@@ -521,7 +562,7 @@ class RDoc::Context < RDoc::CodeObject
521
562
  # This means any of: comment, aliases, methods, attributes, external
522
563
  # aliases, require, constant.
523
564
  #
524
- # Includes are also checked unless <tt>includes == false</tt>.
565
+ # Includes and extends are also checked unless <tt>includes == false</tt>.
525
566
 
526
567
  def any_content(includes = true)
527
568
  @any_content ||= !(
@@ -533,7 +574,7 @@ class RDoc::Context < RDoc::CodeObject
533
574
  @requires.empty? &&
534
575
  @constants.empty?
535
576
  )
536
- @any_content || (includes && !@includes.empty?)
577
+ @any_content || (includes && !(@includes + @extends).empty? )
537
578
  end
538
579
 
539
580
  ##
@@ -616,6 +657,9 @@ class RDoc::Context < RDoc::CodeObject
616
657
  ##
617
658
  # Iterator for ancestors for duck-typing. Does nothing. See
618
659
  # RDoc::ClassModule#each_ancestor.
660
+ #
661
+ # This method exists to make it easy to work with Context subclasses that
662
+ # aren't part of RDoc.
619
663
 
620
664
  def each_ancestor # :nodoc:
621
665
  end
@@ -648,6 +692,13 @@ class RDoc::Context < RDoc::CodeObject
648
692
  @includes.each do |i| yield i end
649
693
  end
650
694
 
695
+ ##
696
+ # Iterator for extension modules
697
+
698
+ def each_extend # :yields: extend
699
+ @extends.each do |e| yield e end
700
+ end
701
+
651
702
  ##
652
703
  # Iterator for methods
653
704
 
@@ -671,9 +722,9 @@ class RDoc::Context < RDoc::CodeObject
671
722
  return enum_for __method__ unless block_given?
672
723
 
673
724
  constants = @constants.group_by do |constant| constant.section end
674
- constants.default = []
675
-
676
725
  attributes = @attributes.group_by do |attribute| attribute.section end
726
+
727
+ constants.default = []
677
728
  attributes.default = []
678
729
 
679
730
  sort_sections.each do |section|
@@ -748,8 +799,8 @@ class RDoc::Context < RDoc::CodeObject
748
799
  ##
749
800
  # Finds a file with +name+ in this context
750
801
 
751
- def find_file_named(name)
752
- top_level.class.find_file_named(name)
802
+ def find_file_named name
803
+ @store.find_file_named name
753
804
  end
754
805
 
755
806
  ##
@@ -819,21 +870,21 @@ class RDoc::Context < RDoc::CodeObject
819
870
  # look for a class or module 'symbol'
820
871
  case symbol
821
872
  when /^::/ then
822
- result = RDoc::TopLevel.find_class_or_module(symbol)
873
+ result = @store.find_class_or_module symbol
823
874
  when /^(\w+):+(.+)$/
824
875
  suffix = $2
825
876
  top = $1
826
877
  searched = self
827
- loop do
878
+ while searched do
828
879
  mod = searched.find_module_named(top)
829
880
  break unless mod
830
- result = RDoc::TopLevel.find_class_or_module(mod.full_name + '::' + suffix)
881
+ result = @store.find_class_or_module "#{mod.full_name}::#{suffix}"
831
882
  break if result || searched.is_a?(RDoc::TopLevel)
832
883
  searched = searched.parent
833
884
  end
834
885
  else
835
886
  searched = self
836
- loop do
887
+ while searched do
837
888
  result = searched.find_module_named(symbol)
838
889
  break if result || searched.is_a?(RDoc::TopLevel)
839
890
  searched = searched.parent
@@ -1079,8 +1130,8 @@ class RDoc::Context < RDoc::CodeObject
1079
1130
  end
1080
1131
 
1081
1132
  ##
1082
- # Sorts sections alphabetically (default) or in TomDoc fasion (none, Public,
1083
- # Internal, Deprecated)
1133
+ # Sorts sections alphabetically (default) or in TomDoc fashion (none,
1134
+ # Public, Internal, Deprecated)
1084
1135
 
1085
1136
  def sort_sections
1086
1137
  titles = @sections.map { |title, _| title }
@@ -1122,10 +1173,11 @@ class RDoc::Context < RDoc::CodeObject
1122
1173
  enclosing.modules_hash.delete mod.name
1123
1174
 
1124
1175
  klass = RDoc::ClassModule.from_module class_type, mod
1176
+ klass.store = @store
1125
1177
 
1126
1178
  # if it was there, then we keep it even if done_documenting
1127
- RDoc::TopLevel.classes_hash[mod.full_name] = klass
1128
- enclosing.classes_hash[mod.name] = klass
1179
+ @store.classes_hash[mod.full_name] = klass
1180
+ enclosing.classes_hash[mod.name] = klass
1129
1181
 
1130
1182
  klass
1131
1183
  end