Class: ReVIEW::INAOBuilder
Constant Summary
Constants inherited
from Builder
Builder::CAPTION_TITLES
Instance Attribute Summary
Attributes inherited from Builder
#ast, #output
Instance Method Summary
collapse
-
#base_parablock(type, lines, caption = nil) ⇒ Object
-
#cmd(lines, caption = nil) ⇒ Object
-
#column_begin(level, label, caption) ⇒ Object
-
#column_end(level) ⇒ Object
-
#compile_ruby(base, ruby) ⇒ Object
-
#emlist(lines, caption = nil) ⇒ Object
-
#error(msg) ⇒ Object
-
#extname ⇒ Object
-
#footnote(id, str) ⇒ Object
-
#headline(level, label, caption) ⇒ Object
-
#image(lines, id, caption, metric = nil) ⇒ Object
-
#inline_b(str) ⇒ Object
-
#inline_balloon(str) ⇒ Object
-
#inline_cmd(str) ⇒ Object
-
#inline_comment(str) ⇒ Object
-
#inline_fn(id) ⇒ Object
-
#inline_i(str) ⇒ Object
-
#inline_img(id) ⇒ Object
-
#inline_kbd(str) ⇒ Object
-
#inline_keytop(str) ⇒ Object
-
#inline_list(id) ⇒ Object
-
#inline_raw(str) ⇒ Object
-
#inline_table(id) ⇒ Object
-
#inline_tt(str) ⇒ Object
-
#inline_uchar(str) ⇒ Object
-
#list_body(id, lines, lang) ⇒ Object
-
#list_header(id, caption, lang) ⇒ Object
-
#listnum_body(lines, lang) ⇒ Object
-
#messages ⇒ Object
-
#nofunc_text(str) ⇒ Object
-
#noindent ⇒ Object
-
#ol_begin ⇒ Object
-
#ol_end ⇒ Object
-
#ol_item(lines, num) ⇒ Object
-
#paragraph(lines) ⇒ Object
-
#post_paragraph ⇒ Object
-
#pre_paragraph ⇒ Object
-
#quote(lines) ⇒ Object
-
#table(lines, id = nil, caption = nil) ⇒ Object
-
#table_begin(ncols) ⇒ Object
-
#table_end ⇒ Object
-
#table_header(id, caption) ⇒ Object
-
#td(str) ⇒ Object
-
#text(str) ⇒ Object
-
#th(str) ⇒ Object
-
#tr(rows) ⇒ Object
-
#ul_begin ⇒ Object
-
#ul_end ⇒ Object
-
#ul_item(lines) ⇒ Object
-
#warn(msg) ⇒ Object
Methods included from TextUtils
#detab
Methods inherited from Builder
#bibpaper, #bind, #captionblock, #detab, #extract_chapter_id, #get_chap, #graph, #handle_metric, #image_ext, #include, #initialize, #inline_bou, #inline_chap, #inline_chapref, #inline_column, #inline_href, #inline_include, #inline_kw, #inline_ruby, #inline_title, #list, #listnum, #node_inline_hd, #node_inline_img, #node_inline_imgref, #parse_metric, #print, #puts, #raw, #result, #result_metric, #source, #target_name, #ul_item_begin, #ul_item_end
Instance Method Details
#base_parablock(type, lines, caption = nil) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/review/inaobuilder.rb', line 59
def base_parablock(type, lines, caption=nil)
buf = ""
buf << "◆#{@titles[type]}/◆\n"
buf << "■■■■■#{caption}\n" unless caption.nil?
buf << lines.join("")
buf << "◆/#{@titles[type]}◆\n"
buf << "\n"
buf
end
|
#cmd(lines, caption = nil) ⇒ Object
226
227
228
229
230
231
232
233
234
|
# File 'lib/review/inaobuilder.rb', line 226
def cmd(lines, caption = nil)
buf = "◆list-white/◆\n"
buf << %Q[●#{caption}\n] unless caption.nil?
lines.each do |line|
buf << detab(line) << "\n"
end
buf << "◆/list-white◆\n"
buf
end
|
#column_begin(level, label, caption) ⇒ Object
130
131
132
133
134
135
|
# File 'lib/review/inaobuilder.rb', line 130
def column_begin(level, label, caption)
buf = ""
buf << "◆column/◆\n"
buf << "■■■■#{caption}\n"
buf
end
|
#column_end(level) ⇒ Object
137
138
139
|
# File 'lib/review/inaobuilder.rb', line 137
def column_end(level)
"◆/column◆\n"
end
|
#compile_ruby(base, ruby) ⇒ Object
121
122
123
|
# File 'lib/review/inaobuilder.rb', line 121
def compile_ruby(base, ruby)
"◆ルビ/◆#{base}◆#{ruby}◆/ルビ◆"
end
|
#emlist(lines, caption = nil) ⇒ Object
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/review/inaobuilder.rb', line 204
def emlist(lines, caption = nil)
buf = ""
buf << "◆list/◆\n"
buf << %Q[●#{caption}\n] unless caption.nil?
lines.each do |line|
buf << detab(line) << "\n"
end
buf << "◆/list◆\n"
buf
end
|
#error(msg) ⇒ Object
51
52
53
|
# File 'lib/review/inaobuilder.rb', line 51
def error(msg)
$stderr.puts "#{@location.filename}:#{@location.lineno}: error: #{msg}"
end
|
28
29
30
|
# File 'lib/review/inaobuilder.rb', line 28
def extname
'.txt'
end
|
102
103
104
105
|
# File 'lib/review/inaobuilder.rb', line 102
def (id, str)
""
end
|
#headline(level, label, caption) ⇒ Object
69
70
71
72
|
# File 'lib/review/inaobuilder.rb', line 69
def headline(level, label, caption)
prefix = "■" * level
"#{prefix}#{caption}\n"
end
|
#image(lines, id, caption, metric = nil) ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/review/inaobuilder.rb', line 245
def image(lines, id, caption, metric=nil)
buf = ""
if get_chap.nil?
buf << "●図#{@chapter.image(id).number} #{caption}\n"
else
buf << "●図#{get_chap}.#{@chapter.image(id).number} #{caption}\n"
end
if @chapter.image(id).bound?
buf << @chapter.image(id).path << "\n"
else
lines.each do |line|
buf << line + "\n"
end
end
buf
end
|
#inline_b(str) ⇒ Object
86
87
88
|
# File 'lib/review/inaobuilder.rb', line 86
def inline_b(str)
"◆b/◆#{str}◆/b◆"
end
|
#inline_balloon(str) ⇒ Object
217
218
219
|
# File 'lib/review/inaobuilder.rb', line 217
def inline_balloon(str)
"◆comment/◆#{str}◆/comment◆"
end
|
#inline_cmd(str) ⇒ Object
98
99
100
|
# File 'lib/review/inaobuilder.rb', line 98
def inline_cmd(str)
inline_tt(str)
end
|
221
222
223
|
# File 'lib/review/inaobuilder.rb', line 221
def (str)
inline_balloon(str)
end
|
#inline_fn(id) ⇒ Object
107
108
109
|
# File 'lib/review/inaobuilder.rb', line 107
def inline_fn(id)
"◆注/◆#{@chapter.(id).content.strip}◆/注◆"
end
|
#inline_i(str) ⇒ Object
90
91
92
|
# File 'lib/review/inaobuilder.rb', line 90
def inline_i(str)
"◆i/◆#{str}◆/i◆"
end
|
#inline_img(id) ⇒ Object
236
237
238
239
240
241
242
243
|
# File 'lib/review/inaobuilder.rb', line 236
def inline_img(id)
chapter, id = (id)
if get_chap(chapter).nil?
"図#{chapter.image(id).number}"
else
"図#{get_chap(chapter)}.#{chapter.image(id).number}"
end
end
|
#inline_kbd(str) ⇒ Object
115
116
117
|
# File 'lib/review/inaobuilder.rb', line 115
def inline_kbd(str)
inline_keytop(str)
end
|
#inline_keytop(str) ⇒ Object
111
112
113
|
# File 'lib/review/inaobuilder.rb', line 111
def inline_keytop(str)
"#{str}▲"
end
|
#inline_list(id) ⇒ Object
167
168
169
170
171
172
173
174
|
# File 'lib/review/inaobuilder.rb', line 167
def inline_list(id)
chapter, id = (id)
if get_chap(chapter).nil?
%Q[リスト#{@chapter.list(id).number}]
else
%Q[リスト#{get_chap(chapter)}.#{@chapter.list(id).number}]
end
end
|
#inline_raw(str) ⇒ Object
340
341
342
|
# File 'lib/review/inaobuilder.rb', line 340
def inline_raw(str)
%Q[#{super(str).gsub("\\n", "\n")}]
end
|
#inline_table(id) ⇒ Object
262
263
264
265
266
267
268
269
|
# File 'lib/review/inaobuilder.rb', line 262
def inline_table(id)
chapter, id = (id)
if get_chap(chapter).nil?
"表#{chapter.table(id).number}"
else
"表#{get_chap(chapter)}.#{chapter.table(id).number}"
end
end
|
#inline_tt(str) ⇒ Object
94
95
96
|
# File 'lib/review/inaobuilder.rb', line 94
def inline_tt(str)
"◆cmd/◆#{str}◆/cmd◆"
end
|
#inline_uchar(str) ⇒ Object
344
345
346
|
# File 'lib/review/inaobuilder.rb', line 344
def inline_uchar(str)
[str.to_i(16)].pack("U")
end
|
#list_body(id, lines, lang) ⇒ Object
186
187
188
189
190
191
192
193
|
# File 'lib/review/inaobuilder.rb', line 186
def list_body(id, lines, lang)
buf = ""
lines.each do |line|
buf << detab(line) << "\n"
end
buf << "◆/list◆\n"
buf
end
|
176
177
178
179
180
181
182
183
184
|
# File 'lib/review/inaobuilder.rb', line 176
def (id, caption, lang)
buf = "◆list/◆\n"
if get_chap.nil?
buf << %Q[●リスト#{@chapter.list(id).number} #{caption}\n]
else
buf << %Q[●リスト#{get_chap}.#{@chapter.list(id).number} #{caption}\n]
end
buf
end
|
#listnum_body(lines, lang) ⇒ Object
195
196
197
198
199
200
201
202
|
# File 'lib/review/inaobuilder.rb', line 195
def listnum_body(lines, lang)
buf = ""
lines.each_with_index do |line, i|
buf << detab((i+1).to_s.rjust(2) + " " + line) << "\n"
end
buf << "◆/list◆\n"
buf
end
|
55
56
57
|
# File 'lib/review/inaobuilder.rb', line 55
def messages
error_messages() + warning_messages()
end
|
#nofunc_text(str) ⇒ Object
352
353
354
|
# File 'lib/review/inaobuilder.rb', line 352
def nofunc_text(str)
str
end
|
82
83
84
|
# File 'lib/review/inaobuilder.rb', line 82
def noindent
@noindent = true
end
|
153
154
155
156
|
# File 'lib/review/inaobuilder.rb', line 153
def ol_begin
@olitem = 0
""
end
|
162
163
164
165
|
# File 'lib/review/inaobuilder.rb', line 162
def ol_end
@olitem = nil
""
end
|
#ol_item(lines, num) ⇒ Object
158
159
160
|
# File 'lib/review/inaobuilder.rb', line 158
def ol_item(lines, num)
"(#{num})#{lines.join}\n"
end
|
#paragraph(lines) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/review/inaobuilder.rb', line 74
def paragraph(lines)
buf = ""
buf << " " if @noindent.nil?
@noindent = nil
buf << lines.join + "\n"
buf
end
|
#post_paragraph ⇒ Object
24
25
26
|
# File 'lib/review/inaobuilder.rb', line 24
def post_paragraph
''
end
|
#pre_paragraph ⇒ Object
20
21
22
|
# File 'lib/review/inaobuilder.rb', line 20
def pre_paragraph
''
end
|
#quote(lines) ⇒ Object
125
126
127
128
|
# File 'lib/review/inaobuilder.rb', line 125
def quote(lines)
lines_fixed = lines.map{|line| line.sub(/^ /,"")} base_parablock "quote", lines_fixed, nil
end
|
#table(lines, id = nil, caption = nil) ⇒ Object
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/review/inaobuilder.rb', line 271
def table(lines, id = nil, caption = nil)
buf = ""
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
if /\A[\=\-]{12}/ =~ line
sepidx ||= idx
next
end
rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
end
rows = adjust_n_cols(rows)
buf << "◆table/◆\n"
begin
buf << (id, caption) unless caption.nil?
rescue KeyError
error "no such table: #{id}"
end
return buf if rows.empty?
buf << table_begin(rows.first.size)
if sepidx
sepidx.times do
buf << "◆table-title◆"
buf << tr(rows.shift.map {|s| th(s) })
end
rows.each do |cols|
buf << tr(cols.map {|s| td(s) })
end
else
rows.each do |cols|
h, *cs = *cols
buf << tr([th(h)] + cs.map {|s| td(s) })
end
end
buf << table_end
buf
end
|
#table_begin(ncols) ⇒ Object
320
321
322
|
# File 'lib/review/inaobuilder.rb', line 320
def table_begin(ncols)
""
end
|
#table_end ⇒ Object
336
337
338
|
# File 'lib/review/inaobuilder.rb', line 336
def table_end
"◆/table◆\n"
end
|
312
313
314
315
316
317
318
|
# File 'lib/review/inaobuilder.rb', line 312
def (id, caption)
if get_chap.nil?
"●表#{@chapter.table(id).number} #{caption}\n"
else
"●表#{get_chap}.#{@chapter.table(id).number} #{caption}\n"
end
end
|
332
333
334
|
# File 'lib/review/inaobuilder.rb', line 332
def td(str)
str
end
|
#text(str) ⇒ Object
348
349
350
|
# File 'lib/review/inaobuilder.rb', line 348
def text(str)
str
end
|
328
329
330
|
# File 'lib/review/inaobuilder.rb', line 328
def th(str)
str
end
|
324
325
326
|
# File 'lib/review/inaobuilder.rb', line 324
def tr(rows)
rows.join("\t") + "\n"
end
|
141
142
143
|
# File 'lib/review/inaobuilder.rb', line 141
def ul_begin
""
end
|
149
150
151
|
# File 'lib/review/inaobuilder.rb', line 149
def ul_end
""
end
|
#ul_item(lines) ⇒ Object
145
146
147
|
# File 'lib/review/inaobuilder.rb', line 145
def ul_item(lines)
"・#{lines.join}\n"
end
|
#warn(msg) ⇒ Object
47
48
49
|
# File 'lib/review/inaobuilder.rb', line 47
def warn(msg)
$stderr.puts "#{@location.filename}:#{@location.lineno}: warning: #{msg}"
end
|