rdoc 7.2.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 (150) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -7
  3. data/LICENSE.rdoc +4 -0
  4. data/README.md +43 -2
  5. data/RI.md +75 -75
  6. data/doc/markup_reference/markdown.md +104 -3
  7. data/exe/rdoc +2 -2
  8. data/lib/rdoc/code_object/alias.rb +70 -74
  9. data/lib/rdoc/code_object/any_method.rb +305 -298
  10. data/lib/rdoc/code_object/attr.rb +150 -143
  11. data/lib/rdoc/code_object/class_module.rb +801 -765
  12. data/lib/rdoc/code_object/constant.rb +178 -150
  13. data/lib/rdoc/code_object/context/section.rb +133 -160
  14. data/lib/rdoc/code_object/context.rb +925 -952
  15. data/lib/rdoc/code_object/extend.rb +7 -5
  16. data/lib/rdoc/code_object/include.rb +7 -5
  17. data/lib/rdoc/code_object/method_attr.rb +325 -324
  18. data/lib/rdoc/code_object/mixin.rb +97 -95
  19. data/lib/rdoc/code_object/normal_class.rb +77 -78
  20. data/lib/rdoc/code_object/normal_module.rb +61 -59
  21. data/lib/rdoc/code_object/require.rb +23 -39
  22. data/lib/rdoc/code_object/single_class.rb +21 -19
  23. data/lib/rdoc/code_object/top_level.rb +212 -213
  24. data/lib/rdoc/code_object.rb +305 -305
  25. data/lib/rdoc/comment.rb +274 -337
  26. data/lib/rdoc/cross_reference.rb +194 -212
  27. data/lib/rdoc/encoding.rb +105 -103
  28. data/lib/rdoc/erb_partial.rb +13 -11
  29. data/lib/rdoc/erbio.rb +29 -27
  30. data/lib/rdoc/generator/aliki.rb +165 -140
  31. data/lib/rdoc/generator/darkfish.rb +647 -631
  32. data/lib/rdoc/generator/json_index.rb +233 -229
  33. data/lib/rdoc/generator/markup.rb +165 -122
  34. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  35. data/lib/rdoc/generator/pot/po.rb +52 -51
  36. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  37. data/lib/rdoc/generator/pot.rb +85 -81
  38. data/lib/rdoc/generator/ri.rb +23 -19
  39. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  40. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  41. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  42. data/lib/rdoc/generator/template/aliki/_head.rhtml +11 -11
  43. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  44. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  45. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  46. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  47. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
  48. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  49. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  50. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  51. data/lib/rdoc/generator/template/aliki/class.rhtml +56 -46
  52. data/lib/rdoc/generator/template/aliki/css/rdoc.css +538 -283
  53. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  54. data/lib/rdoc/generator/template/aliki/js/aliki.js +80 -102
  55. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  57. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  58. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  59. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  60. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  61. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  62. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  63. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  64. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  65. data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
  66. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
  67. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  68. data/lib/rdoc/generator.rb +48 -46
  69. data/lib/rdoc/i18n/locale.rb +99 -95
  70. data/lib/rdoc/i18n/text.rb +109 -105
  71. data/lib/rdoc/i18n.rb +7 -5
  72. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  73. data/lib/rdoc/markdown.kpeg +30 -21
  74. data/lib/rdoc/markdown.rb +329 -151
  75. data/lib/rdoc/markup/block_quote.rb +12 -8
  76. data/lib/rdoc/markup/document.rb +127 -123
  77. data/lib/rdoc/markup/formatter.rb +215 -221
  78. data/lib/rdoc/markup/heading.rb +1 -4
  79. data/lib/rdoc/markup/include.rb +33 -29
  80. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  81. data/lib/rdoc/markup/inline_parser.rb +281 -277
  82. data/lib/rdoc/markup/list.rb +80 -88
  83. data/lib/rdoc/markup/list_item.rb +73 -85
  84. data/lib/rdoc/markup/paragraph.rb +23 -19
  85. data/lib/rdoc/markup/parser.rb +501 -497
  86. data/lib/rdoc/markup/pre_process.rb +284 -305
  87. data/lib/rdoc/markup/raw.rb +2 -2
  88. data/lib/rdoc/markup/rule.rb +16 -12
  89. data/lib/rdoc/markup/to_ansi.rb +143 -139
  90. data/lib/rdoc/markup/to_bs.rb +72 -68
  91. data/lib/rdoc/markup/to_html.rb +600 -493
  92. data/lib/rdoc/markup/to_html_crossref.rb +221 -191
  93. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  94. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  95. data/lib/rdoc/markup/to_label.rb +63 -59
  96. data/lib/rdoc/markup/to_markdown.rb +212 -208
  97. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  98. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  99. data/lib/rdoc/markup/to_test.rb +60 -56
  100. data/lib/rdoc/markup/to_tt_only.rb +83 -86
  101. data/lib/rdoc/markup/verbatim.rb +62 -58
  102. data/lib/rdoc/markup.rb +198 -196
  103. data/lib/rdoc/options.rb +1063 -1076
  104. data/lib/rdoc/parser/c.rb +1039 -1036
  105. data/lib/rdoc/parser/changelog.rb +319 -315
  106. data/lib/rdoc/parser/markdown.rb +17 -13
  107. data/lib/rdoc/parser/rbs.rb +279 -0
  108. data/lib/rdoc/parser/rd.rb +17 -13
  109. data/lib/rdoc/parser/ruby.rb +1231 -2222
  110. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  111. data/lib/rdoc/parser/simple.rb +31 -27
  112. data/lib/rdoc/parser/text.rb +12 -8
  113. data/lib/rdoc/parser.rb +230 -221
  114. data/lib/rdoc/rbs_helper.rb +186 -0
  115. data/lib/rdoc/rd/inline.rb +57 -53
  116. data/lib/rdoc/rd.rb +90 -88
  117. data/lib/rdoc/rdoc.rb +547 -366
  118. data/lib/rdoc/ri/driver.rb +1141 -1130
  119. data/lib/rdoc/ri/formatter.rb +7 -3
  120. data/lib/rdoc/ri/paths.rb +140 -136
  121. data/lib/rdoc/ri/servlet.rb +456 -0
  122. data/lib/rdoc/ri/store.rb +4 -2
  123. data/lib/rdoc/ri/task.rb +55 -51
  124. data/lib/rdoc/ri.rb +14 -11
  125. data/lib/rdoc/rubygems_hook.rb +194 -192
  126. data/lib/rdoc/server.rb +462 -0
  127. data/lib/rdoc/stats/normal.rb +46 -42
  128. data/lib/rdoc/stats/quiet.rb +39 -35
  129. data/lib/rdoc/stats/verbose.rb +35 -31
  130. data/lib/rdoc/stats.rb +363 -338
  131. data/lib/rdoc/store.rb +919 -725
  132. data/lib/rdoc/task.rb +260 -255
  133. data/lib/rdoc/text.rb +130 -245
  134. data/lib/rdoc/token_stream.rb +101 -115
  135. data/lib/rdoc/tom_doc.rb +203 -201
  136. data/lib/rdoc/version.rb +1 -1
  137. data/lib/rdoc.rb +35 -7
  138. data/lib/rubygems_plugin.rb +2 -11
  139. data/rdoc-logo.svg +43 -0
  140. data/rdoc.gemspec +6 -4
  141. metadata +36 -20
  142. data/lib/rdoc/code_object/anon_class.rb +0 -10
  143. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  144. data/lib/rdoc/code_object/meta_method.rb +0 -6
  145. data/lib/rdoc/markdown/literals.kpeg +0 -21
  146. data/lib/rdoc/markdown/literals.rb +0 -454
  147. data/lib/rdoc/parser/prism_ruby.rb +0 -1112
  148. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  149. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  150. data/lib/rdoc/servlet.rb +0 -452
