rdoc 8.0.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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -3
  3. data/RI.md +75 -75
  4. data/exe/rdoc +2 -2
  5. data/lib/rdoc/code_object/alias.rb +71 -69
  6. data/lib/rdoc/code_object/any_method.rb +305 -303
  7. data/lib/rdoc/code_object/attr.rb +150 -148
  8. data/lib/rdoc/code_object/class_module.rb +798 -792
  9. data/lib/rdoc/code_object/constant.rb +175 -173
  10. data/lib/rdoc/code_object/context/section.rb +142 -138
  11. data/lib/rdoc/code_object/context.rb +926 -958
  12. data/lib/rdoc/code_object/extend.rb +7 -5
  13. data/lib/rdoc/code_object/include.rb +7 -5
  14. data/lib/rdoc/code_object/method_attr.rb +326 -319
  15. data/lib/rdoc/code_object/mixin.rb +97 -95
  16. data/lib/rdoc/code_object/normal_class.rb +77 -78
  17. data/lib/rdoc/code_object/normal_module.rb +61 -59
  18. data/lib/rdoc/code_object/require.rb +23 -39
  19. data/lib/rdoc/code_object/single_class.rb +21 -19
  20. data/lib/rdoc/code_object/top_level.rb +212 -219
  21. data/lib/rdoc/code_object.rb +305 -303
  22. data/lib/rdoc/comment.rb +275 -273
  23. data/lib/rdoc/cross_reference.rb +192 -190
  24. data/lib/rdoc/encoding.rb +105 -103
  25. data/lib/rdoc/erb_partial.rb +13 -11
  26. data/lib/rdoc/erbio.rb +29 -27
  27. data/lib/rdoc/generator/aliki.rb +161 -153
  28. data/lib/rdoc/generator/darkfish.rb +645 -635
  29. data/lib/rdoc/generator/json_index.rb +233 -229
  30. data/lib/rdoc/generator/markup.rb +164 -146
  31. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  32. data/lib/rdoc/generator/pot/po.rb +52 -51
  33. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  34. data/lib/rdoc/generator/pot.rb +85 -81
  35. data/lib/rdoc/generator/ri.rb +23 -19
  36. data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
  37. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  38. data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
  39. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  40. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  41. data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
  42. data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  44. data/lib/rdoc/generator.rb +48 -46
  45. data/lib/rdoc/i18n/locale.rb +99 -95
  46. data/lib/rdoc/i18n/text.rb +109 -105
  47. data/lib/rdoc/i18n.rb +7 -5
  48. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  49. data/lib/rdoc/markdown.kpeg +15 -11
  50. data/lib/rdoc/markdown.rb +40 -47
  51. data/lib/rdoc/markup/block_quote.rb +12 -8
  52. data/lib/rdoc/markup/document.rb +127 -123
  53. data/lib/rdoc/markup/formatter.rb +219 -215
  54. data/lib/rdoc/markup/include.rb +33 -29
  55. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  56. data/lib/rdoc/markup/inline_parser.rb +281 -277
  57. data/lib/rdoc/markup/list.rb +80 -88
  58. data/lib/rdoc/markup/list_item.rb +73 -85
  59. data/lib/rdoc/markup/paragraph.rb +23 -19
  60. data/lib/rdoc/markup/parser.rb +501 -497
  61. data/lib/rdoc/markup/pre_process.rb +283 -279
  62. data/lib/rdoc/markup/raw.rb +2 -2
  63. data/lib/rdoc/markup/rule.rb +16 -12
  64. data/lib/rdoc/markup/to_ansi.rb +143 -139
  65. data/lib/rdoc/markup/to_bs.rb +72 -68
  66. data/lib/rdoc/markup/to_html.rb +594 -565
  67. data/lib/rdoc/markup/to_html_crossref.rb +234 -230
  68. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  69. data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
  70. data/lib/rdoc/markup/to_label.rb +63 -59
  71. data/lib/rdoc/markup/to_markdown.rb +212 -208
  72. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  73. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  74. data/lib/rdoc/markup/to_test.rb +60 -56
  75. data/lib/rdoc/markup/to_tt_only.rb +84 -80
  76. data/lib/rdoc/markup/verbatim.rb +62 -58
  77. data/lib/rdoc/markup.rb +198 -196
  78. data/lib/rdoc/options.rb +1063 -1061
  79. data/lib/rdoc/parser/c.rb +1039 -1037
  80. data/lib/rdoc/parser/changelog.rb +319 -315
  81. data/lib/rdoc/parser/markdown.rb +17 -13
  82. data/lib/rdoc/parser/rbs.rb +239 -235
  83. data/lib/rdoc/parser/rd.rb +17 -13
  84. data/lib/rdoc/parser/ruby.rb +1245 -1124
  85. data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
  86. data/lib/rdoc/parser/simple.rb +31 -27
  87. data/lib/rdoc/parser/text.rb +12 -8
  88. data/lib/rdoc/parser.rb +228 -220
  89. data/lib/rdoc/rbs_helper.rb +1 -1
  90. data/lib/rdoc/rd/inline.rb +57 -53
  91. data/lib/rdoc/rd.rb +90 -88
  92. data/lib/rdoc/rdoc.rb +500 -491
  93. data/lib/rdoc/ri/driver.rb +1140 -1135
  94. data/lib/rdoc/ri/formatter.rb +7 -3
  95. data/lib/rdoc/ri/paths.rb +140 -136
  96. data/lib/rdoc/ri/servlet.rb +354 -350
  97. data/lib/rdoc/ri/store.rb +4 -2
  98. data/lib/rdoc/ri/task.rb +55 -51
  99. data/lib/rdoc/ri.rb +14 -12
  100. data/lib/rdoc/rubygems_hook.rb +183 -181
  101. data/lib/rdoc/server.rb +349 -347
  102. data/lib/rdoc/stats/normal.rb +46 -42
  103. data/lib/rdoc/stats/quiet.rb +39 -35
  104. data/lib/rdoc/stats/verbose.rb +35 -31
  105. data/lib/rdoc/stats.rb +365 -363
  106. data/lib/rdoc/store.rb +888 -902
  107. data/lib/rdoc/task.rb +260 -256
  108. data/lib/rdoc/text.rb +135 -133
  109. data/lib/rdoc/token_stream.rb +101 -93
  110. data/lib/rdoc/tom_doc.rb +203 -201
  111. data/lib/rdoc/version.rb +1 -1
  112. metadata +4 -5
  113. data/lib/rdoc/markdown/literals.kpeg +0 -21
  114. data/lib/rdoc/markdown/literals.rb +0 -454
