Class: ReVIEW::TOPBuilder

Inherits:
PLAINTEXTBuilder show all
Defined in:
lib/review/topbuilder.rb

Direct Known Subclasses

TEXTBuilder

Constant Summary

Constants inherited from Builder

Builder::CAPTION_TITLES

Instance Attribute Summary

Attributes inherited from Builder

#doc_status

Instance Method Summary collapse

Methods inherited from PLAINTEXTBuilder

#best, #bibpaper, #bibpaper_bibpaper, #bpo, #caution, #centering, #circle_end, #cmd, #column_begin, #column_end, #dl_begin, #dl_end, #dtp, #edition_begin, #edition_end, #emlist, #expert, #extname, #flushright, #hood_begin, #hood_end, #imgtable, #important, #info, #inline_br, #inline_chap, #inline_chapref, #inline_del, #inline_dtp, #inline_hd_chap, #inline_raw, #inline_uchar, #insideout_begin, #insideout_end, #insn, #label, #link, #memo, #nodisp_begin, #nodisp_end, #nofunc_text, #nonum_end, #note, #notice, #notoc_end, #ol_begin, #ol_end, #olnum, #paragraph, #planning, #point, #post_paragraph, #practice, #pre_paragraph, #quote, #ref_begin, #ref_end, #reference, #result, #security, #shoot, #source, #sup_begin, #sup_end, #table_begin, #table_header, #term, #text, #tip, #tr, #ul_begin, #ul_end, #warning, #world_begin, #world_end, #xcolumn_begin, #xcolumn_end

Methods included from TextUtils

#add_space?, #defer_math_image, #detab, #join_lines_to_paragraph, #split_paragraph

Methods inherited from Builder

#bibpaper, #bind, #blankline, #captionblock, #compile_inline, #detab, #embed, #emtable, #error, #escape, #extract_chapter_id, #firstlinenum, #get_chap, #graph, #graph_aafigure, #graph_blockdiag, #graph_gnuplot, #graph_graphviz, #graph_plantuml, #handle_metric, #highlight?, #image_ext, #initialize, #inline_chap, #inline_chapref, #inline_column, #inline_column_chap, #inline_embed, #inline_eq, #inline_hd, #inline_href, #inline_img, #inline_imgref, #inline_include, #inline_kw, #inline_list, #inline_raw, #inline_ruby, #inline_table, #inline_tcy, #inline_title, #inline_w, #inline_wb, #line_num, #load_words, #over_secnolevel?, #parse_metric, #parse_table_rows, #post_paragraph, #pre_paragraph, #print, #puts, #raw, #result, #result_metric, #source, #system_graph, #table_row_separator_regexp, #table_rows, #target_name, #text, #tsize, #ul_item_begin, #ul_item_end, #warn

Constructor Details

This class inherits a constructor from ReVIEW::Builder

Instance Method Details

#base_block(type, lines, caption = nil) ⇒ Object



122
123
124
125
126
127
128
129
# File 'lib/review/topbuilder.rb', line 122

def base_block(type, lines, caption = nil)
  blank
  puts "◆→開始:#{@titles[type]}←◆"
  puts "#{compile_inline(caption)}" if caption.present?
  puts lines.join("\n")
  puts "◆→終了:#{@titles[type]}←◆"
  blank
end

#base_parablock(type, lines, caption = nil) ⇒ Object



131
132
133
134
135
136
137
138
# File 'lib/review/topbuilder.rb', line 131

def base_parablock(type, lines, caption = nil)
  blank
  puts "◆→開始:#{@titles[type]}←◆"
  puts "#{compile_inline(caption)}" if caption.present?
  puts split_paragraph(lines).join("\n")
  puts "◆→終了:#{@titles[type]}←◆"
  blank
end

#bibpaper_header(id, caption) ⇒ Object



384
385
386
387
# File 'lib/review/topbuilder.rb', line 384