@@ -1,342 +1,321 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Handle common directives that can occur in a block of text:
4
- #
5
- # \:include: filename
6
- #
7
- # Directives can be escaped by preceding them with a backslash.
8
- #
9
- # RDoc plugin authors can register additional directives to be handled by
10
- # using RDoc::Markup::PreProcess::register.
11
- #
12
- # Any directive that is not built-in to RDoc (including those registered via
13
- # plugins) will be stored in the metadata hash on the CodeObject the comment
14
- # is attached to. See RDoc::Markup@Directives for the list of built-in
15
- # directives.
16
-
17
- class RDoc::Markup::PreProcess
18
-
19
- ##
20
- # An RDoc::Options instance that will be filled in with overrides from
21
- # directives
22
-
23
- attr_accessor :options
24
-
25
- ##
26
- # Adds a post-process handler for directives. The handler will be called
27
- # with the result RDoc::Comment (or text String) and the code object for the
28
- # comment (if any).
29
-
30
- def self.post_process(&block)
31
- @post_processors << block
32
- end
33
-
34
- ##
35
- # Registered post-processors
36
-
37
- def self.post_processors
38
- @post_processors
39
- end
2
+ module RDoc
3
+ class Markup
4
+ ##
5
+ # Handle common directives that can occur in a block of text:
6
+ #
7
+ # \:include: filename
8
+ #
9
+ # Directives can be escaped by preceding them with a backslash.
10
+ #
11
+ # RDoc plugin authors can register additional directives to be handled by
12
+ # using RDoc::Markup::PreProcess::register.
13
+ #
14
+ # Any directive that is not built-in to RDoc (including those registered via
15
+ # plugins) will be stored in the metadata hash on the CodeObject the comment
16
+ # is attached to. See RDoc::Markup@Directives for the list of built-in
17
+ # directives.
18
+
19
+ class PreProcess
20
+
21
+ ##
22
+ # An RDoc::Options instance that will be filled in with overrides from
23
+ # directives
24
+
25
+ attr_accessor :options
26
+
27
+ ##
28
+ # Adds a post-process handler for directives. The handler will be called
29
+ # with the result RDoc::Comment (or text String) and the code object for the
30
+ # comment (if any).
31
+
32
+ def self.post_process(&block)
33
+ @post_processors << block
34
+ end
40
35
 