@@ -1,317 +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
40
-
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
56
-
57
- ##
58
- # Registered directives
59
-
60
- def self.registered
61
- @registered
62
- end
63
-
64
- ##
65
- # Clears all registered directives and post-processors
66
-
67
- def self.reset
68
- @post_processors = []
69
- @registered = {}
70
- end
71
-
72
- reset
73
-
74
- ##
75
- # Creates a new pre-processor for +input_file_name+ that will look for
76
- # included files in +include_path+
77
-
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
83
-
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
104
-
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"
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
121
34
  end
122
- handle_directive $1, $3, $5, code_object, text.encoding, &block
123
- end
124
35
 
125
- if comment then
126
- comment.text = text
127
- else
128
- comment = text
129
- end
36
+ ##
37
+ # Registered post-processors
130
38
 
131
- run_post_processes(comment, code_object)
39
+ def self.post_processors
40
+ @post_processors
41
+ end
132
42
 
133
- text
134
- 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
135
58
 
136
- # Apply directives to a code object
59
+ ##
60
+ # Registered directives
137
61
 
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
62
+ def self.registered
63
+ @registered
64
+ end
149
65
 
150
- # Perform post preocesses to a code object
66
+ ##
67
+ # Clears all registered directives and post-processors
151
68
 
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
69
+ def self.reset
70
+ @post_processors = []
71
+ @registered = {}
72
+ end
157
73
 
158
- # Parse comment and return [normalized_comment_text, directives_hash]
74
+ reset
159
75
 
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
76
+ ##
77
+ # Creates a new pre-processor for +input_file_name+ that will look for
78
+ # included files in +include_path+
165
79
 
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
80
+ def initialize(input_file_name, include_path)
81
+ @input_file_name = input_file_name
82
+ @include_path = include_path
83
+ @options = nil
195
84
  end
196
85
 
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 'nodoc' then
213
- return blankline unless code_object
214
- code_object.document_self = nil # notify nodoc
215
- code_object.document_children = param !~ /all/i
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
216
106
 
217
- blankline
218
- when 'notnew', 'not_new', 'not-new' then
219
- return blankline unless RDoc::AnyMethod === 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
220
126
 