def bibpaper_header(id, caption)
  print "[#{@chapter.bibpaper(id).number}]"
  puts " #{compile_inline(caption)}"
end

#circle_begin(_level, _label, caption) ⇒ Object



452
453
454
# File 'lib/review/topbuilder.rb', line 452

def circle_begin(_level, _label, caption)
  puts "・\t#{caption}"
end

#comment(lines, comment = nil) ⇒ Object



246
247
248
249
250
251
252
253
254
# File 'lib/review/topbuilder.rb', line 246

def comment(lines, comment = nil)
  return unless @book.config['draft']
  lines ||= []
  unless comment.blank?
    lines.unshift(comment)
  end
  str = lines.join("\n")
  puts "◆→#{str}←◆"
end

#common_column_begin(type, caption) ⇒ Object



407
408
409
410
411
# File 'lib/review/topbuilder.rb', line 407

def common_column_begin(type, caption)
  blank
  puts "◆→開始:#{@titles[type]}←◆"
  puts "#{compile_inline(caption)}"
end

#common_column_end(type) ⇒ Object



413
414
415
416
# File 'lib/review/topbuilder.rb', line 413

def common_column_end(type)
  puts "◆→終了:#{@titles[type]}←◆"
  blank
end

#compile_href(url, label) ⇒ Object



277
278
279
280
281
282
283
# File 'lib/review/topbuilder.rb', line 277

def compile_href(url, label)
  if label
    "#{label}(△#{url}☆)"
  else
    "#{url}"
  end
end

#compile_kw(word, alt) ⇒ Object



270
271
272
273
274
275
# File 'lib/review/topbuilder.rb', line 270

def compile_kw(word, alt)
  if alt
  then "#{word}☆(#{alt.strip}"
  else "#{word}"
  end
end

#compile_ruby(base, ruby) ⇒ Object



266
267
268
# File 'lib/review/topbuilder.rb', line 266

def compile_ruby(base, ruby)
  "#{base}◆→DTP連絡:「#{base}」に「#{ruby}」とルビ←◆"
end

#dd(lines) ⇒ Object



79
80
81
82
83
# File 'lib/review/topbuilder.rb', line 79

def dd(lines)
  split_paragraph(lines).each do |paragraph|
    puts "\t#{paragraph.gsub(/\n/, '')}"
  end
end

#dt(line) ⇒ Object



75
76
77
# File 'lib/review/topbuilder.rb', line 75

def dt(line)
  puts "#{line}"
end

#emlistnum(lines, caption = nil, _lang = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
# File 'lib/review/topbuilder.rb', line 140

def emlistnum(lines, caption = nil, _lang = nil)
  blank
  puts "◆→開始:#{@titles['emlist']}←◆"
  puts "#{compile_inline(caption)}" if caption.present?
  lines.each_with_index do |line, i|
    puts((i + 1).to_s.rjust(2) + ": #{line}")
  end
  puts "◆→終了:#{@titles['emlist']}←◆"
  blank
end

#footnote(id, str) ⇒ Object



256
257
258
# File 'lib/review/topbuilder.rb', line 256

def footnote(id, str)
  puts "【注#{@chapter.footnote(id).number}#{compile_inline(str)}"
end

#headline(level, _label, caption) ⇒ Object



62
63
64
65
# File 'lib/review/topbuilder.rb', line 62

