class ReVIEW::TOPBuilder

Public Instance Methods

base_block(type, lines, caption = nil) click to toggle source
# File lib/review/topbuilder.rb, line 128
def base_block(type, lines, caption = nil)
  blank
  puts "◆→開始:#{@titles[type]}←◆"
  if caption_top?('list') && caption.present?
    puts "■#{compile_inline(caption)}"
  end
  puts lines.join("\n")
  if !caption_top?('list') && caption.present?
    puts "■#{compile_inline(caption)}"
  end
  puts "◆→終了:#{@titles[type]}←◆"
  blank
end
base_parablock(type, lines, caption = nil) click to toggle source
# File lib/review/topbuilder.rb, line 142
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) click to toggle source
# File lib/review/topbuilder.rb, line 487
def bibpaper_header(id, caption)
  print "[#{@chapter.bibpaper(id).number}]"
  puts " #{compile_inline(caption)}"
end
circle_begin(_level, _label, caption) click to toggle source
# File lib/review/topbuilder.rb, line 596
def circle_begin(_level, _label, caption)
  puts "・\t#{caption}"
end
comment(lines, comment = nil) click to toggle source
# File lib/review/topbuilder.rb, line 320
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_block_begin(type, _level, _label, caption = nil) click to toggle source
# File lib/review/topbuilder.rb, line 521
def common_block_begin(type, _level, _label, caption = nil)
  blank
  puts "◆→開始:#{@titles[type]}←◆"
  puts '■' + compile_inline(caption) if caption.present?
end
common_block_end(type, _level) click to toggle source
# File lib/review/topbuilder.rb, line 527
def common_block_end(type, _level)
  puts "◆→終了:#{@titles[type]}←◆"
  blank
end
common_column_begin(type, caption) click to toggle source
# File lib/review/topbuilder.rb, line 510
def common_column_begin(type, caption)
  blank
  puts "◆→開始:#{@titles[type]}←◆"
  puts "■#{compile_inline(caption)}"
end
common_column_end(type) click to toggle source
# File lib/review/topbuilder.rb, line 516
def common_column_end(type)
  puts "◆→終了:#{@titles[type]}←◆"
  blank
end
compile_href(url, label) click to toggle source
# File lib/review/topbuilder.rb, line 371
def compile_href(url, label)
  if label
    "#{label}(△#{url}☆)"
  else
    "△#{url}☆"
  end
end
compile_kw(word, alt) click to toggle source
# File lib/review/topbuilder.rb, line 363
def compile_kw(word, alt)
  if alt
    "★#{word}☆(#{alt.strip})"
  else
    "★#{word}☆"
  end
end
compile_ruby(base, ruby) click to toggle source
# File lib/review/topbuilder.rb, line 359
def compile_ruby(base, ruby)
  "#{base}◆→DTP連絡:「#{base}」に「#{ruby}」とルビ←◆"
end
dd(lines) click to toggle source
# File lib/review/topbuilder.rb, line 79
def dd(lines)
  split_paragraph(lines).each do |paragraph|
    puts "\t#{paragraph.delete("\n")}"
  end
end
dt(line) click to toggle source
# File lib/review/topbuilder.rb, line 75
def dt(line)
  puts "★#{line}☆"
end
emlistnum(lines, caption = nil, _lang = nil) click to toggle source
# File lib/review/topbuilder.rb, line 151
def emlistnum(lines, caption = nil, _lang = nil)
  blank
  puts "◆→開始:#{@titles['emlist']}←◆"
  if caption_top?('list') && caption.present?
    puts "■#{compile_inline(caption)}"
  end
  lines.each_with_index do |line, i|
    puts((i + 1).to_s.rjust(2) + ": #{line}")
  end
  if !caption_top?('list') && caption.present?
    puts "■#{compile_inline(caption)}"
  end
  puts "◆→終了:#{@titles['emlist']}←◆"
  blank
end
endnote_begin() click to toggle source
# File lib/review/topbuilder.rb, line 347
def endnote_begin
  puts '◆→開始:後注←◆'
