Class: AbstractFormatter
Overview
Instance Method Summary
collapse
#pop_alignment, #pop_style, #push_alignment, #push_style
Constructor Details
Returns a new instance of AbstractFormatter.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/web/unit/formatter.rb', line 30
def initialize(writer)
@writer = writer
@align = nil
@align_stack = []
@font_stack = []
@margin_stack = []
@spacing = nil
@style_stack = []
@nospace = true
@softspace = false
@para_end = true
@parskip = 0
@hard_break = true
@have_label = false
end
|
Instance Method Details
#add_flowing_data(data) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/web/unit/formatter.rb', line 102
def add_flowing_data(data)
return if not data
prespace = (/^\s/ =~ data)
postspace = (/\s$/ =~ data)
data = data.split.join(" ")
if @nospace and data.length < 1
return
elsif prespace or @softspace
if data.length == 0
if not @nospace
@softspace = true
@parskip = 0
end
return
end
if not @nospace
data = ' ' + data
end
end
@hard_break = @nospace = @para_end = false
@have_label = false
@parskip = 0
@softspace = postspace
@writer.send_flowing_data(data)
end
|
#add_hor_rule ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/web/unit/formatter.rb', line 73
def add_hor_rule
if not @hard_break
@writer.send_line_break
end
@writer.send_hor_rule @hard_break = true
@nospace = true
@have_label = false
@para_end = false
@softspace = false
@parskip = 0
end
|
#add_label_data(format, counter, blankline = nil) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/web/unit/formatter.rb', line 86
def add_label_data(format, counter, blankline = nil)
if @have_label or !@hard_break
@writer.send_line_break
end
if not @para_end
@writer.send_paragraph(1) end
if format.kind_of? String
else
@writer.send_label_data(format)
end
@nospace = @have_label = @hard_break = @para_end = 1
@softspace = @parskip = 0
end
|
#add_line_break ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/web/unit/formatter.rb', line 62
def add_line_break
if not (@hard_break or @para_end)
@writer.send_line_break
@have_label = false
@parskip = 0
end
@hard_break = true
@nospace = true
@softspace = false
end
|
#add_literal_data(data) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/web/unit/formatter.rb', line 128
def add_literal_data(data)
return if not data
if @softspace
@writer.send_flowing_data("_")
end
@hard_break = (data[-1,1] == "\n")
@nospace = @para_end = @softspace = false
@have_label = false
@parskip = 0
@writer.send_literal_data(data)
end
|
#assert_line_data(flag = true) ⇒ Object
219
220
221
222
223
224
225
|
# File 'lib/web/unit/formatter.rb', line 219
def assert_line_data(flag=true)
@nospace = !flag
@hard_break = !flag
@para_end = false
@have_label = false
@parskip = 0
end
|
#end_paragraph(blankline) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/web/unit/formatter.rb', line 46
def end_paragraph(blankline)
if not @hard_break
@writer.send_line_break
@have_label = false
end
if (@parskip < blankline) and !@have_label
@writer.send_paragraph(blankline - @parskip)
@parskip = blankline
@have_label = 0
end
@hard_break = true
@nospace = true
@para_end = true
@softspace = false
end
|
#flush_softspace ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/web/unit/formatter.rb', line 140
def flush_softspace
if @softspace
@hard_break = false
@para_end = false
@have_label = false
@softspace = false
@parskip = 0
@nospace = true
@writer.send_flowing_data(' ')
end
end
|
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/web/unit/formatter.rb', line 180
def pop_font
if @font_stack.length > 0
@font_stack.pop
end
if @font_stack
font = @font_stack[-1]
else
font = nil
end
@writer.new_font(font)
end
|
#pop_margin ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/web/unit/formatter.rb', line 201
def pop_margin
if @margin_stack
@margin_stack.pop
end
fstack = @margin_stack.compact
if fstack.length > 0
margin = fstack[-1]
else
margin = nil
end
@writer.new_margin(margin, fstack.length)
end
|
#push_font(size, i, b, tt) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/web/unit/formatter.rb', line 152
def push_font(size, i, b, tt)
if @softspace
@hard_break = false
@para_end = false
@softspace = false
@nospace = true
@writer.send_flowing_data(' ')
end
if @font_stack.length > 0
csize, ci, cb, ctt = @font_stack[-1]
if size == nil
size = csize
end
if i == nil
i = ci
end
if b == nil
b = cb
end
if tt == nil
tt = ctt
end
end
font = [size, i, b, tt]
@font_stack << font
@writer.new_font(font)
end
|
#push_margin(margin) ⇒ Object
192
193
194
195
196
197
198
199
|
# File 'lib/web/unit/formatter.rb', line 192
def push_margin(margin)
@margin_stack << margin
fstack = @margin_stack.compact
if (!margin) && (fstack.length > 0)
margin = fstack[-1]
end
@writer.new_margin(margin, fstack.length)
end
|
#set_spacing(spacing) ⇒ Object
214
215
216
217
|
# File 'lib/web/unit/formatter.rb', line 214
def set_spacing(spacing)
@spacing = spacing
@writer.new_spacing(spacing)
end
|