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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -3
- data/RI.md +75 -75
- data/exe/rdoc +2 -2
- data/lib/rdoc/code_object/alias.rb +71 -69
- data/lib/rdoc/code_object/any_method.rb +305 -303
- data/lib/rdoc/code_object/attr.rb +150 -148
- data/lib/rdoc/code_object/class_module.rb +798 -792
- data/lib/rdoc/code_object/constant.rb +175 -173
- data/lib/rdoc/code_object/context/section.rb +142 -138
- data/lib/rdoc/code_object/context.rb +926 -958
- data/lib/rdoc/code_object/extend.rb +7 -5
- data/lib/rdoc/code_object/include.rb +7 -5
- data/lib/rdoc/code_object/method_attr.rb +326 -319
- data/lib/rdoc/code_object/mixin.rb +97 -95
- data/lib/rdoc/code_object/normal_class.rb +77 -78
- data/lib/rdoc/code_object/normal_module.rb +61 -59
- data/lib/rdoc/code_object/require.rb +23 -39
- data/lib/rdoc/code_object/single_class.rb +21 -19
- data/lib/rdoc/code_object/top_level.rb +212 -219
- data/lib/rdoc/code_object.rb +305 -303
- data/lib/rdoc/comment.rb +275 -273
- data/lib/rdoc/cross_reference.rb +192 -190
- data/lib/rdoc/encoding.rb +105 -103
- data/lib/rdoc/erb_partial.rb +13 -11
- data/lib/rdoc/erbio.rb +29 -27
- data/lib/rdoc/generator/aliki.rb +161 -153
- data/lib/rdoc/generator/darkfish.rb +645 -635
- data/lib/rdoc/generator/json_index.rb +233 -229
- data/lib/rdoc/generator/markup.rb +164 -146
- data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
- data/lib/rdoc/generator/pot/po.rb +52 -51
- data/lib/rdoc/generator/pot/po_entry.rb +138 -132
- data/lib/rdoc/generator/pot.rb +85 -81
- data/lib/rdoc/generator/ri.rb +23 -19
- data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
- data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
- data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
- data/lib/rdoc/generator.rb +48 -46
- data/lib/rdoc/i18n/locale.rb +99 -95
- data/lib/rdoc/i18n/text.rb +109 -105
- data/lib/rdoc/i18n.rb +7 -5
- data/lib/rdoc/markdown/byte_runtime.rb +80 -0
- data/lib/rdoc/markdown.kpeg +15 -11
- data/lib/rdoc/markdown.rb +40 -47
- data/lib/rdoc/markup/block_quote.rb +12 -8
- data/lib/rdoc/markup/document.rb +127 -123
- data/lib/rdoc/markup/formatter.rb +219 -215
- data/lib/rdoc/markup/include.rb +33 -29
- data/lib/rdoc/markup/indented_paragraph.rb +37 -33
- data/lib/rdoc/markup/inline_parser.rb +281 -277
- data/lib/rdoc/markup/list.rb +80 -88
- data/lib/rdoc/markup/list_item.rb +73 -85
- data/lib/rdoc/markup/paragraph.rb +23 -19
- data/lib/rdoc/markup/parser.rb +501 -497
- data/lib/rdoc/markup/pre_process.rb +283 -279
- data/lib/rdoc/markup/raw.rb +2 -2
- data/lib/rdoc/markup/rule.rb +16 -12
- data/lib/rdoc/markup/to_ansi.rb +143 -139
- data/lib/rdoc/markup/to_bs.rb +72 -68
- data/lib/rdoc/markup/to_html.rb +594 -565
- data/lib/rdoc/markup/to_html_crossref.rb +234 -230
- data/lib/rdoc/markup/to_html_snippet.rb +232 -227
- data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
- data/lib/rdoc/markup/to_label.rb +63 -59
- data/lib/rdoc/markup/to_markdown.rb +212 -208
- data/lib/rdoc/markup/to_rdoc.rb +336 -332
- data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
- data/lib/rdoc/markup/to_test.rb +60 -56
- data/lib/rdoc/markup/to_tt_only.rb +84 -80
- data/lib/rdoc/markup/verbatim.rb +62 -58
- data/lib/rdoc/markup.rb +198 -196
- data/lib/rdoc/options.rb +1063 -1061
- data/lib/rdoc/parser/c.rb +1039 -1037
- data/lib/rdoc/parser/changelog.rb +319 -315
- data/lib/rdoc/parser/markdown.rb +17 -13
- data/lib/rdoc/parser/rbs.rb +239 -235
- data/lib/rdoc/parser/rd.rb +17 -13
- data/lib/rdoc/parser/ruby.rb +1245 -1124
- data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
- data/lib/rdoc/parser/simple.rb +31 -27
- data/lib/rdoc/parser/text.rb +12 -8
- data/lib/rdoc/parser.rb +228 -220
- data/lib/rdoc/rbs_helper.rb +1 -1
- data/lib/rdoc/rd/inline.rb +57 -53
- data/lib/rdoc/rd.rb +90 -88
- data/lib/rdoc/rdoc.rb +500 -491
- data/lib/rdoc/ri/driver.rb +1140 -1135
- data/lib/rdoc/ri/formatter.rb +7 -3
- data/lib/rdoc/ri/paths.rb +140 -136
- data/lib/rdoc/ri/servlet.rb +354 -350
- data/lib/rdoc/ri/store.rb +4 -2
- data/lib/rdoc/ri/task.rb +55 -51
- data/lib/rdoc/ri.rb +14 -12
- data/lib/rdoc/rubygems_hook.rb +183 -181
- data/lib/rdoc/server.rb +349 -347
- data/lib/rdoc/stats/normal.rb +46 -42
- data/lib/rdoc/stats/quiet.rb +39 -35
- data/lib/rdoc/stats/verbose.rb +35 -31
- data/lib/rdoc/stats.rb +365 -363
- data/lib/rdoc/store.rb +888 -902
- data/lib/rdoc/task.rb +260 -256
- data/lib/rdoc/text.rb +135 -133
- data/lib/rdoc/token_stream.rb +101 -93
- data/lib/rdoc/tom_doc.rb +203 -201
- data/lib/rdoc/version.rb +1 -1
- metadata +4 -5
- data/lib/rdoc/markdown/literals.kpeg +0 -21
- data/lib/rdoc/markdown/literals.rb +0 -454
|
@@ -1,317 +1,321 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# is
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
else
|
|
128
|
-
comment = text
|
|
129
|
-
end
|
|
36
|
+
##
|
|
37
|
+
# Registered post-processors
|
|
130
38
|
|
|
131
|
-
|
|
39
|
+
def self.post_processors
|
|
40
|
+
@post_processors
|
|
41
|
+
end
|
|
132
42
|
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
59
|
+
##
|
|
60
|
+
# Registered directives
|
|
137
61
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
66
|
+
##
|
|
67
|
+
# Clears all registered directives and post-processors
|
|
151
68
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
end
|
|
69
|
+
def self.reset
|
|
70
|
+
@post_processors = []
|
|
71
|
+
@registered = {}
|
|
72
|
+
end
|
|
157
73
|
|
|
158
|
-
|
|
74
|
+
reset
|
|
159
75
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
127
|
+
if comment
|
|
128
|
+
comment.text = text
|
|
129
|
+
else
|
|
130
|
+
comment = text
|
|
131
|
+
end
|
|
222
132
|
|
|
223
|
-
|
|
224
|
-
when 'startdoc' then
|
|
225
|
-
return blankline unless code_object
|
|
133
|
+
run_post_processes(comment, code_object)
|
|
226
134
|
|
|
227
|
-
|
|
228
|
-
|
|
135
|
+
text
|
|
136
|
+
end
|
|
229
137
|
|
|
230
|
-
|
|
231
|
-
when 'stopdoc' then
|
|
232
|
-
return blankline unless code_object
|
|
138
|
+
# Apply directives to a code object
|
|
233
139
|
|
|
234
|
-
code_object
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
-
else
|
|
246
|
-
result = yield directive, param if block_given?
|
|
160
|
+
# Parse comment and return [normalized_comment_text, directives_hash]
|
|
247
161
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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 =
|
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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
|
-
|
|
290
|
-
|
|
294
|
+
# strip magic comment
|
|
295
|
+
content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
|
|
291
296
|
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
305
|
-
|
|
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
|
data/lib/rdoc/markup/raw.rb
CHANGED
data/lib/rdoc/markup/rule.rb
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class Markup
|
|
4
|
+
##
|
|
5
|
+
# A horizontal rule with a weight
|
|
4
6
|
|
|
5
|
-
class
|
|
7
|
+
class Rule < Struct.new :weight
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
##
|
|
10
|
+
# Calls #accept_rule on +visitor+
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|