end
endnote_end() click to toggle source
# File lib/review/topbuilder.rb, line 351
def endnote_end
  puts '◆→終了:後注←◆'
end
endnote_item(id) click to toggle source
# File lib/review/topbuilder.rb, line 355
def endnote_item(id)
  puts "【後注#{@chapter.endnote(id).number}】#{compile_inline(@chapter.endnote(id).content)}"
end
footnote(id, str) click to toggle source
# File lib/review/topbuilder.rb, line 331
def footnote(id, str)
  puts "【注#{@chapter.footnote(id).number}】#{compile_inline(str)}"
end
headline(level, _label, caption) click to toggle source
# 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) click to toggle source
# File lib/review/topbuilder.rb, line 193
def image(lines, id, caption, metric = nil)
  metrics = parse_metric('top', metric)
  metrics = " #{metrics}" if metrics.present?
  blank
  puts "◆→開始:#{@titles['image']}←◆"
  if caption_top?('image')
    image_header(id, caption)
    blank
  end
  if @chapter.image_bound?(id)
    puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
  else
    warn "image not bound: #{id}", location: location
    lines.each do |line|
      puts line
    end
  end
  unless caption_top?('image')
    blank
    image_header(id, caption)
  end
  puts "◆→終了:#{@titles['image']}←◆"
  blank
end
image_header(id, caption) click to toggle source
# File lib/review/topbuilder.rb, line 218
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
imgtable(lines, id, caption = nil, metric = nil) click to toggle source
# File lib/review/topbuilder.rb, line 295
def imgtable(lines, id, caption = nil, metric = nil)
  metrics = parse_metric('top', metric)
  metrics = " #{metrics}" if metrics.present?
  blank
  puts "◆→開始:#{@titles['table']}←◆"
  if caption_top?('table') && caption.present?
    table_header(id, caption)
  end

  if @chapter.image_bound?(id)
    puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
  else
    warn "image not bound: #{id}", location: location
    lines.each do |line|
      puts line
    end
  end

  if !caption_top?('table') && caption.present?
    table_header(id, caption)
  end
  puts "◆→終了:#{@titles['table']}←◆"
  blank
end
indepimage(lines, id, caption = nil, metric = nil) click to toggle source
# File lib/review/topbuilder.rb, line 547
def indepimage(lines, id, caption = nil, metric = nil)
  metrics = parse_metric('top', metric)
  metrics = " #{metrics}" if metrics.present?
  blank
  puts "◆→開始:#{@titles['image']}←◆"
  if caption_top?('image') && caption.present?
    indepimage_header(id, caption)
    blank
  end
  if @chapter.image_bound?(id)
    puts "◆→#{@chapter.image(id).path}#{metrics}←◆"
  else
    warn "image not bound: #{id}", location: location
    lines.each do |line|
      puts line
    end
  end
  if !caption_top?('image') && caption.present?
    blank
    indepimage_header(id, caption)
  end
  puts "◆→終了:#{@titles['image']}←◆"
  blank
end
Also aliased as: numberlessimage
indepimage_header(_id, caption) click to toggle source
# File lib/review/topbuilder.rb, line 574
def indepimage_header(_id, caption)
  puts "図#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
end
inline_ami(str) click to toggle source
# File lib/review/topbuilder.rb, line 403
def inline_ami(str)
  "#{str}◆→DTP連絡:「#{str}」に網カケ←◆"
end
inline_b(str) click to toggle source
# File lib/review/topbuilder.rb, line 411
def inline_b(str)
  "★#{str}☆"
