rdoc 2.4.3 → 2.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/.autotest +3 -1
- data/History.txt +68 -0
- data/LICENSE.txt +57 -0
- data/Manifest.txt +37 -19
- data/README.txt +2 -12
- data/Rakefile +12 -12
- data/bin/rdoc +4 -4
- data/lib/rdoc.rb +32 -9
- data/lib/rdoc/alias.rb +2 -2
- data/lib/rdoc/any_method.rb +108 -16
- data/lib/rdoc/attr.rb +87 -1
- data/lib/rdoc/class_module.rb +131 -5
- data/lib/rdoc/code_object.rb +28 -5
- data/lib/rdoc/constant.rb +22 -0
- data/lib/rdoc/context.rb +80 -37
- data/lib/rdoc/gauntlet.rb +48 -0
- data/lib/rdoc/generator/darkfish.rb +25 -23
- data/lib/rdoc/generator/markup.rb +6 -29
- data/lib/rdoc/generator/ri.rb +39 -189
- data/lib/rdoc/generator/template/darkfish/classpage.rhtml +17 -1
- data/lib/rdoc/generator/template/darkfish/filepage.rhtml +10 -0
- data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/rdoc.css +38 -33
- data/lib/rdoc/include.rb +22 -0
- data/lib/rdoc/markup.rb +10 -262
- data/lib/rdoc/markup/attribute_manager.rb +57 -50
- data/lib/rdoc/markup/blank_line.rb +19 -0
- data/lib/rdoc/markup/document.rb +72 -0
- data/lib/rdoc/markup/formatter.rb +118 -0
- data/lib/rdoc/markup/formatter_test_case.rb +341 -0
- data/lib/rdoc/markup/heading.rb +17 -0
- data/lib/rdoc/markup/inline.rb +6 -5
- data/lib/rdoc/markup/list.rb +78 -0
- data/lib/rdoc/markup/list_item.rb +83 -0
- data/lib/rdoc/markup/paragraph.rb +66 -0
- data/lib/rdoc/markup/parser.rb +528 -0
- data/lib/rdoc/markup/rule.rb +17 -0
- data/lib/rdoc/markup/to_ansi.rb +72 -0
- data/lib/rdoc/markup/to_bs.rb +74 -0
- data/lib/rdoc/markup/to_html.rb +106 -172
- data/lib/rdoc/markup/to_html_crossref.rb +10 -4
- data/lib/rdoc/markup/to_rdoc.rb +243 -0
- data/lib/rdoc/markup/to_test.rb +27 -16
- data/lib/rdoc/markup/verbatim.rb +42 -0
- data/lib/rdoc/normal_class.rb +38 -1
- data/lib/rdoc/normal_module.rb +38 -8
- data/lib/rdoc/options.rb +39 -151
- data/lib/rdoc/parser.rb +36 -18
- data/lib/rdoc/parser/c.rb +102 -109
- data/lib/rdoc/parser/ruby.rb +359 -1662
- data/lib/rdoc/parser/ruby_tools.rb +157 -0
- data/lib/rdoc/parser/simple.rb +0 -2
- data/lib/rdoc/rdoc.rb +142 -82
- data/lib/rdoc/ri.rb +10 -0
- data/lib/rdoc/ri/driver.rb +674 -444
- data/lib/rdoc/ri/formatter.rb +2 -651
- data/lib/rdoc/ri/paths.rb +70 -45
- data/lib/rdoc/ri/store.rb +248 -0
- data/lib/rdoc/ruby_lex.rb +1284 -0
- data/lib/rdoc/ruby_token.rb +416 -0
- data/lib/rdoc/single_class.rb +5 -0
- data/lib/rdoc/stats.rb +152 -83
- data/lib/rdoc/task.rb +27 -49
- data/lib/rdoc/text.rb +130 -0
- data/lib/rdoc/tokenstream.rb +28 -9
- data/lib/rdoc/top_level.rb +49 -43
- data/test/hidden.zip.txt +1 -0
- data/test/test_attribute_manager.rb +9 -16
- data/test/test_rdoc_any_method.rb +23 -0
- data/test/test_rdoc_attr.rb +40 -0
- data/test/test_rdoc_class_module.rb +100 -0
- data/test/test_rdoc_code_object.rb +18 -2
- data/test/test_rdoc_context.rb +41 -0
- data/test/test_rdoc_generator_ri.rb +56 -0
- data/test/test_rdoc_markup.rb +21 -610
- data/test/test_rdoc_markup_attribute_manager.rb +14 -17
- data/test/test_rdoc_markup_document.rb +51 -0
- data/test/test_rdoc_markup_paragraph.rb +27 -0
- data/test/test_rdoc_markup_parser.rb +1327 -0
- data/test/test_rdoc_markup_to_ansi.rb +426 -0
- data/test/test_rdoc_markup_to_bs.rb +443 -0
- data/test/test_rdoc_markup_to_html.rb +183 -18
- data/test/test_rdoc_markup_to_html_crossref.rb +1 -3
- data/test/test_rdoc_markup_to_rdoc.rb +426 -0
- data/test/test_rdoc_normal_class.rb +17 -0
- data/test/test_rdoc_normal_module.rb +6 -6
- data/test/test_rdoc_options.rb +41 -0
- data/test/test_rdoc_parser.rb +66 -13
- data/test/test_rdoc_parser_c.rb +93 -38
- data/test/test_rdoc_parser_perl.rb +2 -3
- data/test/test_rdoc_parser_ruby.rb +291 -28
- data/test/test_rdoc_parser_simple.rb +48 -0
- data/test/test_rdoc_rdoc.rb +66 -0
- data/test/test_rdoc_ri_driver.rb +752 -38
- data/test/test_rdoc_ri_paths.rb +39 -0
- data/test/test_rdoc_ri_store.rb +309 -0
- data/test/test_rdoc_text.rb +157 -0
- data/test/test_rdoc_top_level.rb +35 -9
- data/test/xref_data.rb +9 -1
- data/test/xref_test_case.rb +8 -3
- metadata +110 -38
- metadata.gz.sig +0 -0
- data/lib/rdoc/cache.rb +0 -41
- data/lib/rdoc/diagram.rb +0 -340
- data/lib/rdoc/dot.rb +0 -249
- data/lib/rdoc/markup/fragments.rb +0 -377
- data/lib/rdoc/markup/lines.rb +0 -156
- data/lib/rdoc/markup/to_flow.rb +0 -211
- data/lib/rdoc/markup/to_latex.rb +0 -328
- data/lib/rdoc/markup/to_texinfo.rb +0 -73
- data/lib/rdoc/ri/cache.rb +0 -187
- data/lib/rdoc/ri/descriptions.rb +0 -156
- data/lib/rdoc/ri/display.rb +0 -340
- data/lib/rdoc/ri/reader.rb +0 -106
- data/lib/rdoc/ri/util.rb +0 -79
- data/lib/rdoc/ri/writer.rb +0 -68
- data/test/test_rdoc_ri_attribute_formatter.rb +0 -44
- data/test/test_rdoc_ri_default_display.rb +0 -302
- data/test/test_rdoc_ri_formatter.rb +0 -320
- data/test/test_rdoc_ri_html_formatter.rb +0 -141
- data/test/test_rdoc_ri_overstrike_formatter.rb +0 -71
data/lib/rdoc/ri/formatter.rb
CHANGED
@@ -1,654 +1,5 @@
|
|
1
|
-
require 'rdoc/ri'
|
2
|
-
require 'rdoc/markup'
|
3
|
-
|
4
|
-
class RDoc::RI::Formatter
|
5
|
-
|
6
|
-
attr_writer :indent
|
7
|
-
attr_accessor :output
|
8
|
-
|
9
|
-
FORMATTERS = { }
|
10
|
-
|
11
|
-
def self.for(name)
|
12
|
-
FORMATTERS[name.downcase]
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.list
|
16
|
-
FORMATTERS.keys.sort.join ", "
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(output, width, indent)
|
20
|
-
@output = output
|
21
|
-
@width = width
|
22
|
-
@indent = indent
|
23
|
-
@original_indent = indent.dup
|
24
|
-
end
|
25
|
-
|
26
|
-
def draw_line(label=nil)
|
27
|
-
len = @width
|
28
|
-
len -= (label.size + 1) if label
|
29
|
-
|
30
|
-
if len > 0 then
|
31
|
-
@output.print '-' * len
|
32
|
-
if label
|
33
|
-
@output.print ' '
|
34
|
-
bold_print label
|
35
|
-
end
|
36
|
-
|
37
|
-
@output.puts
|
38
|
-
else
|
39
|
-
@output.print '-' * @width
|
40
|
-
@output.puts
|
41
|
-
|
42
|
-
@output.puts label
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def indent
|
47
|
-
return @indent unless block_given?
|
48
|
-
|
49
|
-
begin
|
50
|
-
indent = @indent.dup
|
51
|
-
@indent += @original_indent
|
52
|
-
yield
|
53
|
-
ensure
|
54
|
-
@indent = indent
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def wrap(txt, prefix=@indent, linelen=@width)
|
59
|
-
return unless txt && !txt.empty?
|
60
|
-
|
61
|
-
work = conv_markup(txt)
|
62
|
-
textLen = linelen - prefix.length
|
63
|
-
patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
|
64
|
-
next_prefix = prefix.tr("^ ", " ")
|
65
|
-
|
66
|
-
res = []
|
67
|
-
|
68
|
-
while work.length > textLen
|
69
|
-
if work =~ patt
|
70
|
-
res << $1
|
71
|
-
work.slice!(0, $&.length)
|
72
|
-
else
|
73
|
-
res << work.slice!(0, textLen)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
res << work if work.length.nonzero?
|
77
|
-
@output.puts(prefix + res.join("\n" + next_prefix))
|
78
|
-
end
|
79
|
-
|
80
|
-
def blankline
|
81
|
-
@output.puts
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# Called when we want to ensure a new 'wrap' starts on a newline. Only
|
86
|
-
# needed for HtmlFormatter, because the rest do their own line breaking.
|
87
|
-
|
88
|
-
def break_to_newline
|
89
|
-
end
|
90
|
-
|
91
|
-
def bold_print(txt)
|
92
|
-
@output.print txt
|
93
|
-
end
|
94
|
-
|
95
|
-
def raw_print_line(txt)
|
96
|
-
@output.print txt
|
97
|
-
end
|
98
|
-
|
99
|
-
##
|
100
|
-
# Convert HTML entities back to ASCII
|
101
|
-
|
102
|
-
def conv_html(txt)
|
103
|
-
txt = txt.gsub(/>/, '>')
|
104
|
-
txt.gsub!(/</, '<')
|
105
|
-
txt.gsub!(/"/, '"')
|
106
|
-
txt.gsub!(/&/, '&')
|
107
|
-
txt
|
108
|
-
end
|
109
|
-
|
110
|
-
##
|
111
|
-
# Convert markup into display form
|
112
|
-
|
113
|
-
def conv_markup(txt)
|
114
|
-
txt = txt.gsub(%r{<tt>(.*?)</tt>}, '+\1+')
|
115
|
-
txt.gsub!(%r{<code>(.*?)</code>}, '+\1+')
|
116
|
-
txt.gsub!(%r{<b>(.*?)</b>}, '*\1*')
|
117
|
-
txt.gsub!(%r{<em>(.*?)</em>}, '_\1_')
|
118
|
-
txt
|
119
|
-
end
|
120
|
-
|
121
|
-
def display_list(list)
|
122
|
-
case list.type
|
123
|
-
when :BULLET
|
124
|
-
prefixer = proc { |ignored| @indent + "* " }
|
125
|
-
|
126
|
-
when :NUMBER, :UPPERALPHA, :LOWERALPHA then
|
127
|
-
start = case list.type
|
128
|
-
when :NUMBER then 1
|
129
|
-
when :UPPERALPHA then 'A'
|
130
|
-
when :LOWERALPHA then 'a'
|
131
|
-
end
|
132
|
-
|
133
|
-
prefixer = proc do |ignored|
|
134
|
-
res = @indent + "#{start}.".ljust(4)
|
135
|
-
start = start.succ
|
136
|
-
res
|
137
|
-
end
|
138
|
-
|
139
|
-
when :LABELED, :NOTE then
|
140
|
-
longest = 0
|
141
|
-
|
142
|
-
list.contents.each do |item|
|
143
|
-
if RDoc::Markup::Flow::LI === item and item.label.length > longest then
|
144
|
-
longest = item.label.length
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
longest += 1
|
149
|
-
|
150
|
-
prefixer = proc { |li| @indent + li.label.ljust(longest) }
|
151
|
-
|
152
|
-
else
|
153
|
-
raise ArgumentError, "unknown list type #{list.type}"
|
154
|
-
end
|
155
|
-
|
156
|
-
list.contents.each do |item|
|
157
|
-
if RDoc::Markup::Flow::LI === item then
|
158
|
-
prefix = prefixer.call item
|
159
|
-
display_flow_item item, prefix
|
160
|
-
else
|
161
|
-
display_flow_item item
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def display_flow_item(item, prefix = @indent)
|
167
|
-
case item
|
168
|
-
when RDoc::Markup::Flow::P, RDoc::Markup::Flow::LI
|
169
|
-
wrap(conv_html(item.body), prefix)
|
170
|
-
blankline
|
171
|
-
|
172
|
-
when RDoc::Markup::Flow::LIST
|
173
|
-
display_list(item)
|
174
|
-
|
175
|
-
when RDoc::Markup::Flow::VERB
|
176
|
-
display_verbatim_flow_item(item, @indent)
|
177
|
-
|
178
|
-
when RDoc::Markup::Flow::H
|
179
|
-
display_heading(conv_html(item.text), item.level, @indent)
|
180
|
-
|
181
|
-
when RDoc::Markup::Flow::RULE
|
182
|
-
draw_line
|
183
|
-
|
184
|
-
else
|
185
|
-
raise RDoc::Error, "Unknown flow element: #{item.class}"
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def display_verbatim_flow_item(item, prefix=@indent)
|
190
|
-
item.body.split(/\n/).each do |line|
|
191
|
-
@output.print @indent, conv_html(line), "\n"
|
192
|
-
end
|
193
|
-
blankline
|
194
|
-
end
|
195
|
-
|
196
|
-
def display_heading(text, level, indent)
|
197
|
-
text = strip_attributes text
|
198
|
-
|
199
|
-
case level
|
200
|
-
when 1 then
|
201
|
-
ul = "=" * text.length
|
202
|
-
@output.puts
|
203
|
-
@output.puts text.upcase
|
204
|
-
@output.puts ul
|
205
|
-
|
206
|
-
when 2 then
|
207
|
-
ul = "-" * text.length
|
208
|
-
@output.puts
|
209
|
-
@output.puts text
|
210
|
-
@output.puts ul
|
211
|
-
else
|
212
|
-
@output.print indent, text, "\n"
|
213
|
-
end
|
214
|
-
|
215
|
-
@output.puts
|
216
|
-
end
|
217
|
-
|
218
|
-
def display_flow(flow)
|
219
|
-
flow.each do |f|
|
220
|
-
display_flow_item(f)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
def strip_attributes(text)
|
225
|
-
text.gsub(/(<\/?(?:b|code|em|i|tt)>)/, '')
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
##
|
231
|
-
# Handle text with attributes. We're a base class: there are different
|
232
|
-
# presentation classes (one, for example, uses overstrikes to handle bold and
|
233
|
-
# underlining, while another using ANSI escape sequences.
|
234
|
-
|
235
|
-
class RDoc::RI::AttributeFormatter < RDoc::RI::Formatter
|
236
|
-
|
237
|
-
BOLD = 1
|
238
|
-
ITALIC = 2
|
239
|
-
CODE = 4
|
240
|
-
|
241
|
-
ATTR_MAP = {
|
242
|
-
"b" => BOLD,
|
243
|
-
"code" => CODE,
|
244
|
-
"em" => ITALIC,
|
245
|
-
"i" => ITALIC,
|
246
|
-
"tt" => CODE
|
247
|
-
}
|
248
|
-
|
249
|
-
AttrChar = Struct.new :char, :attr
|
250
|
-
|
251
|
-
class AttributeString
|
252
|
-
attr_reader :txt
|
253
|
-
|
254
|
-
def initialize
|
255
|
-
@txt = []
|
256
|
-
@optr = 0
|
257
|
-
end
|
258
|
-
|
259
|
-
def <<(char)
|
260
|
-
@txt << char
|
261
|
-
end
|
262
|
-
|
263
|
-
def empty?
|
264
|
-
@optr >= @txt.length
|
265
|
-
end
|
266
|
-
|
267
|
-
# accept non space, then all following spaces
|
268
|
-
def next_word
|
269
|
-
start = @optr
|
270
|
-
len = @txt.length
|
271
|
-
|
272
|
-
while @optr < len && @txt[@optr].char != " "
|
273
|
-
@optr += 1
|
274
|
-
end
|
275
|
-
|
276
|
-
while @optr < len && @txt[@optr].char == " "
|
277
|
-
@optr += 1
|
278
|
-
end
|
279
|
-
|
280
|
-
@txt[start...@optr]
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
##
|
285
|
-
# Overrides base class. Looks for <tt>...</tt> etc sequences and generates
|
286
|
-
# an array of AttrChars. This array is then used as the basis for the
|
287
|
-
# split.
|
288
|
-
|
289
|
-
def wrap(txt, prefix=@indent, linelen=@width)
|
290
|
-
return unless txt && !txt.empty?
|
291
|
-
|
292
|
-
txt = add_attributes_to(txt)
|
293
|
-
next_prefix = prefix.tr("^ ", " ")
|
294
|
-
linelen -= prefix.size
|
295
|
-
|
296
|
-
line = []
|
297
|
-
|
298
|
-
until txt.empty?
|
299
|
-
word = txt.next_word
|
300
|
-
if word.size + line.size > linelen
|
301
|
-
write_attribute_text(prefix, line)
|
302
|
-
prefix = next_prefix
|
303
|
-
line = []
|
304
|
-
end
|
305
|
-
line.concat(word)
|
306
|
-
end
|
307
|
-
|
308
|
-
write_attribute_text(prefix, line) if line.length > 0
|
309
|
-
end
|
310
|
-
|
311
|
-
protected
|
312
|
-
|
313
|
-
def write_attribute_text(prefix, line)
|
314
|
-
@output.print prefix
|
315
|
-
line.each do |achar|
|
316
|
-
@output.print achar.char
|
317
|
-
end
|
318
|
-
@output.puts
|
319
|
-
end
|
320
|
-
|
321
|
-
def bold_print(txt)
|
322
|
-
@output.print txt
|
323
|
-
end
|
324
|
-
|
325
|
-
private
|
326
|
-
|
327
|
-
def add_attributes_to(txt)
|
328
|
-
tokens = txt.split(%r{(</?(?:b|code|em|i|tt)>)})
|
329
|
-
text = AttributeString.new
|
330
|
-
attributes = 0
|
331
|
-
tokens.each do |tok|
|
332
|
-
case tok
|
333
|
-
when %r{^</(\w+)>$} then attributes &= ~(ATTR_MAP[$1]||0)
|
334
|
-
when %r{^<(\w+)>$} then attributes |= (ATTR_MAP[$1]||0)
|
335
|
-
else
|
336
|
-
tok.split(//).each {|ch| text << AttrChar.new(ch, attributes)}
|
337
|
-
end
|
338
|
-
end
|
339
|
-
text
|
340
|
-
end
|
341
|
-
|
342
|
-
end
|
343
|
-
|
344
1
|
##
|
345
|
-
#
|
346
|
-
# pagers such as man and less.
|
347
|
-
|
348
|
-
class RDoc::RI::OverstrikeFormatter < RDoc::RI::AttributeFormatter
|
349
|
-
|
350
|
-
BS = "\C-h"
|
351
|
-
|
352
|
-
def write_attribute_text(prefix, line)
|
353
|
-
@output.print prefix
|
354
|
-
|
355
|
-
line.each do |achar|
|
356
|
-
attr = achar.attr
|
357
|
-
@output.print "_", BS if (attr & (ITALIC + CODE)) != 0
|
358
|
-
@output.print achar.char, BS if (attr & BOLD) != 0
|
359
|
-
@output.print achar.char
|
360
|
-
end
|
361
|
-
|
362
|
-
@output.puts
|
363
|
-
end
|
364
|
-
|
365
|
-
##
|
366
|
-
# Draw a string in bold
|
367
|
-
|
368
|
-
def bold_print(text)
|
369
|
-
text.split(//).each do |ch|
|
370
|
-
@output.print ch, BS, ch
|
371
|
-
end
|
372
|
-
end
|
2
|
+
# For RubyGems backwards compatibility
|
373
3
|
|
4
|
+
module RDoc::RI::Formatter # :nodoc:
|
374
5
|
end
|
375
|
-
|
376
|
-
##
|
377
|
-
# This formatter uses ANSI escape sequences to colorize stuff works with
|
378
|
-
# pagers such as man and less.
|
379
|
-
|
380
|
-
class RDoc::RI::AnsiFormatter < RDoc::RI::AttributeFormatter
|
381
|
-
|
382
|
-
def initialize(*args)
|
383
|
-
super
|
384
|
-
@output.print "\033[0m"
|
385
|
-
end
|
386
|
-
|
387
|
-
def write_attribute_text(prefix, line)
|
388
|
-
@output.print prefix
|
389
|
-
curr_attr = 0
|
390
|
-
line.each do |achar|
|
391
|
-
attr = achar.attr
|
392
|
-
if achar.attr != curr_attr
|
393
|
-
update_attributes(achar.attr)
|
394
|
-
curr_attr = achar.attr
|
395
|
-
end
|
396
|
-
@output.print achar.char
|
397
|
-
end
|
398
|
-
update_attributes(0) unless curr_attr.zero?
|
399
|
-
@output.puts
|
400
|
-
end
|
401
|
-
|
402
|
-
def bold_print(txt)
|
403
|
-
@output.print "\033[1m#{txt}\033[m"
|
404
|
-
end
|
405
|
-
|
406
|
-
HEADINGS = {
|
407
|
-
1 => ["\033[1;32m", "\033[m"],
|
408
|
-
2 => ["\033[4;32m", "\033[m"],
|
409
|
-
3 => ["\033[32m", "\033[m"],
|
410
|
-
}
|
411
|
-
|
412
|
-
def display_heading(text, level, indent)
|
413
|
-
level = 3 if level > 3
|
414
|
-
heading = HEADINGS[level]
|
415
|
-
@output.print indent
|
416
|
-
@output.print heading[0]
|
417
|
-
@output.print strip_attributes(text)
|
418
|
-
@output.puts heading[1]
|
419
|
-
end
|
420
|
-
|
421
|
-
private
|
422
|
-
|
423
|
-
ATTR_MAP = {
|
424
|
-
BOLD => "1",
|
425
|
-
ITALIC => "33",
|
426
|
-
CODE => "36"
|
427
|
-
}
|
428
|
-
|
429
|
-
def update_attributes(attr)
|
430
|
-
str = "\033["
|
431
|
-
for quality in [ BOLD, ITALIC, CODE]
|
432
|
-
unless (attr & quality).zero?
|
433
|
-
str << ATTR_MAP[quality]
|
434
|
-
end
|
435
|
-
end
|
436
|
-
@output.print str, "m"
|
437
|
-
end
|
438
|
-
|
439
|
-
end
|
440
|
-
|
441
|
-
##
|
442
|
-
# This formatter uses HTML.
|
443
|
-
|
444
|
-
class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter
|
445
|
-
|
446
|
-
##
|
447
|
-
# We depend on HTML4-conforming user agents to ignore an empty p element
|
448
|
-
|
449
|
-
def blankline
|
450
|
-
@output.puts '<p />'
|
451
|
-
end
|
452
|
-
|
453
|
-
##
|
454
|
-
# Emboldens +text+
|
455
|
-
|
456
|
-
def bold_print(text)
|
457
|
-
tag("b") { text }
|
458
|
-
end
|
459
|
-
|
460
|
-
##
|
461
|
-
# Outputs a forced line break element
|
462
|
-
|
463
|
-
def break_to_newline
|
464
|
-
@output.puts '<br />'
|
465
|
-
end
|
466
|
-
|
467
|
-
##
|
468
|
-
# Outputs heading elements for +text+ with +level+ up to 4. Ignores
|
469
|
-
# +indent+.
|
470
|
-
|
471
|
-
def display_heading(text, level, indent)
|
472
|
-
level = 4 if level > 4
|
473
|
-
tag("h#{level}") { text }
|
474
|
-
@output.puts
|
475
|
-
end
|
476
|
-
|
477
|
-
##
|
478
|
-
# Outputs +list+ which is displayed as follows:
|
479
|
-
#
|
480
|
-
# BULLET:: unordered list
|
481
|
-
# NUMBER:: ordered list
|
482
|
-
# LABELED:: definition list
|
483
|
-
# NOTE:: table
|
484
|
-
|
485
|
-
def display_list(list)
|
486
|
-
case list.type
|
487
|
-
when :BULLET then
|
488
|
-
list_type = "ul"
|
489
|
-
prefixer = proc { |ignored| '<li>' }
|
490
|
-
suffix = '</li>'
|
491
|
-
|
492
|
-
when :NUMBER, :UPPERALPHA, :LOWERALPHA then
|
493
|
-
list_type = "ol"
|
494
|
-
prefixer = proc { |ignored| '<li>' }
|
495
|
-
suffix = '</li>'
|
496
|
-
|
497
|
-
when :LABELED then
|
498
|
-
list_type = "dl"
|
499
|
-
prefixer = proc do |li|
|
500
|
-
"<dt><b>#{escape li.label}</b></dt><dd>"
|
501
|
-
end
|
502
|
-
suffix = '</dd>'
|
503
|
-
|
504
|
-
when :NOTE then
|
505
|
-
list_type = "table"
|
506
|
-
prefixer = proc do |li|
|
507
|
-
%{<tr valign="top"><td>#{li.label.gsub(/ /, ' ')}</td><td>}
|
508
|
-
end
|
509
|
-
suffix = '</td></tr>'
|
510
|
-
else
|
511
|
-
fail "unknown list type"
|
512
|
-
end
|
513
|
-
|
514
|
-
@output.print "<#{list_type}>"
|
515
|
-
|
516
|
-
list.contents.each do |item|
|
517
|
-
if item.kind_of? RDoc::Markup::Flow::LI
|
518
|
-
prefix = prefixer.call item
|
519
|
-
@output.print prefix
|
520
|
-
display_flow_item item, prefix
|
521
|
-
@output.print suffix
|
522
|
-
else
|
523
|
-
display_flow_item item
|
524
|
-
end
|
525
|
-
end
|
526
|
-
|
527
|
-
@output.print "</#{list_type}>"
|
528
|
-
end
|
529
|
-
|
530
|
-
##
|
531
|
-
# Outputs a preformatted section for +item+. +prefix+ is ignored.
|
532
|
-
|
533
|
-
def display_verbatim_flow_item(item, prefix=@indent)
|
534
|
-
@output.print '<pre>'
|
535
|
-
|
536
|
-
item.body.split(/\n/).each do |line|
|
537
|
-
@output.puts escape(line)
|
538
|
-
end
|
539
|
-
|
540
|
-
@output.puts '</pre>'
|
541
|
-
end
|
542
|
-
|
543
|
-
##
|
544
|
-
# Outputs a horizontal rule element, optionally labeled above with +label+ in
|
545
|
-
# bold.
|
546
|
-
|
547
|
-
def draw_line(label = nil)
|
548
|
-
bold_print label if label
|
549
|
-
|
550
|
-
@output.puts "<hr />"
|
551
|
-
end
|
552
|
-
|
553
|
-
def write_attribute_text(prefix, line)
|
554
|
-
curr_attr = 0
|
555
|
-
|
556
|
-
line.each do |achar|
|
557
|
-
attr = achar.attr
|
558
|
-
if achar.attr != curr_attr then
|
559
|
-
update_attributes curr_attr, achar.attr
|
560
|
-
curr_attr = achar.attr
|
561
|
-
end
|
562
|
-
@output.print escape(achar.char)
|
563
|
-
end
|
564
|
-
|
565
|
-
update_attributes curr_attr, 0 unless curr_attr.zero?
|
566
|
-
end
|
567
|
-
|
568
|
-
private
|
569
|
-
|
570
|
-
ATTR_MAP = {
|
571
|
-
BOLD => "b>",
|
572
|
-
ITALIC => "i>",
|
573
|
-
CODE => "tt>"
|
574
|
-
}
|
575
|
-
|
576
|
-
def update_attributes(current, wanted)
|
577
|
-
str = ""
|
578
|
-
# first turn off unwanted ones
|
579
|
-
off = current & ~wanted
|
580
|
-
for quality in [ BOLD, ITALIC, CODE]
|
581
|
-
if (off & quality) > 0
|
582
|
-
str << "</" + ATTR_MAP[quality]
|
583
|
-
end
|
584
|
-
end
|
585
|
-
|
586
|
-
# now turn on wanted
|
587
|
-
for quality in [ BOLD, ITALIC, CODE]
|
588
|
-
unless (wanted & quality).zero?
|
589
|
-
str << "<" << ATTR_MAP[quality]
|
590
|
-
end
|
591
|
-
end
|
592
|
-
@output.print str
|
593
|
-
end
|
594
|
-
|
595
|
-
def tag(code)
|
596
|
-
@output.print("<#{code}>")
|
597
|
-
@output.print(yield)
|
598
|
-
@output.print("</#{code}>")
|
599
|
-
end
|
600
|
-
|
601
|
-
def escape(str)
|
602
|
-
str = str.gsub(/&/n, '&')
|
603
|
-
str.gsub!(/\"/n, '"')
|
604
|
-
str.gsub!(/>/n, '>')
|
605
|
-
str.gsub!(/</n, '<')
|
606
|
-
str
|
607
|
-
end
|
608
|
-
|
609
|
-
end
|
610
|
-
|
611
|
-
##
|
612
|
-
# This formatter reduces extra lines for a simpler output. It improves way
|
613
|
-
# output looks for tools like IRC bots.
|
614
|
-
|
615
|
-
class RDoc::RI::SimpleFormatter < RDoc::RI::Formatter
|
616
|
-
|
617
|
-
##
|
618
|
-
# No extra blank lines
|
619
|
-
|
620
|
-
def blankline
|
621
|
-
end
|
622
|
-
|
623
|
-
##
|
624
|
-
# Display labels only, no lines
|
625
|
-
|
626
|
-
def draw_line(label=nil)
|
627
|
-
unless label.nil? then
|
628
|
-
bold_print(label)
|
629
|
-
@output.puts
|
630
|
-
end
|
631
|
-
end
|
632
|
-
|
633
|
-
##
|
634
|
-
# Place heading level indicators inline with heading.
|
635
|
-
|
636
|
-
def display_heading(text, level, indent)
|
637
|
-
text = strip_attributes(text)
|
638
|
-
case level
|
639
|
-
when 1
|
640
|
-
@output.puts "= " + text.upcase
|
641
|
-
when 2
|
642
|
-
@output.puts "-- " + text
|
643
|
-
else
|
644
|
-
@output.print indent, text, "\n"
|
645
|
-
end
|
646
|
-
end
|
647
|
-
|
648
|
-
end
|
649
|
-
|
650
|
-
RDoc::RI::Formatter::FORMATTERS['plain'] = RDoc::RI::Formatter
|
651
|
-
RDoc::RI::Formatter::FORMATTERS['simple'] = RDoc::RI::SimpleFormatter
|
652
|
-
RDoc::RI::Formatter::FORMATTERS['bs'] = RDoc::RI::OverstrikeFormatter
|
653
|
-
RDoc::RI::Formatter::FORMATTERS['ansi'] = RDoc::RI::AnsiFormatter
|
654
|
-
RDoc::RI::Formatter::FORMATTERS['html'] = RDoc::RI::HtmlFormatter
|