rdoc 6.17.0 → 8.1.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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. data/lib/rdoc/servlet.rb +0 -452
@@ -1,411 +1,424 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Abstract class representing either a method or an attribute.
4
-
5
- class RDoc::MethodAttr < RDoc::CodeObject
6
-
7
- include Comparable
8
-
2
+ module RDoc
9
3
  ##
10
- # Name of this method/attribute.
4
+ # Abstract class representing either a method or an attribute.
11
5
 
12
- attr_accessor :name
6
+ class MethodAttr < CodeObject
13
7
 
14
- ##
15
- # public, protected, private
8
+ include Comparable
16
9
 
17
- attr_accessor :visibility
10
+ ##
11
+ # Name of this method/attribute.
18
12
 
19
- ##
20
- # Is this a singleton method/attribute?
13
+ attr_accessor :name
21
14
 
22
- attr_accessor :singleton
15
+ ##
16
+ # public, protected, private
23
17
 
24
- ##
25
- # Source file token stream
18
+ attr_accessor :visibility
26
19
 
27
- attr_reader :text
20
+ ##
21
+ # Is this a singleton method/attribute?
28
22
 
29
- ##
30
- # Array of other names for this method/attribute
23
+ attr_accessor :singleton
31
24
 
32
- attr_reader :aliases
25
+ ##
26
+ # Array of other names for this method/attribute
33
27
 
34
- ##
35
- # The method/attribute we're aliasing
28
+ attr_reader :aliases
36
29
 
37
- attr_accessor :is_alias_for
30
+ ##
31
+ # The method/attribute we're aliasing
38
32
 
39
- #--
40
- # The attributes below are for AnyMethod only.
41
- # They are left here for the time being to
42
- # allow ri to operate.
43
- # TODO modify ri to avoid calling these on attributes.
44
- #++
33
+ attr_accessor :is_alias_for
45
34
 
46
- ##
47
- # Parameters yielded by the called block
35
+ #--
36
+ # The attributes below are for AnyMethod only.
37
+ # They are left here for the time being to
38
+ # allow ri to operate.
39
+ # TODO modify ri to avoid calling these on attributes.
40
+ #++
48
41
 
49
- attr_reader :block_params
42
+ ##
43
+ # Parameters yielded by the called block
50
44
 
51
- ##
52
- # Parameters for this method
45
+ attr_reader :block_params
53
46
 
54
- attr_accessor :params
47
+ ##
48
+ # Parameters for this method
55
49
 
56
- ##
57
- # Different ways to call this method
50
+ attr_accessor :params
58
51
 
59
- attr_accessor :call_seq
52
+ ##
53
+ # Different ways to call this method
60
54
 
61
- ##
62
- # The call_seq or the param_seq with method name, if there is no call_seq.
55
+ attr_accessor :call_seq
63
56
 
64
- attr_reader :arglists
57
+ ##
58
+ # RBS type signature lines from inline annotations or loaded .rbs files.
59
+ # Each entry is one overload or type expression.
65
60
 
66
- ##
67
- # Creates a new MethodAttr from token stream +text+ and method or attribute
68
- # name +name+.
69
- #
70
- # Usually this is called by super from a subclass.
71
-
72
- def initialize(text, name, singleton: false)
73
- super()
74
-
75
- @text = text
76
- @name = name
77
-
78
- @aliases = []
79
- @is_alias_for = nil
80
- @parent_name = nil
81
- @singleton = singleton
82
- @visibility = :public
83
- @see = false
84
-
85
- @arglists = nil
86
- @block_params = nil
87
- @call_seq = nil
88
- @params = nil
89
- end
61
+ attr_accessor :type_signature_lines
90
62
 
91
- ##
92
- # Resets cached data for the object so it can be rebuilt by accessor methods
63
+ ##
64
+ # The call_seq or the param_seq with method name, if there is no call_seq.
93
65
 
94
- def initialize_copy(other) # :nodoc:
95
- @full_name = nil
96
- end
66
+ attr_reader :arglists
97
67
 
