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
@@ -1,377 +0,0 @@
|
|
1
|
-
require 'rdoc/markup'
|
2
|
-
require 'rdoc/markup/lines'
|
3
|
-
|
4
|
-
class RDoc::Markup
|
5
|
-
|
6
|
-
##
|
7
|
-
# A Fragment is a chunk of text, subclassed as a paragraph, a list
|
8
|
-
# entry, or verbatim text.
|
9
|
-
|
10
|
-
class Fragment
|
11
|
-
attr_reader :level, :param, :txt
|
12
|
-
attr_accessor :type
|
13
|
-
|
14
|
-
##
|
15
|
-
# This is a simple factory system that lets us associate fragement
|
16
|
-
# types (a string) with a subclass of fragment
|
17
|
-
|
18
|
-
TYPE_MAP = {}
|
19
|
-
|
20
|
-
def self.type_name(name)
|
21
|
-
TYPE_MAP[name] = self
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.for(line)
|
25
|
-
klass = TYPE_MAP[line.type] ||
|
26
|
-
raise("Unknown line type: '#{line.type.inspect}:' '#{line.text}'")
|
27
|
-
return klass.new(line.level, line.param, line.flag, line.text)
|
28
|
-
end
|
29
|
-
|
30
|
-
def initialize(level, param, type, txt)
|
31
|
-
@level = level
|
32
|
-
@param = param
|
33
|
-
@type = type
|
34
|
-
@txt = ""
|
35
|
-
add_text(txt) if txt
|
36
|
-
end
|
37
|
-
|
38
|
-
def add_text(txt)
|
39
|
-
@txt << " " if @txt.length > 0
|
40
|
-
@txt << txt.tr_s("\n ", " ").strip
|
41
|
-
end
|
42
|
-
|
43
|
-
def to_s
|
44
|
-
"L#@level: #{self.class.name.split('::')[-1]}\n#@txt"
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# A paragraph is a fragment which gets wrapped to fit. We remove all
|
51
|
-
# newlines when we're created, and have them put back on output.
|
52
|
-
|
53
|
-
class Paragraph < Fragment
|
54
|
-
type_name :PARAGRAPH
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
# An empty line
|
59
|
-
|
60
|
-
class BlankLine < Paragraph
|
61
|
-
type_name :BLANK
|
62
|
-
end
|
63
|
-
|
64
|
-
##
|
65
|
-
# A heading
|
66
|
-
|
67
|
-
class Heading < Paragraph
|
68
|
-
type_name :HEADING
|
69
|
-
|
70
|
-
##
|
71
|
-
# Level of heading, smaller is more important
|
72
|
-
|
73
|
-
def head_level
|
74
|
-
@param.to_i
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# A List is a fragment with some kind of label
|
81
|
-
|
82
|
-
class ListBase < Paragraph
|
83
|
-
LIST_TYPES = [
|
84
|
-
:BULLET,
|
85
|
-
:NUMBER,
|
86
|
-
:UPPERALPHA,
|
87
|
-
:LOWERALPHA,
|
88
|
-
:LABELED,
|
89
|
-
:NOTE,
|
90
|
-
]
|
91
|
-
end
|
92
|
-
|
93
|
-
##
|
94
|
-
# An item in a list
|
95
|
-
|
96
|
-
class ListItem < ListBase
|
97
|
-
type_name :LIST
|
98
|
-
|
99
|
-
def to_s # :nodoc:
|
100
|
-
text = if [:NOTE, :LABELED].include? type then
|
101
|
-
"#{@param}: #{@txt}"
|
102
|
-
else
|
103
|
-
@txt
|
104
|
-
end
|
105
|
-
|
106
|
-
"L#@level: #{type} #{self.class.name.split('::')[-1]}\n#{text}"
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
##
|
112
|
-
# Start of a list
|
113
|
-
|
114
|
-
class ListStart < ListBase
|
115
|
-
|
116
|
-
##
|
117
|
-
# Creates a ListStart with nesting +level+
|
118
|
-
|
119
|
-
def initialize(level, param, type)
|
120
|
-
super(level, param, type, nil)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
##
|
125
|
-
# End of a list
|
126
|
-
|
127
|
-
class ListEnd < ListBase
|
128
|
-
|
129
|
-
##
|
130
|
-
# Creates a ListEnd with nesting +level+
|
131
|
-
|
132
|
-
def initialize(level, type)
|
133
|
-
super(level, "", type, nil)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
##
|
138
|
-
# Verbatim code contains lines that don't get wrapped.
|
139
|
-
|
140
|
-
class Verbatim < Fragment
|
141
|
-
type_name :VERBATIM
|
142
|
-
|
143
|
-
##
|
144
|
-
# Adds +txt+ to this verbatim
|
145
|
-
|
146
|
-
def add_text(txt)
|
147
|
-
@txt << txt.chomp << "\n"
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
##
|
153
|
-
# A horizontal rule
|
154
|
-
|
155
|
-
class Rule < Fragment
|
156
|
-
type_name :RULE
|
157
|
-
end
|
158
|
-
|
159
|
-
##
|
160
|
-
# Collect groups of lines together. Each group will end up containing a flow
|
161
|
-
# of text.
|
162
|
-
|
163
|
-
class LineCollection
|
164
|
-
|
165
|
-
##
|
166
|
-
# Creates a new collection of lines
|
167
|
-
|
168
|
-
def initialize
|
169
|
-
@fragments = []
|
170
|
-
end
|
171
|
-
|
172
|
-
##
|
173
|
-
# Adds +fragment+ to the collection
|
174
|
-
|
175
|
-
def add(fragment)
|
176
|
-
@fragments << fragment
|
177
|
-
end
|
178
|
-
|
179
|
-
##
|
180
|
-
# Iterates over the lines in the collection
|
181
|
-
|
182
|
-
def each(&b)
|
183
|
-
@fragments.each(&b)
|
184
|
-
end
|
185
|
-
|
186
|
-
def to_a # :nodoc:
|
187
|
-
@fragments.map {|fragment| fragment.to_s}
|
188
|
-
end
|
189
|
-
|
190
|
-
##
|
191
|
-
# Factory for different fragment types
|
192
|
-
|
193
|
-
def fragment_for(*args)
|
194
|
-
Fragment.for(*args)
|
195
|
-
end
|
196
|
-
|
197
|
-
##
|
198
|
-
# Tidy up at the end
|
199
|
-
|
200
|
-
def normalize
|
201
|
-
change_verbatim_blank_lines
|
202
|
-
add_list_start_and_ends
|
203
|
-
add_list_breaks
|
204
|
-
tidy_blank_lines
|
205
|
-
end
|
206
|
-
|
207
|
-
def to_s # :nodoc:
|
208
|
-
@fragments.join("\n----\n")
|
209
|
-
end
|
210
|
-
|
211
|
-
def accept(am, visitor)
|
212
|
-
visitor.start_accepting
|
213
|
-
|
214
|
-
@fragments.each do |fragment|
|
215
|
-
case fragment
|
216
|
-
when Verbatim
|
217
|
-
visitor.accept_verbatim(am, fragment)
|
218
|
-
when Rule
|
219
|
-
visitor.accept_rule(am, fragment)
|
220
|
-
when ListStart
|
221
|
-
visitor.accept_list_start(am, fragment)
|
222
|
-
when ListEnd
|
223
|
-
visitor.accept_list_end(am, fragment)
|
224
|
-
when ListItem
|
225
|
-
visitor.accept_list_item(am, fragment)
|
226
|
-
when BlankLine
|
227
|
-
visitor.accept_blank_line(am, fragment)
|
228
|
-
when Heading
|
229
|
-
visitor.accept_heading(am, fragment)
|
230
|
-
when Paragraph
|
231
|
-
visitor.accept_paragraph(am, fragment)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
visitor.end_accepting
|
236
|
-
end
|
237
|
-
|
238
|
-
private
|
239
|
-
|
240
|
-
##
|
241
|
-
# If you have:
|
242
|
-
#
|
243
|
-
# normal paragraph text.
|
244
|
-
#
|
245
|
-
# this is code
|
246
|
-
#
|
247
|
-
# and more code
|
248
|
-
#
|
249
|
-
# You'll end up with the fragments Paragraph, BlankLine, Verbatim,
|
250
|
-
# BlankLine, Verbatim, BlankLine, etc.
|
251
|
-
#
|
252
|
-
# The BlankLine in the middle of the verbatim chunk needs to be changed to
|
253
|
-
# a real verbatim newline, and the two verbatim blocks merged
|
254
|
-
|
255
|
-
def change_verbatim_blank_lines
|
256
|
-
frag_block = nil
|
257
|
-
blank_count = 0
|
258
|
-
@fragments.each_with_index do |frag, i|
|
259
|
-
if frag_block.nil?
|
260
|
-
frag_block = frag if Verbatim === frag
|
261
|
-
else
|
262
|
-
case frag
|
263
|
-
when Verbatim
|
264
|
-
blank_count.times { frag_block.add_text("\n") }
|
265
|
-
blank_count = 0
|
266
|
-
frag_block.add_text(frag.txt)
|
267
|
-
@fragments[i] = nil # remove out current fragment
|
268
|
-
when BlankLine
|
269
|
-
if frag_block
|
270
|
-
blank_count += 1
|
271
|
-
@fragments[i] = nil
|
272
|
-
end
|
273
|
-
else
|
274
|
-
frag_block = nil
|
275
|
-
blank_count = 0
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
@fragments.compact!
|
280
|
-
end
|
281
|
-
|
282
|
-
##
|
283
|
-
# List nesting is implicit given the level of indentation. Make it
|
284
|
-
# explicit, just to make life a tad easier for the output processors
|
285
|
-
|
286
|
-
def add_list_start_and_ends
|
287
|
-
level = 0
|
288
|
-
res = []
|
289
|
-
type_stack = []
|
290
|
-
|
291
|
-
@fragments.each do |fragment|
|
292
|
-
# $stderr.puts "#{level} : #{fragment.class.name} : #{fragment.level}"
|
293
|
-
new_level = fragment.level
|
294
|
-
while (level < new_level)
|
295
|
-
level += 1
|
296
|
-
type = fragment.type
|
297
|
-
res << ListStart.new(level, fragment.param, type) if type
|
298
|
-
type_stack.push type
|
299
|
-
# $stderr.puts "Start: #{level}"
|
300
|
-
end
|
301
|
-
|
302
|
-
while level > new_level
|
303
|
-
type = type_stack.pop
|
304
|
-
res << ListEnd.new(level, type) if type
|
305
|
-
level -= 1
|
306
|
-
# $stderr.puts "End: #{level}, #{type}"
|
307
|
-
end
|
308
|
-
|
309
|
-
res << fragment
|
310
|
-
level = fragment.level
|
311
|
-
end
|
312
|
-
level.downto(1) do |i|
|
313
|
-
type = type_stack.pop
|
314
|
-
res << ListEnd.new(i, type) if type
|
315
|
-
end
|
316
|
-
|
317
|
-
@fragments = res
|
318
|
-
end
|
319
|
-
|
320
|
-
##
|
321
|
-
# Inserts start/ends between list entries at the same level that have
|
322
|
-
# different element types
|
323
|
-
|
324
|
-
def add_list_breaks
|
325
|
-
res = @fragments
|
326
|
-
|
327
|
-
@fragments = []
|
328
|
-
list_stack = []
|
329
|
-
|
330
|
-
res.each do |fragment|
|
331
|
-
case fragment
|
332
|
-
when ListStart
|
333
|
-
list_stack.push fragment
|
334
|
-
when ListEnd
|
335
|
-
start = list_stack.pop
|
336
|
-
fragment.type = start.type
|
337
|
-
when ListItem
|
338
|
-
l = list_stack.last
|
339
|
-
if fragment.type != l.type
|
340
|
-
@fragments << ListEnd.new(l.level, l.type)
|
341
|
-
start = ListStart.new(l.level, fragment.param, fragment.type)
|
342
|
-
@fragments << start
|
343
|
-
list_stack.pop
|
344
|
-
list_stack.push start
|
345
|
-
end
|
346
|
-
else
|
347
|
-
;
|
348
|
-
end
|
349
|
-
@fragments << fragment
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
##
|
354
|
-
# Tidy up the blank lines:
|
355
|
-
# * change Blank/ListEnd into ListEnd/Blank
|
356
|
-
# * remove blank lines at the front
|
357
|
-
|
358
|
-
def tidy_blank_lines
|
359
|
-
(@fragments.size - 1).times do |i|
|
360
|
-
if BlankLine === @fragments[i] and ListEnd === @fragments[i+1] then
|
361
|
-
@fragments[i], @fragments[i+1] = @fragments[i+1], @fragments[i]
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
# remove leading blanks
|
366
|
-
@fragments.each_with_index do |f, i|
|
367
|
-
break unless f.kind_of? BlankLine
|
368
|
-
@fragments[i] = nil
|
369
|
-
end
|
370
|
-
|
371
|
-
@fragments.compact!
|
372
|
-
end
|
373
|
-
|
374
|
-
end
|
375
|
-
|
376
|
-
end
|
377
|
-
|
data/lib/rdoc/markup/lines.rb
DELETED
@@ -1,156 +0,0 @@
|
|
1
|
-
class RDoc::Markup
|
2
|
-
|
3
|
-
##
|
4
|
-
# We store the lines we're working on as objects of class Line. These
|
5
|
-
# contain the text of the line, along with a flag indicating the line type,
|
6
|
-
# and an indentation level.
|
7
|
-
|
8
|
-
class Line
|
9
|
-
|
10
|
-
##
|
11
|
-
# Not really
|
12
|
-
|
13
|
-
INFINITY = 9999
|
14
|
-
|
15
|
-
LINE_TYPES = [
|
16
|
-
:BLANK,
|
17
|
-
:HEADING,
|
18
|
-
:LIST,
|
19
|
-
:PARAGRAPH,
|
20
|
-
:RULE,
|
21
|
-
:VERBATIM,
|
22
|
-
]
|
23
|
-
|
24
|
-
# line type
|
25
|
-
attr_accessor :type
|
26
|
-
|
27
|
-
# The indentation nesting level
|
28
|
-
attr_accessor :level
|
29
|
-
|
30
|
-
# The contents
|
31
|
-
attr_accessor :text
|
32
|
-
|
33
|
-
# A prefix or parameter. For LIST lines, this is
|
34
|
-
# the text that introduced the list item (the label)
|
35
|
-
attr_accessor :param
|
36
|
-
|
37
|
-
# A flag. For list lines, this is the type of the list
|
38
|
-
attr_accessor :flag
|
39
|
-
|
40
|
-
# the number of leading spaces
|
41
|
-
attr_accessor :leading_spaces
|
42
|
-
|
43
|
-
# true if this line has been deleted from the list of lines
|
44
|
-
attr_accessor :deleted
|
45
|
-
|
46
|
-
def initialize(text)
|
47
|
-
@text = text.dup
|
48
|
-
@deleted = false
|
49
|
-
|
50
|
-
# expand tabs
|
51
|
-
1 while @text.gsub!(/\t+/) { ' ' * (8*$&.length - $`.length % 8)} && $~ #`
|
52
|
-
|
53
|
-
# Strip trailing whitespace
|
54
|
-
@text.sub!(/\s+$/, '')
|
55
|
-
|
56
|
-
# and look for leading whitespace
|
57
|
-
if @text.length > 0
|
58
|
-
@text =~ /^(\s*)/
|
59
|
-
@leading_spaces = $1.length
|
60
|
-
else
|
61
|
-
@leading_spaces = INFINITY
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Return true if this line is blank
|
66
|
-
def blank?
|
67
|
-
@text.empty?
|
68
|
-
end
|
69
|
-
|
70
|
-
# stamp a line with a type, a level, a prefix, and a flag
|
71
|
-
def stamp(type, level, param="", flag=nil)
|
72
|
-
@type, @level, @param, @flag = type, level, param, flag
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# Strip off the leading margin
|
77
|
-
|
78
|
-
def strip_leading(size)
|
79
|
-
if @text.size > size
|
80
|
-
@text[0,size] = ""
|
81
|
-
else
|
82
|
-
@text = ""
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def to_s
|
87
|
-
"#@type#@level: #@text"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
##
|
92
|
-
# A container for all the lines.
|
93
|
-
|
94
|
-
class Lines
|
95
|
-
|
96
|
-
include Enumerable
|
97
|
-
|
98
|
-
attr_reader :lines # :nodoc:
|
99
|
-
|
100
|
-
def initialize(lines)
|
101
|
-
@lines = lines
|
102
|
-
rewind
|
103
|
-
end
|
104
|
-
|
105
|
-
def empty?
|
106
|
-
@lines.size.zero?
|
107
|
-
end
|
108
|
-
|
109
|
-
def each
|
110
|
-
@lines.each do |line|
|
111
|
-
yield line unless line.deleted
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# def [](index)
|
116
|
-
# @lines[index]
|
117
|
-
# end
|
118
|
-
|
119
|
-
def rewind
|
120
|
-
@nextline = 0
|
121
|
-
end
|
122
|
-
|
123
|
-
def next
|
124
|
-
begin
|
125
|
-
res = @lines[@nextline]
|
126
|
-
@nextline += 1 if @nextline < @lines.size
|
127
|
-
end while res and res.deleted and @nextline < @lines.size
|
128
|
-
res
|
129
|
-
end
|
130
|
-
|
131
|
-
def unget
|
132
|
-
@nextline -= 1
|
133
|
-
end
|
134
|
-
|
135
|
-
def delete(a_line)
|
136
|
-
a_line.deleted = true
|
137
|
-
end
|
138
|
-
|
139
|
-
def normalize
|
140
|
-
margin = @lines.collect{|l| l.leading_spaces}.min
|
141
|
-
margin = 0 if margin == :INFINITY
|
142
|
-
@lines.each {|line| line.strip_leading(margin) } if margin > 0
|
143
|
-
end
|
144
|
-
|
145
|
-
def as_text
|
146
|
-
@lines.map {|l| l.text}.join("\n")
|
147
|
-
end
|
148
|
-
|
149
|
-
def line_types
|
150
|
-
@lines.map {|l| l.type }
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|