end
Also aliased as: inline_strong
inline_balloon(str) click to toggle source
# File lib/review/topbuilder.rb, line 464
def inline_balloon(str)
  %Q(\t←#{str.gsub(/@maru\[(\d+)\]/, inline_maru('\1'))})
end
inline_bib(id) click to toggle source
# File lib/review/topbuilder.rb, line 492
def inline_bib(id)
  %Q([#{@chapter.bibpaper(id).number}])
rescue KeyError
  app_error "unknown bib: #{id}"
end
inline_bou(str) click to toggle source
# File lib/review/topbuilder.rb, line 456
def inline_bou(str)
  "#{str}◆→DTP連絡:「#{str}」に傍点←◆"
end
inline_code(str) click to toggle source
# File lib/review/topbuilder.rb, line 578
def inline_code(str)
  "△#{str}☆"
end
inline_comment(str) click to toggle source
# File lib/review/topbuilder.rb, line 468
def inline_comment(str)
  if @book.config['draft']
    "◆→#{str}←◆"
  else
    ''
  end
end
inline_del(str) click to toggle source
# File lib/review/topbuilder.rb, line 439
def inline_del(str)
  "◆→開始:削除表現←◆#{str}◆→終了:削除表現←◆"
end
inline_endnote(id) click to toggle source
# File lib/review/topbuilder.rb, line 341
def inline_endnote(id)
  "【後注#{@chapter.endnote(id).number}】"
rescue KeyError
  app_error "unknown endnote: #{id}"
end
inline_fn(id) click to toggle source
# File lib/review/topbuilder.rb, line 335
def inline_fn(id)
  "【注#{@chapter.footnote(id).number}】"
rescue KeyError
  app_error "unknown footnote: #{id}"
end
inline_hidx(str) click to toggle source
# File lib/review/topbuilder.rb, line 399
def inline_hidx(str)
  "◆→索引項目:#{str}←◆"
end
inline_hint(str) click to toggle source
# File lib/review/topbuilder.rb, line 387
def inline_hint(str)
  "◆→ヒントスタイルここから←◆#{str}◆→ヒントスタイルここまで←◆"
end
inline_i(str) click to toggle source
# File lib/review/topbuilder.rb, line 407
def inline_i(str)
  "▲#{str}☆"
end
inline_icon(id) click to toggle source
# File lib/review/topbuilder.rb, line 447
def inline_icon(id)
  begin
    "◆→画像 #{@chapter.image(id).path.sub(%r{\A\./}, '')}←◆"
  rescue StandardError
    warn "image not bound: #{id}", location: location
    "◆→画像 #{id}←◆"
  end
end
inline_idx(str) click to toggle source
# File lib/review/topbuilder.rb, line 395
def inline_idx(str)
  "#{str}◆→索引項目:#{str}←◆"
end
inline_ins(str) click to toggle source
# File lib/review/topbuilder.rb, line 435
def inline_ins(str)
  "◆→開始:挿入表現←◆#{str}◆→終了:挿入表現←◆"
end
inline_keytop(str) click to toggle source
# File lib/review/topbuilder.rb, line 460
def inline_keytop(str)
  "#{str}◆→キートップ#{str}←◆"
end
inline_labelref(idref) click to toggle source
# File lib/review/topbuilder.rb, line 586
def inline_labelref(idref)
  "「◆→#{idref}←◆」" # 節、項を参照
end
Also aliased as: inline_ref
inline_m(str) click to toggle source
# File lib/review/topbuilder.rb, line 476
def inline_m(str)
  if @book.config['math_format'] == 'imgmath'
    math_str = '$' + str + '$'
    key = Digest::SHA256.hexdigest(str)
    img_path = @img_math.defer_math_image(math_str, key)
    %Q(◆→TeX式ここから←◆◆→math:#{File.basename(img_path)}←◆◆→TeX式ここまで←◆)
  else
    %Q(◆→TeX式ここから←◆#{str}◆→TeX式ここまで←◆)
  end
end
inline_maru(str) click to toggle source
# File lib/review/topbuilder.rb, line 391
def inline_maru(str)
  "#{str}◆→丸数字#{str}←◆"
end
inline_pageref(idref) click to toggle source
# File lib/review/topbuilder.rb, line 592
def inline_pageref(idref)
  "●ページ◆→#{idref}←◆" # ページ番号を参照
end
inline_ref(idref)
Alias for: inline_labelref
inline_strong(str)
Alias for: inline_b
inline_sub(str) click to toggle source
# File lib/review/topbuilder.rb, line 383
def inline_sub(str)
  "#{str}◆→DTP連絡:「#{str}」は下付き←◆"
end
inline_sup(str) click to toggle source
# File lib/review/topbuilder.rb, line 379
def inline_sup(str)
  "#{str}◆→DTP連絡:「#{str}」は上付き←◆"
end
inline_tcy(str) click to toggle source
# File lib/review/topbuilder.rb, line 443
def inline_tcy(str)
  "◆→開始:回転←◆#{str}◆→終了:縦回転←◆"
end
inline_tt(str) click to toggle source
# File lib/review/topbuilder.rb, line 417
def inline_tt(str)
  "△#{str}☆"
end
inline_ttb(str) click to toggle source
# File lib/review/topbuilder.rb, line 421
def inline_ttb(str)
  "★#{str}☆◆→等幅フォント太字←◆"
end
Also aliased as: inline_ttbold
inline_ttbold(str)
Alias for: inline_ttb
inline_tti(str) click to toggle source
# File lib/review/topbuilder.rb, line 427
def inline_tti(str)
  "▲#{str}☆◆→等幅フォントイタ←◆"
end
inline_ttibold(str) click to toggle source
# File lib/review/topbuilder.rb, line 582
def inline_ttibold(str)
  "▲#{str}☆◆→等幅フォント太字イタ←◆"
end
inline_u(str) click to toggle source
# File lib/review/topbuilder.rb, line 431
def inline_u(str)
  "@#{str}@◆→@〜@部分に下線←◆"
end
lead(lines)
Alias for: read
list(lines, id, caption, lang = nil) click to toggle source
# File lib/review/topbuilder.rb, line 94
def list(lines, id, caption, lang = nil)
  blank
  puts "◆→開始:#{@titles['list']}←◆"
  begin
    if caption_top?('list')
      list_header(id, caption, lang)
      blank
    end
    list_body(id, lines, lang)
    unless caption_top?('list')
      blank
      list_header(id, caption, lang)
    end
  rescue KeyError
    app_error "no such list: #{id}"
  end
  puts "◆→終了:#{@titles['list']}←◆"
  blank
end
list_body(_id, lines, _lang) click to toggle source
# File lib/review/topbuilder.rb, line 122
def list_body(_id, lines, _lang)
  lines.each do |line|
    puts detab(line)
  end
end
list_header(id, caption, _lang) click to toggle source
# File lib/review/topbuilder.rb, line 114
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) click to toggle source
# File lib/review/topbuilder.rb, line 167
def listnum(lines, id, caption, lang = nil)
  blank
  puts "◆→開始:#{@titles['list']}←◆"
  begin
    if caption_top?('list') && caption.present?
      list_header(id, caption, lang)
      blank
    end
    listnum_body(lines, lang)
    if !caption_top?('list') && caption.present?
      blank
      list_header(id, caption, lang)
    end
  rescue KeyError
    app_error "no such list: #{id}"
  end
  puts "◆→終了:#{@titles['list']}←◆"
  blank
end
listnum_body(lines, _lang) click to toggle source
# File lib/review/topbuilder.rb, line 187
def listnum_body(lines, _lang)
  lines.each_with_index do |line, i|
    puts((i + 1).to_s.rjust(2) + ": #{line}")
  end
end
noindent() click to toggle source
# File lib/review/topbuilder.rb, line 498
def noindent
  puts '◆→DTP連絡:次の1行インデントなし←◆'
end
nonum_begin(level, _label, caption) click to toggle source
# File lib/review/topbuilder.rb, line 502
def nonum_begin(level, _label, caption)
  puts "■H#{level}■#{compile_inline(caption)}"
end
notoc_begin(level, _label, caption) click to toggle source
# File lib/review/topbuilder.rb, line 506
def notoc_begin(level, _label, caption)
  puts "■H#{level}■#{compile_inline(caption)}◆→DTP連絡:目次に掲載しない←◆"
end
numberlessimage(lines, id, caption = nil, metric = nil)
Alias for: indepimage
ol_item(lines, num) click to toggle source
# File lib/review/topbuilder.rb, line 71
def ol_item(lines, num)
  puts "#{num}\t#{join_lines_to_paragraph(lines)}"
end
read(lines) click to toggle source
# File lib/review/topbuilder.rb, line 85
def read(lines)
  puts "◆→開始:#{@titles['lead']}←◆"
  puts split_paragraph(lines).join("\n")
  puts "◆→終了:#{@titles['lead']}←◆"
  blank
end
Also aliased as: lead
table(lines, id = nil, caption = nil) click to toggle source
Calls superclass method ReVIEW::PLAINTEXTBuilder#table
# File lib/review/topbuilder.rb, line 257
def table(lines, id = nil, caption = nil)
  blank
  puts "◆→開始:#{@titles['table']}←◆"
  super(lines, id, caption, true)
  puts "◆→終了:#{@titles['table']}←◆"
  blank
end
table_end() click to toggle source
# File lib/review/topbuilder.rb, line 292
def table_end
end
table_rows(sepidx, rows) click to toggle source
# File lib/review/topbuilder.rb, line 265
def table_rows(sepidx, rows)
  if sepidx
    sepidx.times do
      tr(rows.shift.map { |s| th(s) })
    end
    if !@book.config['textmaker'] || !@book.config['textmaker']['th_bold']
      puts '-' * 12
    end
    rows.each do |cols|
      tr(cols.map { |s| td(s) })
    end
  else
    rows.each do |cols|
      h, *cs = *cols
      tr([th(h)] + cs.map { |s| td(s) })
    end
  end
end
texequation(lines, id = nil, caption = '') click to toggle source
# File lib/review/topbuilder.rb, line 226
def texequation(lines, id = nil, caption = '')
  blank
  puts "◆→開始:#{@titles['texequation']}←◆"
  texequation_header(id, caption) if caption_top?('equation')

  if @book.config['math_format'] == '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)
    img_path = @img_math.defer_math_image(math_str, key)
    puts "◆→math:#{File.basename(img_path)}←◆"
  else
    puts lines.join("\n")
  end

  texequation_header(id, caption) unless caption_top?('equation')
  puts "◆→終了:#{@titles['texequation']}←◆"
  blank
end
texequation_header(id, caption) click to toggle source
# File lib/review/topbuilder.rb, line 247
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) click to toggle source
# File lib/review/topbuilder.rb, line 284
def th(str)
  if @book.config['textmaker'] && @book.config['textmaker']['th_bold']
    "★#{str}☆"
  else
    str
  end
end
ul_item(lines) click to toggle source
# File lib/review/topbuilder.rb, line 67
def ul_item(lines)
  puts "●\t#{join_lines_to_paragraph(lines)}"
end

Private Instance Methods

builder_init_file() click to toggle source
# File lib/review/topbuilder.rb, line 13
def builder_init_file
  super

  @titles = {
    'emlist' => 'インラインリスト',
    'cmd' => 'コマンド',
    'quote' => '引用',
    'centering' => '中央揃え',
    'flushright' => '右寄せ',
    'note' => 'ノート',
    'memo' => 'メモ',
    'important' => '重要',
    'info' => '情報',
    'planning' => 'プランニング',
    'shoot' => 'トラブルシュート',
    'term' => '用語解説',
    'notice' => '注意',
    'caution' => '警告',
    'warning' => '危険',
    'point' => 'ここがポイント',
    'reference' => '参考',
    'link' => 'リンク',
    'best' => 'ベストプラクティス',
    'practice' => '練習問題',
    'security' => 'セキュリティ',
    'expert' => 'エキスパートに訊け',
    'tip' => 'TIP',
    'box' => '書式',
    'insn' => '書式',
    'column' => 'コラム',
    'xcolumn' => 'コラムパターン2',
    'world' => 'Worldコラム',
    'hood' => 'Under The Hoodコラム',
    'edition' => 'Editionコラム',
    'insideout' => 'InSideOutコラム',
    'ref' => '参照',
    'sup' => '補足',
    'read' => 'リード',
    'lead' => 'リード',
    'list' => 'リスト',
    'image' => '図',
    'texequation' => 'TeX式',
    'table' => '表',
    'bpo' => 'bpo',
    'source' => 'ソースコードリスト'
  }
end