41
- ##
42
- # Registers +directive+ as one handled by RDoc. If a block is given the
43
- # directive will be replaced by the result of the block, otherwise the
44
- # directive will be removed from the processed text.
45
- #
46
- # The block will be called with the directive name and the directive
47
- # parameter:
48
- #
49
- # RDoc::Markup::PreProcess.register 'my-directive' do |directive, param|
50
- # # replace text, etc.
51
- # end
52
-
53
- def self.register(directive, &block)
54
- @registered[directive] = block
55
- end
36
+ ##
37
+ # Registered post-processors
56
38
 
57
- ##
58
- # Registered directives
39
+ def self.post_processors
40
+ @post_processors
41
+ end
59
42
 
60
- def self.registered
61
- @registered
62
- end
43
+ ##
44
+ # Registers +directive+ as one handled by RDoc. If a block is given the
45
+ # directive will be replaced by the result of the block, otherwise the
46
+ # directive will be removed from the processed text.
47
+ #
48
+ # The block will be called with the directive name and the directive
49
+ # parameter:
50
+ #
51
+ # RDoc::Markup::PreProcess.register 'my-directive' do |directive, param|
52
+ # # replace text, etc.
53
+ # end
54
+
55
+ def self.register(directive, &block)
56
+ @registered[directive] = block
57
+ end
63
58
 
64
- ##
65
- # Clears all registered directives and post-processors
59
+ ##
60
+ # Registered directives
66
61
 
67
- def self.reset
68
- @post_processors = []
69
- @registered = {}
70
- end
62
+ def self.registered
63
+ @registered
64
+ end
71
65
 
72
- reset
66
+ ##
67
+ # Clears all registered directives and post-processors
73
68
 
74
- ##
75
- # Creates a new pre-processor for +input_file_name+ that will look for
76
- # included files in +include_path+
69
+ def self.reset
70
+ @post_processors = []
71
+ @registered = {}
72
+ end
77
73
 
78
- def initialize(input_file_name, include_path)
79
- @input_file_name = input_file_name
80
- @include_path = include_path
81
- @options = nil
82
- end
74
+ reset
83
75
 
84
- ##
85
- # Look for directives in the given +text+.
86
- #
87
- # Options that we don't handle are yielded. If the block returns false the
88
- # directive is restored to the text. If the block returns nil or no block
89
- # was given the directive is handled according to the registered directives.
90
- # If a String was returned the directive is replaced with the string.
91
- #
92
- # If no matching directive was registered the directive is restored to the
93
- # text.
94
- #
95
- # If +code_object+ is given and the directive is unknown then the
96
- # directive's parameter is set as metadata on the +code_object+. See
97
- # RDoc::CodeObject#metadata for details.
98
-
99
- def handle(text, code_object = nil, &block)
100
- if RDoc::Comment === text then
101
- comment = text
102
- text = text.text
103
- end
76
+ ##
77
+ # Creates a new pre-processor for +input_file_name+ that will look for
78
+ # included files in +include_path+
104
79
 