98
- def initialize_visibility # :nodoc:
99
- super
100
- @see = nil
101
- end
68
+ ##
69
+ # Creates a new MethodAttr with method or attribute
70
+ # name +name+.
71
+ #
72
+ # Usually this is called by super from a subclass.
102
73
 
103
- ##
104
- # Order by #singleton then #name
74
+ def initialize(name, singleton: false)
75
+ super()
105
76
 
106
- def <=>(other)
107
- return unless other.respond_to?(:singleton) &&
108
- other.respond_to?(:name)
77
+ @name = name
109
78
 
110
- [@singleton ? 0 : 1, name_ord_range, name] <=>
111
- [other.singleton ? 0 : 1, other.name_ord_range, other.name]
112
- end
79
+ @aliases = []
80
+ @is_alias_for = nil
81
+ @parent_name = nil
82
+ @singleton = singleton
83
+ @visibility = :public
84
+ @see = false
113
85
 
114
- def ==(other) # :nodoc:
115
- equal?(other) or self.class == other.class and full_name == other.full_name
116
- end
86
+ @arglists = nil
87
+ @block_params = nil
88
+ @call_seq = nil
89
+ @params = nil
90
+ @type_signature_lines = nil
91
+ end
117
92
 
118
- ##
119
- # A method/attribute is documented if any of the following is true:
120
- # - it was marked with :nodoc:;
121
- # - it has a comment;
122
- # - it is an alias for a documented method;
123
- # - it has a +#see+ method that is documented.
124
-
125
- def documented?
126
- super or
127
- (is_alias_for and is_alias_for.documented?) or
128
- (see and see.documented?)
129
- end
93
+ ##
94
+ # Resets cached data for the object so it can be rebuilt by accessor methods
130
95
 
131
- ##
132
- # A method/attribute to look at,
133
- # in particular if this method/attribute has no documentation.
134
- #
135
- # It can be a method/attribute of the superclass or of an included module,
136
- # including the Kernel module, which is always appended to the included
137
- # modules.
138
- #
139
- # Returns +nil+ if there is no such method/attribute.
140
- # The +#is_alias_for+ method/attribute, if any, is not included.
141
- #
142
- # Templates may generate a "see also ..." if this method/attribute
143
- # has documentation, and "see ..." if it does not.
144
-
145
- def see
146
- @see = find_see if @see == false
147
- @see
148
- end
96
+ def initialize_copy(other) # :nodoc:
97
+ @full_name = nil
98
+ end
149
99
 
150
- ##
151
- # Sets the store for this class or module and its contained code objects.
100
+ def initialize_visibility # :nodoc:
101
+ super
102
+ @see = nil
103
+ end
152
104
 
153
- def store=(store)
154
- super
105
+ ##
106
+ # Order by #singleton then #name
155
107
 
156
- @file = @store.add_file @file.full_name if @file
157
- end
108
+ def <=>(other)
109
+ return unless other.respond_to?(:singleton) &&
110
+ other.respond_to?(:name)
158
111
 
159
- def find_see # :nodoc:
160
- return nil if singleton || is_alias_for
112
+ [@singleton ? 0 : 1, name_ord_range, name] <=>
113
+ [other.singleton ? 0 : 1, other.name_ord_range, other.name]
114
+ end
161
115
 
162
- # look for the method
163
- other = find_method_or_attribute name
164
- return other if other
116
+ def ==(other) # :nodoc:
117
+ equal?(other) or self.class == other.class and full_name == other.full_name
118
+ end
165
119
 
166
- # if it is a setter, look for a getter
167
- return nil unless name =~ /[a-z_]=$/i # avoid == or ===
168
- return find_method_or_attribute name[0..-2]
169
- end
120
+ ##
121
+ # A method/attribute is documented if any of the following is true:
122
+ # - it was marked with :nodoc:;
123
+ # - it has a comment;
124
+ # - it is an alias for a documented method;
125
+ # - it has a +#see+ method that is documented.
126
+
127
+ def documented?
128
+ super or
129
+ (is_alias_for and is_alias_for.documented?) or
130
+ (see and see.documented?)
131
+ end
170
132
 