def headline(level, _label, caption)
  prefix, _anchor = headline_prefix(level)
  puts %Q(■H#{level}#{prefix}#{compile_inline(caption)})
end

#image(lines, id, caption, metric = nil) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/review/topbuilder.rb', line 171

def image(lines, id, caption, metric = nil)
  metrics = parse_metric('top', metric)
  metrics = " #{metrics}" if metrics.present?
  blank
  puts "◆→開始:#{@titles['image']}←◆"
  image_header(id, caption)
  blank
  if @chapter.image_bound?(id)
    puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
  else
    warn "image not bound: #{id}"
    lines.each do |line|
      puts line
    end
  end
  puts "◆→終了:#{@titles['image']}←◆"
  blank
end

#image_header(id, caption) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/review/topbuilder.rb', line 190

def image_header(id, caption)
  if get_chap
    puts "#{I18n.t('image')}#{I18n.t('format_number', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
  else
    puts "#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
  end
end

#indepimage(_lines, id, caption = nil, metric = nil) ⇒ Object Also known as: numberlessimage



418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/review/topbuilder.rb', line 418

def indepimage(_lines, id, caption = nil, metric = nil)
  metrics = parse_metric('top', metric)
  metrics = " #{metrics}" if metrics.present?
  blank
  begin
    puts "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}#{metrics}←◆"
  rescue
    warn "image not bound: #{id}"
    puts "◆→画像 #{id}←◆"
  end
  puts "図 #{compile_inline(caption)}" if caption.present?
  blank
end

#inline_ami(str) ⇒ Object



309
310
311
# File 'lib/review/topbuilder.rb', line 309

def inline_ami(str)
  "#{str}◆→DTP連絡:「#{str}」に網カケ←◆"
end

#inline_b(str) ⇒ Object Also known as: inline_strong



317
318
319
# File 'lib/review/topbuilder.rb', line 317

def inline_b(str)
  "#{str}"
end

#inline_balloon(str) ⇒ Object



358
359
360
# File 'lib/review/topbuilder.rb', line 358

def inline_balloon(str)
  %Q(\t←#{str.gsub(/@maru\[(\d+)\]/, inline_maru('\1'))})
end

#inline_bib(id) ⇒ Object



389
390
391
392
393
# File 'lib/review/topbuilder.rb', line 389

def inline_bib(id)
  %Q([#{@chapter.bibpaper(id).number}])
rescue KeyError
  error "unknown bib: #{id}"
end

#inline_bou(str) ⇒ Object



350
351
352
# File 'lib/review/topbuilder.rb', line 350

def inline_bou(str)
  "#{str}◆→DTP連絡:「#{str}」に傍点←◆"
end

#inline_code(str) ⇒ Object



434
435
436
# File 'lib/review/topbuilder.rb', line 434

def inline_code(str)
  "#{str}"
end

#inline_comment(str) ⇒ Object



362
363
364
365
366
367
368
# File 'lib/review/topbuilder.rb', line 362

def inline_comment(str)
  if @book.config['draft']
    "◆→#{str}←◆"
  else
    ''
  end
end

#inline_fn(id) ⇒ Object



260
261
262
263
264
# File 'lib/review/topbuilder.rb', line 260

def inline_fn(id)
  "【注#{@chapter.footnote(id).number}"
rescue KeyError
  error "unknown footnote: #{id}"
end

#inline_hidx(str) ⇒ Object



305
306
307
# File 'lib/review/topbuilder.rb', line 305

def inline_hidx(str)
  "◆→索引項目:#{str}←◆"
end

#inline_hint(str) ⇒ Object



293
294
295
# File 'lib/review/topbuilder.rb', line 293

def inline_hint(str)
  "◆→ヒントスタイルここから←◆#{str}◆→ヒントスタイルここまで←◆"
end

#inline_i(str) ⇒ Object



313
314
315
# File 'lib/review/topbuilder.rb', line 313

def inline_i(str)
  "#{str}"
end

#inline_icon(id) ⇒ Object



341
342
343
344
345
346
347
348
# File 'lib/review/topbuilder.rb', line 341

def inline_icon(id)
  begin
    "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}←◆"
  rescue
    warn "image not bound: #{id}"
    "◆→画像 #{id}←◆"
  end
end

#inline_idx(str) ⇒ Object



301
302
303
# File 'lib/review/topbuilder.rb', line 301

def inline_idx(str)
  "#{str}◆→索引項目:#{str}←◆"
end

#inline_keytop(str) ⇒ Object



354
355
356
# File 'lib/review/topbuilder.rb', line 354

def inline_keytop(str)
  "#{str}◆→キートップ#{str}←◆"
end

#inline_labelref(idref) ⇒ Object Also known as: inline_ref



442
443
444
# File 'lib/review/topbuilder.rb', line 442

def inline_labelref(idref)
  "「◆→#{idref}←◆」" # 節、項を参照
end

#inline_m(str) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/review/topbuilder.rb', line 370

def inline_m(str)
  if @book.config['imgmath']
    math_str = '$' + str + '$'
    key = Digest::SHA256.hexdigest(str)
    math_dir = File.join(@book.config['imagedir'], '_review_math_text')
    Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
    img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
    defer_math_image(math_str, img_path, key)
    %Q(◆→TeX式ここから←◆◆→math:#{File.basename(img_path)}←◆◆→TeX式ここまで←◆)
  else
    %Q(◆→TeX式ここから←◆#{str}◆→TeX式ここまで←◆)
  end
end

#inline_maru(str) ⇒ Object



297
298
299
# File 'lib/review/topbuilder.rb', line 297

def inline_maru(str)
  "#{str}◆→丸数字#{str}←◆"
end

#inline_pageref(idref) ⇒ Object



448
449
450
# File 'lib/review/topbuilder.rb', line 448

def inline_pageref(idref)
  "●ページ◆→#{idref}←◆" # ページ番号を参照
end

#inline_sub(str) ⇒ Object



289
290
291
# File 'lib/review/topbuilder.rb', line 289

def inline_sub(str)
  "#{str}◆→DTP連絡:「#{str}」は下付き←◆"
end

#inline_sup(str) ⇒ Object



285
286
287
# File 'lib/review/topbuilder.rb', line 285

def inline_sup(str)
  "#{str}◆→DTP連絡:「#{str}」は上付き←◆"
end

#inline_tt(str) ⇒ Object



323
324
325
# File 'lib/review/topbuilder.rb', line 323

def inline_tt(str)
  "#{str}"
end

#inline_ttb(str) ⇒ Object Also known as: inline_ttbold



327
328
329
# File 'lib/review/topbuilder.rb', line 327

def inline_ttb(str)
  "#{str}☆◆→等幅フォント太字←◆"
end

#inline_tti(str) ⇒ Object



333
334
335
# File 'lib/review/topbuilder.rb', line 333

def inline_tti(str)
  "#{str}☆◆→等幅フォントイタ←◆"
end

#inline_ttibold(str) ⇒ Object



438
439
440
# File 'lib/review/topbuilder.rb', line 438

def inline_ttibold(str)
  "#{str}☆◆→等幅フォント太字イタ←◆"
end

#inline_u(str) ⇒ Object



337
338
339
# File 'lib/review/topbuilder.rb', line 337

def inline_u(str)
  "#{str}@◆→@〜@部分に下線←◆"
end

#list(lines, id, caption, lang = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/review/topbuilder.rb', line 94

def list(lines, id, caption, lang = nil)
  blank
  puts "◆→開始:#{@titles['list']}←◆"
  begin
    list_header(id, caption, lang)
  rescue KeyError
    error "no such list: #{id}"
  end
  blank
  list_body(id, lines, lang)
  puts "◆→終了:#{@titles['list']}←◆"
  blank
end

#list_body(_id, lines, _lang) ⇒ Object



116
117
118
119
120
# File 'lib/review/topbuilder.rb', line 116

def list_body(_id, lines, _lang)
  lines.each do |line|
    puts detab(line)
  end
end

#list_header(id, caption, _lang) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/review/topbuilder.rb', line 108

def list_header(id, caption, _lang)
  if get_chap
    puts %Q(#{I18n.t('list')}#{I18n.t('format_number', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
  else
    puts %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
  end
end

#listnum(lines, id, caption, lang = nil) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/review/topbuilder.rb', line 151

def listnum(lines, id, caption, lang = nil)
  blank
  puts "◆→開始:#{@titles['list']}←◆"
  begin
    list_header(id, caption, lang)
  rescue KeyError
    error "no such list: #{id}"
  end
  blank
  listnum_body(lines, lang)
  puts "◆→終了:#{@titles['list']}←◆"
  blank
end

#listnum_body(lines, _lang) ⇒ Object



165
166
167
168
169
# File 'lib/review/topbuilder.rb', line 165

def listnum_body(lines, _lang)
  lines.each_with_index do |line, i|
    puts((i + 1).to_s.rjust(2) + ": #{line}")
  end
end

#noindentObject



395
396
397
# File 'lib/review/topbuilder.rb', line 395

def noindent
  puts '◆→DTP連絡:次の1行インデントなし←◆'
end

#nonum_begin(level, _label, caption) ⇒ Object



399
400
401
# File 'lib/review/topbuilder.rb', line 399

def nonum_begin(level, _label, caption)
  puts "■H#{level}#{compile_inline(caption)}"
end

#notoc_begin(level, _label, caption) ⇒ Object



403
404
405
# File 'lib/review/topbuilder.rb', line 403

def notoc_begin(level, _label, caption)
  puts "■H#{level}#{compile_inline(caption)}◆→DTP連絡:目次に掲載しない←◆"
end

#ol_item(lines, num) ⇒ Object



71
72
73
# File 'lib/review/topbuilder.rb', line 71

def ol_item(lines, num)
  puts "#{num}\t#{join_lines_to_paragraph(lines)}"
end

#read(lines) ⇒ Object Also known as: lead



85
86
87
88
89
90
# File 'lib/review/topbuilder.rb', line 85

def read(lines)
  puts "◆→開始:#{@titles['lead']}←◆"
  puts split_paragraph(lines).join("\n")
  puts "◆→終了:#{@titles['lead']}←◆"
  blank
end

#table(lines, id = nil, caption = nil) ⇒ Object



231
232
233
234
235
236
237
# File 'lib/review/topbuilder.rb', line 231

def table(lines, id = nil, caption = nil)
  blank
  puts "◆→開始:#{@titles['table']}←◆"
  super(lines, id, caption, true)
  puts "◆→終了:#{@titles['table']}←◆"
  blank
end

#table_endObject



243
244
# File 'lib/review/topbuilder.rb', line 243

def table_end
end

#texequation(lines, id = nil, caption = '') ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/review/topbuilder.rb', line 198

def texequation(lines, id = nil, caption = '')
  blank
  puts "◆→開始:#{@titles['texequation']}←◆"
  texequation_header(id, caption)

  if @book.config['imgmath']
    fontsize = @book.config['imgmath_options']['fontsize'].to_f
    lineheight = @book.config['imgmath_options']['lineheight'].to_f
    math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n"
    key = Digest::SHA256.hexdigest(math_str)
    math_dir = File.join(@book.config['imagedir'], '_review_math_text')
    Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
    img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
    defer_math_image(math_str, img_path, key)
    puts "◆→math:#{File.basename(img_path)}←◆"
  else
    puts lines.join("\n")
  end

  puts "◆→終了:#{@titles['texequation']}←◆"
  blank
end

#texequation_header(id, caption) ⇒ Object



221
222
223
224
225
226
227
228
229
# File 'lib/review/topbuilder.rb', line 221

def texequation_header(id, caption)
  if id
    if get_chap
      puts "#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
    else
      puts "#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
    end
  end
end

#th(str) ⇒ Object



239
240
241
# File 'lib/review/topbuilder.rb', line 239

def th(str)
  "#{str}"
end

#ul_item(lines) ⇒ Object



67
68
69
# File 'lib/review/topbuilder.rb', line 67

def ul_item(lines)
  puts "●\t#{join_lines_to_paragraph(lines)}"
end