105
- # regexp helper (square brackets for optional)
106
- # $1 $2 $3 $4 $5
107
- # [prefix][\]:directive:[spaces][param]newline
108
- text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/) do
109
- # skip something like ':toto::'
110
- next $& if $4.empty? and $5 and $5[0, 1] == ':'
111
-
112
- # skip if escaped
113
- next "#$1:#$3:#$4#$5\n" unless $2.empty?
114
-
115
- # This is not in handle_directive because I didn't want to pass another
116
- # argument into it
117
- if comment and $3 == 'markup' then
118
- next "#{$1.strip}\n" unless $5
119
- comment.format = $5.downcase
120
- next "#{$1.strip}\n"
80
+ def initialize(input_file_name, include_path)
81
+ @input_file_name = input_file_name
82
+ @include_path = include_path
83
+ @options = nil
121
84
  end
122
- handle_directive $1, $3, $5, code_object, text.encoding, &block
123
- end
124
85
 
125
- if comment then
126
- comment.text = text
127
- else
128
- comment = text
129
- end
86
+ ##
87
+ # Look for directives in the given +text+.
88
+ #
89
+ # Options that we don't handle are yielded. If the block returns false the
90
+ # directive is restored to the text. If the block returns nil or no block
91
+ # was given the directive is handled according to the registered directives.
92
+ # If a String was returned the directive is replaced with the string.
93
+ #
94
+ # If no matching directive was registered the directive is restored to the
95
+ # text.
96
+ #
97
+ # If +code_object+ is given and the directive is unknown then the
98
+ # directive's parameter is set as metadata on the +code_object+. See
99
+ # RDoc::CodeObject#metadata for details.
100
+
101
+ def handle(text, code_object = nil, &block)
102
+ if Comment === text
103
+ comment = text
104
+ text = text.text
105
+ end
130
106
 
131
- run_post_processes(comment, code_object)
107
+ # regexp helper (square brackets for optional)
108
+ # $1 $2 $3 $4 $5
109
+ # [prefix][\]:directive:[spaces][param]newline
110
+ text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/) do
111
+ # skip something like ':toto::'
112
+ next $& if $4.empty? and $5 and $5[0, 1] == ':'
113
+
114
+ # skip if escaped
115
+ next "#$1:#$3:#$4#$5\n" unless $2.empty?
116
+
117
+ # This is not in handle_directive because I didn't want to pass another
118
+ # argument into it
119
+ if comment and $3 == 'markup'
120
+ next "#{$1.strip}\n" unless $5
121
+ comment.format = $5.downcase
122
+ next "#{$1.strip}\n"
123
+ end
124
+ handle_directive $1, $3, $5, code_object, text.encoding, &block
125
+ end
132
126
 
133
- text
134
- end
127
+ if comment
128
+ comment.text = text
129
+ else
130
+ comment = text
131
+ end
135
132
 
136
- # Apply directives to a code object
133
+ run_post_processes(comment, code_object)
137
134
 
138
- def run_pre_processes(comment_text, code_object, start_line_no, type)
139
- comment_text, directives = parse_comment(comment_text, start_line_no, type)
140
- directives.each do |directive, (param, line_no)|
141
- handle_directive('', directive, param, code_object)
142
- end
143
- if code_object.is_a?(RDoc::AnyMethod) && (call_seq, = directives['call-seq']) && call_seq
144
- code_object.call_seq = call_seq.lines.map(&:chomp).reject(&:empty?).join("\n")
145
- end
146
- format, = directives['markup']
147
- [comment_text, format]
148
- end
135
+ text
136
+ end
149
137
 
150
- # Perform post preocesses to a code object
138
+ # Apply directives to a code object
151
139
 