171
- def find_method_or_attribute(name) # :nodoc:
172
- return nil unless parent.respond_to? :ancestors
133
+ ##
134
+ # A method/attribute to look at,
135
+ # in particular if this method/attribute has no documentation.
136
+ #
137
+ # It can be a method/attribute of the superclass or of an included module,
138
+ # including the Kernel module, which is always appended to the included
139
+ # modules.
140
+ #
141
+ # Returns +nil+ if there is no such method/attribute.
142
+ # The +#is_alias_for+ method/attribute, if any, is not included.
143
+ #
144
+ # Templates may generate a "see also ..." if this method/attribute
145
+ # has documentation, and "see ..." if it does not.
146
+
147
+ def see
148
+ @see = find_see if @see == false
149
+ @see
150
+ end
173
151
 
174
- searched = parent.ancestors
175
- kernel = @store.modules_hash['Kernel']
152
+ ##
153
+ # Sets the store for this class or module and its contained code objects.
176
154
 
177
- searched << kernel if kernel &&
178
- parent != kernel && !searched.include?(kernel)
155
+ def store=(store)
156
+ super
179
157
 
180
- searched.each do |ancestor|
181
- next if String === ancestor
182
- next if parent == ancestor
158
+ @file = @store.add_file @file.full_name if @file
159
+ end
183
160
 
184
- other = ancestor.find_method_named('#' + name) ||
185
- ancestor.find_attribute_named(name)
161
+ def find_see # :nodoc:
162
+ return nil if singleton || is_alias_for
186
163
 
164
+ # look for the method
165
+ other = find_method_or_attribute name
187
166
  return other if other
167
+
168
+ # if it is a setter, look for a getter
169
+ return nil unless name =~ /[a-z_]=$/i # avoid == or ===
170
+ return find_method_or_attribute name[0..-2]
188
171
  end
189
172
 
190
- nil
191
- end
173
+ def find_method_or_attribute(name) # :nodoc:
174
+ return nil unless parent.respond_to? :ancestors
192
175
 
193
- ##
194
- # Abstract method. Contexts in their building phase call this
195
- # to register a new alias for this known method/attribute.
196
- #
197
- # - creates a new AnyMethod/Attribute named <tt>an_alias.new_name</tt>;
198
- # - adds +self+ as an alias for the new method or attribute
199
- # - adds the method or attribute to #aliases
200
- # - adds the method or attribute to +context+.
201
-
202
- def add_alias(an_alias, context)
203
- raise NotImplementedError
204
- end
176
+ searched = parent.ancestors
177
+ kernel = @store.modules_hash['Kernel']
205
178
 
206
- ##
207
- # HTML fragment reference for this method
179
+ searched << kernel if kernel &&
180
+ parent != kernel && !searched.include?(kernel)
208
181
 
209
- def aref
210
- type = singleton ? 'c' : 'i'
211
- # % characters are not allowed in html names => dash instead
212
- "#{aref_prefix}-#{type}-#{html_name}"
213
- end
182
+ searched.each do |ancestor|
183
+ next if String === ancestor
184
+ next if parent == ancestor
214
185
 
215
- ##
216
- # Prefix for +aref+, defined by subclasses.
186
+ other = ancestor.find_method_named('#' + name) ||
187
+ ancestor.find_attribute_named(name)
217
188
 
218
- def aref_prefix
219
- raise NotImplementedError
220
- end
189
+ return other if other
190
+ end
221
191
 
222
- ##
223
- # Attempts to sanitize the content passed by the Ruby parser:
224
- # remove outer parentheses, etc.
192
+ nil
193
+ end
194
+
195
+ ##
196
+ # Abstract method. Contexts in their building phase call this
197
+ # to register a new alias for this known method/attribute.
198
+ #
199
+ # - creates a new AnyMethod/Attribute named <tt>an_alias.new_name</tt>;
200
+ # - adds +self+ as an alias for the new method or attribute
201
+ # - adds the method or attribute to #aliases
202
+ # - adds the method or attribute to +context+.
203
+
204
+ def add_alias(an_alias, context)
205
+ raise NotImplementedError
206
+ end
225
207
 