221
- code_object.dont_rename_initialize = true
127
+ if comment
128
+ comment.text = text
129
+ else
130
+ comment = text
131
+ end
222
132
 
223
- blankline
224
- when 'startdoc' then
225
- return blankline unless code_object
133
+ run_post_processes(comment, code_object)
226
134
 
227
- code_object.start_doc
228
- code_object.force_documentation = true
135
+ text
136
+ end
229
137
 
230
- blankline
231
- when 'stopdoc' then
232
- return blankline unless code_object
138
+ # Apply directives to a code object
233
139
 
234
- code_object.stop_doc
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
235
151
 
236
- blankline
237
- when 'yield', 'yields' then
238
- return blankline unless code_object
239
- # remove parameter &block
240
- code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
152
+ # Perform post preocesses to a code object
241
153
 
242
- code_object.block_params = param || ''
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
243
159
 
244
- blankline
245
- else
246
- result = yield directive, param if block_given?
160
+ # Parse comment and return [normalized_comment_text, directives_hash]
247
161
 
248
- case result
249
- when nil then
250
- code_object.metadata[directive] = param if code_object
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
166
+ end
251
167
 
252
- if RDoc::Markup::PreProcess.registered.include? directive then
253
- handler = RDoc::Markup::PreProcess.registered[directive]
254
- 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
255
247
  else
256
- 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
257
265
  end
258
- when false then
259
- result = "#{prefix}:#{directive}: #{param}\n"
260
266
  end
261
267
 
262
- result
263
- end
264
- 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
265
290
 
266
- ##
267
- # Handles the <tt>:include: _filename_</tt> directive.
268
- #
269
- # If the first line of the included file starts with '#', and contains
270
- # an encoding information in the form 'coding:' or 'coding=', it is
271
- # removed.
272
- #
273
- # If all lines in the included file start with a '#', this leading '#'
274
- # is removed before inclusion. The included content is indented like
275
- # the <tt>:include:</tt> directive.
276
- #--
277
- # so all content will be verbatim because of the likely space after '#'?
278
- # TODO shift left the whole file content in that case
279
- # TODO comment stop/start #-- and #++ in included file must be processed here
280
-
281
- def include_file(name, indent, encoding)
282
- full_name = find_include_file name
283
-
284
- unless full_name then
285
- warn "Couldn't find file to include '#{name}' from #{@input_file_name}"
286
- return ''
287
- end
291
+ content = Encoding.read_file full_name, encoding, true
292
+ content = Encoding.remove_magic_comment content
288
293
 
289
- content = RDoc::Encoding.read_file full_name, encoding, true
290
- content = RDoc::Encoding.remove_magic_comment content
294
+ # strip magic comment
295
+ content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
291
296
 
292
- # strip magic comment
293
- 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
294
304
 
295
- # strip leading '#'s, but only if all lines start with them
296
- if content =~ /^[^#]/ then
297
- content.gsub(/^/, indent)
298
- else
299
- content.gsub(/^#?/, indent)
300
- end
301
- 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
302
308
 
303
- ##
304
- # Look for the given file in the directory containing the current file,
305
- # 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
306
318
 
307
- def find_include_file(name)
308
- to_search = [File.dirname(@input_file_name)].concat @include_path
309
- to_search.each do |dir|
310
- full_name = File.join(dir, name)
311
- stat = File.stat(full_name) rescue next
312
- return full_name if stat.readable?
313
319
  end
314
- nil
315
320
  end
316
-
317
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
 
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # A horizontal rule with a weight
2
+ module RDoc
3
+ class Markup
4
+ ##
5
+ # A horizontal rule with a weight
4
6
 
5
- class RDoc::Markup::Rule < Struct.new :weight
7
+ class Rule < Struct.new :weight
6
8
 
7
- ##
8
- # Calls #accept_rule on +visitor+
9
+ ##
10
+ # Calls #accept_rule on +visitor+
9
11
 
10
- def accept(visitor)
11
- visitor.accept_rule self
12
- end
12
+ def accept(visitor)
13
+ visitor.accept_rule self
14
+ end
15
+
16
+ def pretty_print(q) # :nodoc:
17
+ q.group 2, '[rule:', ']' do
18
+ q.pp weight
19
+ end
20
+ end
13
21
 
14
- def pretty_print(q) # :nodoc:
15
- q.group 2, '[rule:', ']' do
16
- q.pp weight
17
22
  end
18
23
  end
19
-
20
24
  end