152
- def run_post_processes(comment, code_object)
153
- self.class.post_processors.each do |handler|
154
- handler.call comment, code_object
155
- end
156
- end
140
+ def run_pre_processes(comment_text, code_object, start_line_no, type)
141
+ comment_text, directives = parse_comment(comment_text, start_line_no, type)
142
+ directives.each do |directive, (param, line_no)|
143
+ handle_directive('', directive, param, code_object)
144
+ end
145
+ if code_object.is_a?(AnyMethod) && (call_seq, = directives['call-seq']) && call_seq
146
+ code_object.call_seq = call_seq.lines.map(&:chomp).reject(&:empty?).join("\n")
147
+ end
148
+ format, = directives['markup']
149
+ [comment_text, format]
150
+ end
157
151
 
158
- # Parse comment and return [normalized_comment_text, directives_hash]
152
+ # Perform post preocesses to a code object
159
153
 
160
- def parse_comment(text, line_no, type)
161
- RDoc::Comment.parse(text, @input_file_name, line_no, type) do |filename, prefix_indent|
162
- include_file(filename, prefix_indent, text.encoding)
163
- end
164
- end
154
+ def run_post_processes(comment, code_object)
155
+ self.class.post_processors.each do |handler|
156
+ handler.call comment, code_object
157
+ end
158
+ end
159
+
160
+ # Parse comment and return [normalized_comment_text, directives_hash]
165
161
 
166
- ##
167
- # Performs the actions described by +directive+ and its parameter +param+.
168
- #
169
- # +code_object+ is used for directives that operate on a class or module.
170
- # +prefix+ is used to ensure the replacement for handled directives is
171
- # correct. +encoding+ is used for the <tt>include</tt> directive.
172
- #
173
- # For a list of directives in RDoc see RDoc::Markup.
174
- #--
175
- # When 1.8.7 support is ditched prefix can be defaulted to ''
176
-
177
- def handle_directive(prefix, directive, param, code_object = nil,
178
- encoding = nil)
179
- blankline = "#{prefix.strip}\n"
180
- directive = directive.downcase
181
-
182
- case directive
183
- when 'arg', 'args' then
184
- return "#{prefix}:#{directive}: #{param}\n" unless code_object && code_object.kind_of?(RDoc::AnyMethod)
185
-
186
- code_object.params = param
187
-
188
- blankline
189
- when 'category' then
190
- if RDoc::Context === code_object then
191
- section = code_object.add_section param
192
- code_object.temporary_section = section
193
- elsif RDoc::AnyMethod === code_object then
194
- code_object.section_title = param
162
+ def parse_comment(text, line_no, type)
163
+ Comment.parse(text, @input_file_name, line_no, type) do |filename, prefix_indent|
164
+ include_file(filename, prefix_indent, text.encoding)
165
+ end
195
166
  end
196
167
 