226
- def block_params=(value)
227
- # 'yield.to_s' or 'assert yield, msg'
228
- return @block_params = '' if value =~ /^[\.,]/
208
+ ##
209
+ # HTML fragment reference for this method
229
210
 
230
- # remove trailing 'if/unless ...'
231
- return @block_params = '' if value =~ /^(if|unless)\s/
211
+ def aref
212
+ type = singleton ? 'c' : 'i'
213
+ # % characters are not allowed in html names => dash instead
214
+ "#{aref_prefix}-#{type}-#{html_name}"
215
+ end
232
216
 
233
- value = $1.strip if value =~ /^(.+)\s(if|unless)\s/
217
+ ##
218
+ # Prefix for +aref+, defined by subclasses.
234
219
 
235
- # outer parentheses
236
- value = $1 if value =~ /^\s*\((.*)\)\s*$/
237
- value = value.strip
220
+ def aref_prefix
221
+ raise NotImplementedError
222
+ end
238
223
 
239
- # proc/lambda
240
- return @block_params = $1 if value =~ /^(proc|lambda)(\s*\{|\sdo)/
224
+ ##
225
+ # Attempts to sanitize the content passed by the Ruby parser:
226
+ # remove outer parentheses, etc.
241
227
 
242
- # surrounding +...+ or [...]
243
- value = $1.strip if value =~ /^\+(.*)\+$/
244
- value = $1.strip if value =~ /^\[(.*)\]$/
228
+ def block_params=(value)
229
+ # 'yield.to_s' or 'assert yield, msg'
230
+ return @block_params = '' if value =~ /^[\.,]/
245
231
 
246
- return @block_params = '' if value.empty?
232
+ # remove trailing 'if/unless ...'
233
+ return @block_params = '' if value =~ /^(if|unless)\s/
247
234
 
248
- # global variable
249
- return @block_params = 'str' if value =~ /^\$[&0-9]$/
235
+ value = $1.strip if value =~ /^(.+)\s(if|unless)\s/
250
236
 
251
- # wipe out array/hash indices
252
- value.gsub!(/(\w)\[[^\[]+\]/, '\1')
237
+ # outer parentheses
238
+ value = $1 if value =~ /^\s*\((.*)\)\s*$/
239
+ value = value.strip
253
240
 
254
- # remove @ from class/instance variables
255
- value.gsub!(/@@?([a-z0-9_]+)/, '\1')
241
+ # proc/lambda
242
+ return @block_params = $1 if value =~ /^(proc|lambda)(\s*\{|\sdo)/
256
243
 
257
- # method calls => method name
258
- value.gsub!(/([A-Z:a-z0-9_]+)\.([a-z0-9_]+)(\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*)?/) do
259
- case $2
260
- when 'to_s' then $1
261
- when 'const_get' then 'const'
262
- when 'new' then
263
- $1.split('::').last. # ClassName => class_name
264
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
265
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
266
- downcase
267
- else
268
- $2
269
- end
270
- end
244
+ # surrounding +...+ or [...]
245
+ value = $1.strip if value =~ /^\+(.*)\+$/
246
+ value = $1.strip if value =~ /^\[(.*)\]$/
271
247
 
272
- # class prefixes
273
- value.gsub!(/[A-Za-z0-9_:]+::/, '')
248
+ return @block_params = '' if value.empty?
274
249
 
275
- # simple expressions
276
- value = $1 if value =~ /^([a-z0-9_]+)\s*[-*+\/]/
250
+ # global variable
251
+ return @block_params = 'str' if value =~ /^\$[&0-9]$/
277
252
 
278
- @block_params = value.strip
279
- end
253
+ # wipe out array/hash indices
254
+ value.gsub!(/(\w)\[[^\[]+\]/, '\1')
280
255
 
281
- ##
282
- # HTML id-friendly method/attribute name
256
+ # remove @ from class/instance variables
257
+ value.gsub!(/@@?([a-z0-9_]+)/, '\1')
283
258
 
284
- def html_name
285
- require 'cgi/escape'
286
- require 'cgi/util' unless defined?(CGI::EscapeExt)
259
+ # method calls => method name
260
+ value.gsub!(/([A-Z:a-z0-9_]+)\.([a-z0-9_]+)(\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*)?/) do
261
+ case $2
262
+ when 'to_s' then $1
263
+ when 'const_get' then 'const'
264
+ when 'new'
265
+ $1.split('::').last. # ClassName => class_name
266
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
267
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
268
+ downcase
269
+ else
270
+ $2
271
+ end
272
+ end
287
273
 
288
- CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
289
- end
274
+ # class prefixes
275
+ value.gsub!(/[A-Za-z0-9_:]+::/, '')
290
276
 
291
- ##
292
- # Full method/attribute name including namespace
277
+ # simple expressions
278
+ value = $1 if value =~ /^([a-z0-9_]+)\s*[-*+\/]/
293
279
 
294
- def full_name
295
- @full_name ||= "#{parent_name}#{pretty_name}"
296
- end
280
+ @block_params = value.strip
281
+ end
297
282
 
298
- def inspect # :nodoc:
299
- alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
300
- visibility = self.visibility
301
- visibility = "forced #{visibility}" if force_documentation
302
- "#<%s:0x%x %s (%s)%s>" % [
303
- self.class, object_id,
304
- full_name,
305
- visibility,
306
- alias_for,
307
- ]
308
- end
283
+ ##
284
+ # HTML id-friendly method/attribute name
309
285
 
310
- ##
311
- # '::' for a class method/attribute, '#' for an instance method.
286
+ def html_name
287
+ require 'cgi/escape'
288
+ require 'cgi/util' unless defined?(CGI::EscapeExt)
312
289
 
313
- def name_prefix
314
- @singleton ? '::' : '#'
315
- end
290
+ CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
291
+ end
316
292
 
317
- ##
318
- # Method/attribute name with class/instance indicator
293
+ ##
294
+ # Full method/attribute name including namespace
319
295
 
320
- def pretty_name
321
- "#{name_prefix}#{@name}"
322
- end
296
+ def full_name
297
+ @full_name ||= "#{parent_name}#{pretty_name}"
298
+ end
323
299
 
324
- ##
325
- # Type of method/attribute (class or instance)
300
+ def inspect # :nodoc:
301
+ alias_for =
302
+ if @is_alias_for.respond_to? :name
303
+ " (alias for #{@is_alias_for.name})"
304
+ elsif Array === @is_alias_for
305
+ " (alias for #{@is_alias_for.last})"
306
+ end
307
+ visibility = self.visibility
308
+ visibility = "forced #{visibility}" if force_documentation
309
+ "#<%s:0x%x %s (%s)%s>" % [
310
+ self.class, object_id,
311
+ full_name,
312
+ visibility,
313
+ alias_for,
314
+ ]
315
+ end
326
316
 
327
- def type
328
- singleton ? 'class' : 'instance'
329
- end
317
+ ##
318
+ # '::' for a class method/attribute, '#' for an instance method.
330
319
 
331
- ##
332
- # Path to this method for use with HTML generator output.
320
+ def name_prefix
321
+ @singleton ? '::' : '#'
322
+ end
333
323
 
334
- def path
335
- "#{@parent.path}##{aref}"
336
- end
324
+ ##
325
+ # Method/attribute name with class/instance indicator
337
326
 
338
- ##
339
- # Name of our parent with special handling for un-marshaled methods
327
+ def pretty_name
328
+ "#{name_prefix}#{@name}"
329
+ end
340
330
 
341
- def parent_name
342
- @parent_name || super
343
- end
331
+ ##
332
+ # Type of method/attribute (class or instance)
344
333
 
345
- def pretty_print(q) # :nodoc:
346
- alias_for =
347
- if @is_alias_for.respond_to? :name then
348
- "alias for #{@is_alias_for.name}"
349
- elsif Array === @is_alias_for then
350
- "alias for #{@is_alias_for.last}"
351
- end
334
+ def type
335
+ singleton ? 'class' : 'instance'
336
+ end
352
337
 
353
- q.group 2, "[#{self.class.name} #{full_name} #{visibility}", "]" do
354
- if alias_for then
355
- q.breakable
356
- q.text alias_for
357
- end
338
+ ##
339
+ # Path to this method for use with HTML generator output.
358
340
 
359
- if text then
360
- q.breakable
361
- q.text "text:"
362
- q.breakable
363
- q.pp @text
364
- end
341
+ def path
342
+ "#{@parent.path}##{aref}"
343
+ end
344
+
345
+ ##
346
+ # Name of our parent with special handling for un-marshaled methods
347
+
348
+ def parent_name
349
+ @parent_name || super
350
+ end
365
351
 
366
- unless comment.empty? then
367
- q.breakable
368
- q.text "comment:"
369
- q.breakable
370
- q.pp @comment
352
+ def pretty_print(q) # :nodoc:
353
+ alias_for =
354
+ if @is_alias_for.respond_to? :name
355
+ "alias for #{@is_alias_for.name}"
356
+ elsif Array === @is_alias_for
357
+ "alias for #{@is_alias_for.last}"
358
+ end
359
+
360
+ q.group 2, "[#{self.class.name} #{full_name} #{visibility}", "]" do
361
+ if alias_for
362
+ q.breakable
363
+ q.text alias_for
364
+ end
365
+
366
+ unless comment.empty?
367
+ q.breakable
368
+ q.text "comment:"
369
+ q.breakable
370
+ q.pp @comment
371
+ end
371
372
  end
372
373
  end
373
- end
374
374
 
375
- ##
376
- # Used by RDoc::Generator::JsonIndex to create a record for the search
377
- # engine.
378
-
379
- def search_record
380
- [
381
- @name,
382
- full_name,
383
- @name,
384
- @parent.full_name,
385
- path,
386
- params,
387
- snippet(@comment),
388
- ]
389
- end
375
+ ##
376
+ # Used by RDoc::Generator::JsonIndex to create a record for the search
377
+ # engine.
378
+ #
379
+ # TODO: Remove this method after dropping the darkfish theme and JsonIndex generator.
380
+ # Use #search_snippet instead for getting documentation snippets.
381
+
382
+ def search_record
383
+ [
384
+ @name,
385
+ full_name,
386
+ @name,
387
+ @parent.full_name,
388
+ path,
389
+ params,
390
+ search_snippet,
391
+ ]
392
+ end
393
+
394
+ ##
395
+ # Returns an HTML snippet of the comment for search results.
396
+
397
+ def search_snippet
398
+ return '' if @comment.empty?
390
399
 
391
- def to_s # :nodoc:
392
- if @is_alias_for
393
- "#{self.class.name}: #{full_name} -> #{is_alias_for}"
394
- else
395
- "#{self.class.name}: #{full_name}"
400
+ snippet(@comment)
401
+ end
402
+
403
+ def to_s # :nodoc:
404
+ if @is_alias_for
405
+ "#{self.class.name}: #{full_name} -> #{is_alias_for}"
406
+ else
407
+ "#{self.class.name}: #{full_name}"
408
+ end
396
409
  end
397
- end
398
410
 
399
- def name_ord_range # :nodoc:
400
- case name.ord
401
- when 0..64 # anything below "A"
402
- 1
403
- when 91..96 # the symbols between "Z" and "a"
404
- 2
405
- when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
406
- 3
407
- else # everythig else can be sorted as normal
408
- 4
411
+ def name_ord_range # :nodoc:
412
+ case name.ord
413
+ when 0..64 # anything below "A"
414
+ 1
415
+ when 91..96 # the symbols between "Z" and "a"
416
+ 2
417
+ when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
418
+ 3
419
+ else # everythig else can be sorted as normal
420
+ 4
421
+ end
409
422
  end
410
423
  end
411
424
  end