197
- blankline # ignore category if we're not on an RDoc::Context
198
- when 'doc' then
199
- return blankline unless code_object
200
- code_object.document_self = true
201
- code_object.force_documentation = true
202
-
203
- blankline
204
- when 'enddoc' then
205
- return blankline unless code_object
206
- code_object.done_documenting = true
207
-
208
- blankline
209
- when 'include' then
210
- filename = param.split(' ', 2).first
211
- include_file filename, prefix, encoding
212
- when 'main' then
213
- @options.main_page = param if @options.respond_to? :main_page
214
- warn <<~MSG
215
- The :main: directive is deprecated and will be removed in RDoc 7.
216
-
217
- You can use these options to specify the initial page displayed instead:
218
- - `--main=#{param}` via the command line
219
- - `rdoc.main = "#{param}"` if you use `RDoc::Task`
220
- - `main_page: #{param}` in your `.rdoc_options` file
221
- MSG
222
-
223
- blankline
224
- when 'nodoc' then
225
- return blankline unless code_object
226
- code_object.document_self = nil # notify nodoc
227
- code_object.document_children = param !~ /all/i
228
-
229
- blankline
230
- when 'notnew', 'not_new', 'not-new' then
231
- return blankline unless RDoc::AnyMethod === code_object
232
-
233
- code_object.dont_rename_initialize = true
234
-
235
- blankline
236
- when 'startdoc' then
237
- return blankline unless code_object
238
-
239
- code_object.start_doc
240
- code_object.force_documentation = true
241
-
242
- blankline
243
- when 'stopdoc' then
244
- return blankline unless code_object
245
-
246
- code_object.stop_doc
247
-
248
- blankline
249
- when 'title' then
250
- @options.default_title = param if @options.respond_to? :default_title=
251
-
252
- warn <<~MSG
253
- The :title: directive is deprecated and will be removed in RDoc 7.
254
-
255
- You can use these options to specify the title displayed instead:
256
- - `--title=#{param}` via the command line
257
- - `rdoc.title = "#{param}"` if you use `RDoc::Task`
258
- - `title: #{param}` in your `.rdoc_options` file
259
- MSG
260
-
261
- blankline
262
- when 'yield', 'yields' then
263
- return blankline unless code_object
264
- # remove parameter &block
265
- code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
266
-
267
- code_object.block_params = param || ''
268
-
269
- blankline
270
- else
271
- result = yield directive, param if block_given?
272
-
273
- case result
274
- when nil then
275
- code_object.metadata[directive] = param if code_object
276
-
277
- if RDoc::Markup::PreProcess.registered.include? directive then
278
- handler = RDoc::Markup::PreProcess.registered[directive]
279
- result = handler.call directive, param if handler
168
+ ##
169
+ # Performs the actions described by +directive+ and its parameter +param+.
170
+ #
171
+ # +code_object+ is used for directives that operate on a class or module.
172
+ # +prefix+ is used to ensure the replacement for handled directives is
173
+ # correct. +encoding+ is used for the <tt>include</tt> directive.
174
+ #
175
+ # For a list of directives in RDoc see RDoc::Markup.
176
+ #--
177
+ # When 1.8.7 support is ditched prefix can be defaulted to ''
178
+
179
+ def handle_directive(prefix, directive, param, code_object = nil,
180
+ encoding = nil)
181
+ blankline = "#{prefix.strip}\n"
182
+ directive = directive.downcase
183
+
184
+ case directive
185
+ when 'arg', 'args'
186
+ return "#{prefix}:#{directive}: #{param}\n" unless code_object && code_object.kind_of?(AnyMethod)
187
+
188
+ code_object.params = param
189
+
190
+ blankline
191
+ when 'category'
192
+ if Context === code_object
193
+ section = code_object.add_section param
194
+ code_object.temporary_section = section
195
+ elsif AnyMethod === code_object
196
+ code_object.section_title = param
197
+ end
198
+
199
+ blankline # ignore category if we're not on an RDoc::Context
200
+ when 'doc'
201
+ return blankline unless code_object
202
+ code_object.document_self = true
203
+ code_object.force_documentation = true
204
+
205
+ blankline
206
+ when 'enddoc'
207
+ return blankline unless code_object
208
+ code_object.done_documenting = true
209
+
210
+ blankline
211
+ when 'include'
212
+ filename = param.split(' ', 2).first
213
+ include_file filename, prefix, encoding
214
+ when 'nodoc'
215
+ return blankline unless code_object
216
+ code_object.document_self = nil # notify nodoc
217
+ code_object.document_children = param !~ /all/i
218
+
219
+ blankline
220
+ when 'notnew', 'not_new', 'not-new'
221
+ return blankline unless AnyMethod === code_object
222
+
223
+ code_object.dont_rename_initialize = true
224
+
225
+ blankline
226
+ when 'startdoc'
227
+ return blankline unless code_object
228
+
229
+ code_object.start_doc
230
+ code_object.force_documentation = true
231
+
232
+ blankline
233
+ when 'stopdoc'
234
+ return blankline unless code_object
235
+
236
+ code_object.stop_doc
237
+
238
+ blankline
239
+ when 'yield', 'yields'
240
+ return blankline unless code_object
241
+ # remove parameter &block
242
+ code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
243
+
244
+ code_object.block_params = param || ''
245
+
246
+ blankline
280
247
  else
281
- result = "#{prefix}:#{directive}: #{param}\n"
248
+ result = yield directive, param if block_given?
249
+
250
+ case result
251
+ when nil
252
+ code_object.metadata[directive] = param if code_object
253
+
254
+ if Markup::PreProcess.registered.include? directive
255
+ handler = Markup::PreProcess.registered[directive]
256
+ result = handler.call directive, param if handler
257
+ else
258
+ result = "#{prefix}:#{directive}: #{param}\n"
259
+ end
260
+ when false
261
+ result = "#{prefix}:#{directive}: #{param}\n"
262
+ end
263
+
264
+ result
282
265
  end
283
- when false then
284
- result = "#{prefix}:#{directive}: #{param}\n"
285
266
  end
286
267
 
287
- result
288
- end
289
- end
268
+ ##
269
+ # Handles the <tt>:include: _filename_</tt> directive.
270
+ #
271
+ # If the first line of the included file starts with '#', and contains
272
+ # an encoding information in the form 'coding:' or 'coding=', it is
273
+ # removed.
274
+ #
275
+ # If all lines in the included file start with a '#', this leading '#'
276
+ # is removed before inclusion. The included content is indented like
277
+ # the <tt>:include:</tt> directive.
278
+ #--
279
+ # so all content will be verbatim because of the likely space after '#'?
280
+ # TODO shift left the whole file content in that case
281
+ # TODO comment stop/start #-- and #++ in included file must be processed here
282
+
283
+ def include_file(name, indent, encoding)
284
+ full_name = find_include_file name
285
+
286
+ unless full_name
287
+ warn "Couldn't find file to include '#{name}' from #{@input_file_name}"
288
+ return ''
289
+ end
290
290
 
291
- ##
292
- # Handles the <tt>:include: _filename_</tt> directive.
293
- #
294
- # If the first line of the included file starts with '#', and contains
295
- # an encoding information in the form 'coding:' or 'coding=', it is
296
- # removed.
297
- #
298
- # If all lines in the included file start with a '#', this leading '#'
299
- # is removed before inclusion. The included content is indented like
300
- # the <tt>:include:</tt> directive.
301
- #--
302
- # so all content will be verbatim because of the likely space after '#'?
303
- # TODO shift left the whole file content in that case
304
- # TODO comment stop/start #-- and #++ in included file must be processed here
305
-
306
- def include_file(name, indent, encoding)
307
- full_name = find_include_file name
308
-
309
- unless full_name then
310
- warn "Couldn't find file to include '#{name}' from #{@input_file_name}"
311
- return ''
312
- end
291
+ content = Encoding.read_file full_name, encoding, true
292
+ content = Encoding.remove_magic_comment content
313
293
 
314
- content = RDoc::Encoding.read_file full_name, encoding, true
315
- content = RDoc::Encoding.remove_magic_comment content
294
+ # strip magic comment
295
+ content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
316
296
 
317
- # strip magic comment
318
- content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
297
+ # strip leading '#'s, but only if all lines start with them
298
+ if content =~ /^[^#]/
299
+ content.gsub(/^/, indent)
300
+ else
301
+ content.gsub(/^#?/, indent)
302
+ end
303
+ end
319
304
 
320
- # strip leading '#'s, but only if all lines start with them
321
- if content =~ /^[^#]/ then
322
- content.gsub(/^/, indent)
323
- else
324
- content.gsub(/^#?/, indent)
325
- end
326
- end
305
+ ##
306
+ # Look for the given file in the directory containing the current file,
307
+ # and then in each of the directories specified in the RDOC_INCLUDE path
327
308
 
328
- ##
329
- # Look for the given file in the directory containing the current file,
330
- # and then in each of the directories specified in the RDOC_INCLUDE path
309
+ def find_include_file(name)
310
+ to_search = [File.dirname(@input_file_name)].concat @include_path
311
+ to_search.each do |dir|
312
+ full_name = File.join(dir, name)
313
+ stat = File.stat(full_name) rescue next
314
+ return full_name if stat.readable?
315
+ end
316
+ nil
317
+ end
331
318
 
332
- def find_include_file(name)
333
- to_search = [File.dirname(@input_file_name)].concat @include_path
334
- to_search.each do |dir|
335
- full_name = File.join(dir, name)
336
- stat = File.stat(full_name) rescue next
337
- return full_name if stat.readable?
338
319
  end
339
- nil
340
320
  end
341
-
342
321
  end
@@ -3,8 +3,8 @@
3
3
  module RDoc
4
4
  class Markup
5
5
  # A section of text that is added to the output document as-is
6
- class Raw
7
- # The component parts of the list
6
+ class Raw < Element
7
+ # The component parts of the raw text
8
8
  #: Array[String]
9
9
  attr_reader :parts
10
10