class ReVIEW::IDGXMLBuilder

Public Instance Methods

best(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 928
def best(lines, caption = nil)
  captionblock("best", lines, caption)
end
bibpaper(lines, id, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1144
def bibpaper(lines, id, caption)
  bibpaper_header id, caption
  unless lines.empty?
    bibpaper_bibpaper id, caption, lines
  end
  puts %Q(</bibitem>)
end
bibpaper_bibpaper(id, caption, lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1157
def bibpaper_bibpaper(id, caption, lines)
    print split_paragraph(lines).join("")
end
bibpaper_header(id, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1152
def bibpaper_header(id, caption)
  puts %Q(<bibitem id="bib-#{id}">)
  puts "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{compile_inline(caption)}</caption>"
end
box(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1024
def box(lines, caption = nil)
  syntaxblock("box", lines, caption)
end
bpo(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1059
def bpo(lines)
  puts %Q[<bpo>#{lines.join("\n")}</bpo>]
end
captionblock(type, lines, caption, specialstyle = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 900
def captionblock(type, lines, caption, specialstyle = nil)
  print "<#{type}>"
  style = specialstyle.nil? ? "#{type}-title" : specialstyle
  puts "<title aid:pstyle='#{style}'>#{compile_inline(caption)}</title>" unless caption.nil?
  blocked_lines = split_paragraph(lines)
  puts "#{blocked_lines.join}</#{type}>"
end
caution(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 940
def caution(lines, caption = nil)
  captionblock("caution", lines, caption)
end
centering(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 896
def centering(lines)
  puts split_paragraph(lines).join.gsub("<p>", "<p align='center'>")
end
choice_multi_begin() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 230
def choice_multi_begin
  puts "<choice type='multi'>"
end
choice_multi_end() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 238
def choice_multi_end
  puts "</choice>"
end
choice_single_begin() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 226
def choice_single_begin
  puts "<choice type='single'>"
end
choice_single_end() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 234
def choice_single_end
  puts "</choice>"
end
circle_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 802
def circle_begin(level, label, caption)
  puts %Q[<title aid:pstyle="smallcircle">&#x2022;#{compile_inline(caption)}</title>]
end
circle_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 806
def circle_end(level)
end
cmd(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 388
def cmd(lines, caption = nil)
  quotedlist lines, 'cmd', caption
end
codelines_body(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 336
def codelines_body(lines)
  no = 1
  lines.each do |line|
    unless @book.config["listinfo"].nil?
      print "<listinfo line=\"#{no}\""
      print " begin=\"1\"" if no == 1
      print " end=\"#{no}\"" if no == lines.size
      print ">"
    end
    print detab(line)
    print "\n"
    print "</listinfo>" unless @book.config["listinfo"].nil?
    no += 1
  end
end
column_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 820
def column_begin(level, label, caption)
  common_column_begin("", caption)
end
column_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 824
def column_end(level)
  common_column_end("")
end
comment(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 629
def comment(str)
  print %Q(<!-- [Comment] #{escape_html(str)} -->)
end
common_column_begin(type, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 809
def common_column_begin(type, caption)
  @column += 1
  a_id = %Q[id="column-#{@column}"]
  print "<#{type}column #{a_id}>"
  puts %Q[<title aid:pstyle="#{type}column-title">#{compile_inline(caption)}</title><?dtp level="9" section="#{escape_html(compile_inline(caption))}"?>]
end
common_column_end(type) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 816
def common_column_end(type)
  puts "</#{type}column>"
end
compile_href(url, label) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 660
def compile_href(url, label)
  %Q[<a linkurl='#{escape_html(url)}'>#{label.nil? ? escape_html(url) : escape_html(label)}</a>]
end
compile_kw(word, alt) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 645
def compile_kw(word, alt)
  '<keyword>' +
    if alt
    then escape_html("#{word}(#{alt.strip})")
    else escape_html(word)
    end +
  '</keyword>' +
    %Q[<index value="#{escape_html(word)}" />] +
    if alt
      alt.split(/\s*,\s*/).collect! {|e| %Q[<index value="#{escape_html(e.strip)}" />] }.join
    else
      ""
    end
end
compile_ruby(base, ruby) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 641
def compile_ruby(base, ruby)
  %Q[<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{escape_html(base.sub(/\A\s+/, "").sub(/\s+$/, ""))}</aid:rb><aid:rt>#{escape_html(ruby.sub(/\A\s+/, "").sub(/\s+$/, ""))}</aid:rt></aid:ruby></GroupRuby>]
end
dd(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 277
def dd(lines)
  puts "<dd>#{lines.join.chomp}</dd>"
end
dl_begin() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 269
def dl_begin
  puts '<dl>'
end
dl_end() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 281
def dl_end
  puts '</dl>'
end
dt(line) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 273
def dt(line)
  puts "<dt>#{line}</dt>"
end
dtp(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1051
def dtp(str)
  print %Q(<?dtp #{str} ?>)
end
edition_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 852
def edition_begin(level, label, caption)
  common_column_begin("edition", caption)
end
edition_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 856
def edition_end(level)
  common_column_end("edition")
end
emlist(lines, caption = nil, lang = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 358
def emlist(lines, caption = nil, lang = nil)
  quotedlist lines, 'emlist', caption
end
emlistnum(lines, caption = nil, lang = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 362
def emlistnum(lines, caption = nil, lang = nil)
  _lines = []
  lines.each_with_index do |line, i|
    _lines << detab("<span type='lineno'>" + (i + 1).to_s.rjust(2) + ": </span>" + line)
  end
  quotedlist _lines, 'emlistnum', caption
end
error(msg) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 106
def error(msg)
  if @no_error
    @errors.push [@location.filename, @location.lineno, msg]
    puts "----ERROR: #{escape_html(msg)}----"
  else
    $stderr.puts "#{@location}: error: #{msg}"
  end
end
error_messages() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 119
def error_messages
  return '' if @errors.empty?
  "<h2>Syntax Errors</h2>\n" +
  "<ul>\n" +
  @errors.map {|file, line, msg|
    "<li>#{escape_html(file)}:#{line}: #{escape_html(msg.to_s)}</li>\n"
  }.join('') +
  "</ul>\n"
end
expert(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 988
def expert(lines)
  captionblock("expert", lines, nil)
end
extname() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 46
def extname
  '.xml'
end
flushright(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 892
def flushright(lines)
  puts split_paragraph(lines).join.gsub("<p>", "<p align='right'>")
end
footnote(id, str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 633
def footnote(id, str)
  # see inline_fn
end
handle_metric(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 449
def handle_metric(str)
  k, v = str.split('=', 2)
  return %Q#{k}=\"#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}\"|
end
headline(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 139
def headline(level, label, caption)
  case level
  when 1
    unless @secttags.nil?
      print "</sect4>" if @subsubsubsection > 0
      print "</sect3>" if @subsubsection > 0
      print "</sect2>" if @subsection > 0
      print "</sect>" if @section > 0
    end

    print %Q(<chapter id="chap:#{@chapter.number}">) unless @secttags.nil?

    @section = 0
    @subsection = 0
    @subsubsection = 0
    @subsubsubsection = 0
  when 2
    unless @secttags.nil?
      print "</sect4>" if @subsubsubsection > 0
      print "</sect3>" if @subsubsection > 0
      print "</sect2>" if @subsection > 0
      print "</sect>" if @section > 0
    end
    @section += 1
    print %Q(<sect id="sect:#{@chapter.number}.#{@section}">) unless @secttags.nil?
  
    @subsection = 0
    @subsubsection = 0
    @subsubsubsection = 0
  when 3
    unless @secttags.nil?
      print "</sect4>" if @subsubsubsection > 0
      print "</sect3>" if @subsubsection > 0
      print "</sect2>" if @subsection > 0
    end

    @subsection += 1
    print %Q(<sect2 id="sect:#{@chapter.number}.#{@section}.#{@subsection}">) unless @secttags.nil?

    @subsubsection = 0
    @subsubsubsection = 0
  when 4
    unless @secttags.nil?
      print "</sect4>" if @subsubsubsection > 0
      print "</sect3>" if @subsubsection > 0
    end

    @subsubsection += 1
    print %Q(<sect3 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}">) unless @secttags.nil?

    @subsubsubsection = 0
  when 5
    unless @secttags.nil?
      print "</sect4>" if @subsubsubsection > 0
    end

    @subsubsubsection += 1
    print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) unless @secttags.nil?
  else
    raise "caption level too deep or unsupported: #{level}"
  end

  prefix, anchor = headline_prefix(level)

  label = label.nil? ? "" : " id=\"#{label}\""
  toccaption = escape_html(compile_inline(caption.gsub(/@<fn>\{.+?\}/, '')).gsub(/<[^>]+>/, ''))
  puts %Q(<title#{label} aid:pstyle="h#{level}">#{prefix}#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{prefix}#{toccaption}"?>)
end
hood_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 844
def hood_begin(level, label, caption)
  common_column_begin("hood", caption)
end
hood_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 848
def hood_end(level)
  common_column_end("hood")
end
hr() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1055
def hr
  print "<hr />"
end
image_dummy(id, caption, lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 466
def image_dummy(id, caption, lines)
  puts "<img>"
  print %Q[<pre aid:pstyle="dummyimage">]
  lines.each do |line|
    print detab(line)
    print "\n"
  end
  print %Q[</pre>]
  image_header id, caption
  puts "</img>"
  warn "no such image: #{id}"
end
image_ext() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1184
def image_ext
  "eps"
end
image_header(id, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 479
def image_header(id, caption)
  if get_chap.nil?
    puts %Q[<caption>#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
  else
    puts %Q[<caption>#{I18n.t("image")}#{I18n.t("format_number", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
  end
end
image_image(id, caption, metric=nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 458
def image_image(id, caption, metric=nil)
  metrics = parse_metric("idgxml", metric)
  puts "<img>"
  puts %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A.\//, "")}"#{metrics} />]
  image_header id, caption
  puts "</img>"
end
imgtable(lines, id, caption = nil, metric = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 616
def imgtable(lines, id, caption = nil, metric = nil)
  if @chapter.image(id).bound?
    metrics = parse_metric("idgxml", metric)
    puts "<table>"
    table_header id, caption
    puts %Q[<imgtable><Image href="file://#{@chapter.image(id).path.sub(/\A.\//, "")}"#{metrics} /></imgtable>]
    puts "</table>"
  else
    warn "image not bound: #{id}" if @strict
    image_dummy id, caption, lines
  end
end
important(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 932
def important(lines, caption = nil)
  captionblock("important", lines, caption)
end
indepimage(id, caption=nil, metric=nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1028
def indepimage(id, caption=nil, metric=nil)
  metrics = parse_metric("idgxml", metric)
  puts "<img>"
  begin
    puts %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A\.\//, "")}"#{metrics} />]
  rescue
    warn %Q[no such image: #{id}]
  end
  puts %Q[<caption>#{compile_inline(caption)}</caption>] if caption.present?
  puts "</img>"
end
Also aliased as: numberlessimage
info(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 920
def info(lines, caption = nil)
  captionblock("info", lines, caption)
end
inline_ami(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 712
def inline_ami(str)
  %Q(<ami>#{escape_html(str)}</ami>)
end
inline_b(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 720
def inline_b(str)
  %Q(<b>#{escape_html(str)}</b>)
end
inline_balloon(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 769
def inline_balloon(str)
  %Q[<balloon>#{escape_html(str).gsub(/@maru\[(\d+)\]/) {|m| inline_maru($1)}}</balloon>]
end
inline_bib(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1161
def inline_bib(id)
  %Q(<span type='bibref' idref='#{id}'>[#{@chapter.bibpaper(id).number}]</span>)
end
inline_bou(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 751
def inline_bou(str)
  %Q[<bou>#{escape_html(str)}</bou>]
end
inline_br(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1071
def inline_br(str)
  "\n"
end
inline_chap(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1110
def inline_chap(id)
  if @book.config["chapterlink"]
    %Q(<link href="#{id}">#{@book.chapter_index.number(id)}</link>)
  else
    @book.chapter_index.number(id)
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end
inline_chapref(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1088
def inline_chapref(id)
  chs = ["", "「", "」"]
  unless @book.config["chapref"].nil?
    _chs = @book.config["chapref"].split(",")
    if _chs.size != 3
      error "--chapsplitter must have exactly 3 parameters with comma."
    else
      chs = _chs
    end
  else
  end
  s = "#{chs[0]}#{@book.chapter_index.number(id)}#{chs[1]}#{@book.chapter_index.title(id)}#{chs[2]}"
  if @book.config["chapterlink"]
    %Q(<link href="#{id}">#{s}</link>)
  else
    s
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end
inline_code(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1067
def inline_code(str)
  %Q[<tt type='inline-code'>#{escape_html(str)}</tt>]
end
inline_column_chap(chapter, id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 310
def inline_column_chap(chapter, id)
  if @book.config["chapterlink"]
    %Q(<link href="#{column_label(id)}">#{escape_html(chapter.column(id).caption)}</link>)
  else
    escape_html(chapter.column(id).caption)
  end
end
inline_dtp(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1063
def inline_dtp(str)
  "<?dtp #{str} ?>"
end
inline_fn(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 637
def inline_fn(id)
  %Q[<footnote>#{compile_inline(@chapter.footnote(id).content.strip)}</footnote>]
end
inline_hd_chap(chap, id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1165
def inline_hd_chap(chap, id)
  if chap.number
    n = chap.headline_index.number(id)
    if @book.config["secnolevel"] >= n.split('.').size
      return I18n.t("chapter_quote", "#{n} #{compile_inline(chap.headline(id).caption)}")
    end
  end
  I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
end
inline_hidx(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 708
def inline_hidx(str)
  %Q(<index value="#{escape_html(str)}" />)
end
inline_hint(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 676
def inline_hint(str)
  if @book.config["nolf"].nil?
    %Q[\n<hint>#{escape_html(str)}</hint>]
  else
    %Q[<hint>#{escape_html(str)}</hint>]
  end
end
inline_i(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 716
def inline_i(str)
  %Q(<i>#{escape_html(str)}</i>)
end
inline_icon(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 742
def inline_icon(id)
  begin
    %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A\.\//, "")}" type="inline" />]
  rescue
    warn "no such icon image: #{id}"
    ""
  end
end
inline_idx(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 704
def inline_idx(str)
  %Q(#{escape_html(str)}<index value="#{escape_html(str)}" />)
end
inline_img(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 427
def inline_img(id)
  chapter, id = extract_chapter_id(id)
  if get_chap(chapter).nil?
    "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}</span>"
  else
    "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}</span>"
  end
end
inline_imgref(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 436
def inline_imgref(id)
  chapter, id = extract_chapter_id(id)
  if chapter.image(id).caption.blank?
    inline_img(id)
  else
    if get_chap(chapter).nil?
      "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}#{I18n.t('image_quote', chapter.image(id).caption)}</span>"
    else
      "<span type='image'>#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}#{I18n.t('image_quote', chapter.image(id).caption)}</span>"
    end
  end
end
inline_keytop(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 755
def inline_keytop(str)
  %Q[<keytop>#{escape_html(str)}</keytop>]
end
inline_labelref(idref) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 759
def inline_labelref(idref)
  %Q[<ref idref='#{escape_html(idref)}'>「#{I18n.t("label_marker")}#{escape_html(idref)}」</ref>] # FIXME:節名とタイトルも込みで要出力
end
Also aliased as: inline_ref
inline_list(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 318
def inline_list(id)
  chapter, id = extract_chapter_id(id)
  if get_chap(chapter).nil?
    "<span type='list'>#{I18n.t("list")}#{I18n.t("format_number_without_chapter", [chapter.list(id).number])}</span>"
  else
    "<span type='list'>#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])}</span>"
  end
end
inline_m(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 777
def inline_m(str)
  @texinlineequation += 1
  %Q[<replace idref="texinline-#{@texinlineequation}"><pre>#{escape_html(str)}</pre></replace>]
end
inline_maru(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 684
def inline_maru(str)
  if str =~ /\A\d+\Z/
    sprintf("&#x%x;", 9311 + str.to_i)
  elsif str =~ /\A[A-Z]\Z/
    begin
      sprintf("&#x%x;", 9398 + str.codepoints.to_a[0] - 65)
    rescue NoMethodError
      sprintf("&#x%x;", 9398 + str[0] - 65)
    end
  elsif str =~ /\A[a-z]\Z/
    begin
      sprintf("&#x%x;", 9392 + str.codepoints.to_a[0] - 65)
    rescue NoMethodError
      sprintf("&#x%x;", 9392 + str[0] - 65)
    end
  else
    raise "can't parse maru: #{str}"
  end
end
inline_pageref(idref) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 765
def inline_pageref(idref)
  %Q[<pageref idref='#{escape_html(idref)}'>●●</pageref>] # ページ番号を参照
end
inline_raw(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 672
def inline_raw(str)
  %Q[#{super(str).gsub("\\n", "\n")}]
end
inline_recipe(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1175
def inline_recipe(id)
  # FIXME
  %Q(<recipe idref="#{escape_html(id)}">[XXX]「#{escape_html(id)}」 p.XX</recipe>)
end
inline_ref(idref)
Alias for: inline_labelref
inline_sub(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 668
def inline_sub(str)
  %Q[<sub>#{escape_html(str)}</sub>]
end
inline_sup(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 664
def inline_sup(str)
  %Q[<sup>#{escape_html(str)}</sup>]
end
inline_table(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 418
def inline_table(id)
  chapter, id = extract_chapter_id(id)
  if get_chap(chapter).nil?
    "<span type='table'>#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}</span>"
  else
    "<span type='table'>#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}</span>"
  end
end
inline_title(id) click to toggle source
Calls superclass method ReVIEW::Builder#inline_title
# File lib/review/idgxmlbuilder.rb, line 1121
def inline_title(id)
  title = super
  if @book.config["chapterlink"]
    %Q(<link href="#{id}">#{title}</link>)
  else
    title
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end
inline_tt(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 724
def inline_tt(str)
  %Q(<tt>#{escape_html(str)}</tt>)
end
inline_ttb(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 728
def inline_ttb(str)
  %Q(<tt style='bold'>#{escape_html(str)}</tt>)
end
Also aliased as: inline_ttbold
inline_ttbold(str)
Alias for: inline_ttb
inline_tti(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 734
def inline_tti(str)
  %Q(<tt style='italic'>#{escape_html(str)}</tt>)
end
inline_u(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 738
def inline_u(str)
  %Q(<underline>#{escape_html(str)}</underline>)
end
inline_uchar(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 773
def inline_uchar(str)
  %Q[&#x#{str};]
end
insideout_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 860
def insideout_begin(level, label, caption)
  common_column_begin("insideout", caption)
end
insideout_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 864
def insideout_end(level)
  common_column_end("insideout")
end
insn(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1020
def insn(lines, caption = nil)
  syntaxblock("insn", lines, caption)
end
label(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1042
def label(id)
  # FIXME
  print "<label id='#{id}' />"
end
lead(lines)
Alias for: read
linebreak() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 786
def linebreak
  # FIXME:pが閉じちゃってるので一度戻らないといけないが、難しい…。
  puts "<br />"
end
list_body(id, lines, lang) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 352
def list_body(id, lines, lang)
  print %Q(<pre>)
  codelines_body(lines)
  puts "</pre></codelist>"
end
list_header(id, caption, lang) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 327
def list_header(id, caption, lang)
  puts %Q[<codelist>]
  if get_chap.nil?
    puts %Q[<caption>#{I18n.t("list")}#{I18n.t("format_number_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
  else
    puts %Q[<caption>#{I18n.t("list")}#{I18n.t("format_number", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
  end
end
listnum_body(lines, lang) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 370
def listnum_body(lines, lang)
  print %Q(<pre>)
  no = 1
  lines.each_with_index do |line, i|
    unless @book.config["listinfo"].nil?
      print "<listinfo line=\"#{no}\""
      print " begin=\"1\"" if no == 1
      print " end=\"#{no}\"" if no == lines.size
      print ">"
    end
    print detab("<span type='lineno'>" + (i + 1).to_s.rjust(2) + ": </span>" + line)
    print "\n"
    print "</listinfo>" unless @book.config["listinfo"].nil?
    no += 1
  end
  puts "</pre></codelist>"
end
memo(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 912
def memo(lines, caption = nil)
  captionblock("memo", lines, caption)
end
messages() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 115
def messages
  error_messages() + warning_messages()
end
nofunc_text(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1180
def nofunc_text(str)
  escape_html(str)
end
noindent() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 782
def noindent
  @noindent = true
end
nonum_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 795
def nonum_begin(level, label, caption)
  puts %Q[<title aid:pstyle="h#{level}">#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{escape_html(compile_inline(caption))}"?>]
end
nonum_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 799
def nonum_end(level)
end
note(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 908
def note(lines, caption = nil)
  captionblock("note", lines, caption)
end
notice(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 956
def notice(lines, caption = nil)
  if caption.nil?
    captionblock("notice", lines, nil)
  else
    captionblock("notice-t", lines, caption, "notice-title")
  end
end
numberlessimage(id, caption=nil, metric=nil)
Alias for: indepimage
ol_begin() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 248
def ol_begin
  puts '<ol>'
  if !@ol_num
    @ol_num = 1
  end
end
ol_end() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 260
def ol_end
  puts '</ol>'
  @ol_num = nil
end
ol_item(lines, num) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 255
def ol_item(lines, num)
  puts %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{lines.join.chomp}</li>)
  @ol_num += 1
end
olnum(num) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 265
def olnum(num)
  @ol_num = num.to_i
end
pagebreak() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 791
def pagebreak
  puts "<pagebreak />"
end
paragraph(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 285
def paragraph(lines)
  if @noindent.nil?
    if lines[0] =~ /\A(\t+)/
      puts %Q(<p inlist="#{$1.size}">#{lines.join('').sub(/\A\t+/, "")}</p>)
    else
      puts "<p>#{lines.join}</p>"
    end
  else
    puts %Q(<p aid:pstyle="noindent" noindent='1'>#{lines.join}</p>)
    @noindent = nil
  end
end
planning(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 924
def planning(lines, caption = nil)
  captionblock("planning", lines, caption)
end
point(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 964
def point(lines, caption = nil)
  if caption.nil?
    captionblock("point", lines, nil)
  else
    captionblock("point-t", lines, caption, "point-title")
  end
end
post_paragraph() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 42
def post_paragraph
  '</p>'
end
practice(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 984
def practice(lines)
  captionblock("practice", lines, nil)
end
pre_paragraph() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 38
def pre_paragraph
  '<p>'
end
puts(arg) click to toggle source
Calls superclass method ReVIEW::Builder#puts
# File lib/review/idgxmlbuilder.rb, line 77
def puts(arg)
  if @book.config["nolf"].present?
    print arg
  else
    super
  end
end
quote(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 413
def quote(lines)
  blocked_lines = split_paragraph(lines)
  puts "<quote>#{blocked_lines.join("")}</quote>"
end
rawblock(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1075
def rawblock(lines)
  no = 1
  lines.each do |l|
    print l.gsub("&lt;", "<").gsub("&gt;", ">").gsub("&quot;", "\"").gsub("&amp;", "&")
    print "\n" unless lines.length == no
    no += 1
  end
end
read(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 298
def read(lines)
  puts %Q[<lead>#{split_paragraph(lines).join}</lead>]
end
Also aliased as: lead
ref_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 868
def ref_begin(level, label, caption)
  if !label.nil?
    puts "<reference id='#{label}'>"
  else
    puts "<reference>"
  end
end
ref_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 876
def ref_end(level)
  puts "</reference>"
end
reference(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 980
def reference(lines)
  captionblock("reference", lines, nil)
end
result() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 85
def result
  s = ""
  unless @secttags.nil?
    s += "</sect4>" if @subsubsubsection > 0
    s += "</sect3>" if @subsubsection > 0
    s += "</sect2>" if @subsection > 0
    s += "</sect>" if @section > 0
    s += "</chapter>" if @chapter.number > 0
  end
  messages() + @output.string + s + "</#{@rootelement}>\n"
end
result_metric(array) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 454
def result_metric(array)
  " #{array.join(' ')}"
end
security(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 936
def security(lines, caption = nil)
  captionblock("security", lines, caption)
end
shoot(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 972
def shoot(lines, caption = nil)
  if caption.nil?
    captionblock("shoot", lines, nil)
  else
    captionblock("shoot-t", lines, caption, "shoot-title")
  end
end
source_body(lines, lang) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1138
def source_body(lines, lang)
  puts %Q[<pre>]
  codelines_body(lines)
  puts %Q[</pre></source>]
end
source_header(caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1133
def source_header(caption)
  puts %Q[<source>]
  puts %Q[<caption>#{compile_inline(caption)}</caption>]
end
sup_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 880
def sup_begin(level, label, caption)
  if !label.nil?
    puts "<supplement id='#{label}'>"
  else
    puts "<supplement>"
  end
end
sup_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 888
def sup_end(level)
  puts "</supplement>"
end
syntaxblock(type, lines, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 992
def syntaxblock(type, lines, caption)
  if caption.nil?
    puts %Q[<#{type}>]
  else
    titleopentag = %Q[caption aid:pstyle="#{type}-title"]
    titleclosetag = "caption"
    if type == "insn"
      titleopentag = %Q[floattitle type="insn"]
      titleclosetag = "floattitle"
    end
    puts %Q[<#{type}><#{titleopentag}>#{compile_inline(caption)}</#{titleclosetag}>]
  end
  no = 1
  lines.each do |line|
    unless @book.config["listinfo"].nil?
      print %Q[<listinfo line="#{no}"]
      print %Q[ begin="1"] if no == 1
      print %Q[ end="#{no}"] if no == lines.size
      print %Q[>]
    end
    print detab(line)
    print "\n"
    print "</listinfo>" unless @book.config["listinfo"].nil?
    no += 1
  end
  puts "</#{type}>"
end
table(lines, id = nil, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 496
def table(lines, id = nil, caption = nil)
  tablewidth = nil
  col = 0
  if @book.config["tableopt"]
    tablewidth = @book.config["tableopt"].split(",")[0].to_f / @book.config["pt_to_mm_unit"].to_f
  end
  puts "<table>"
  rows = []
  sepidx = nil
  lines.each_with_index do |line, idx|
    if /\A[\=\-]{12}/ =~ line
      sepidx ||= idx
      next
    end
    if tablewidth.nil?
      rows.push(line.gsub(/\t\.\t/, "\t\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\t").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ""))
    else
      rows.push(line.gsub(/\t\.\t/, "\tDUMMYCELLSPLITTER\t").gsub(/\t\.\.\t/, "\t.\t").gsub(/\t\.\Z/, "\tDUMMYCELLSPLITTER").gsub(/\t\.\.\Z/, "\t.").gsub(/\A\./, ""))
    end
    _col = rows[rows.length - 1].split(/\t/).length
    col = _col if _col > col
  end

  cellwidth = []
  unless tablewidth.nil?
    if @tsize.nil?
      col.times {|n| cellwidth[n] = tablewidth / col }
    else
      cellwidth = @tsize.split(/\s*,\s*/)
      totallength = 0
      cellwidth.size.times do |n|
        cellwidth[n] = cellwidth[n].to_f / @book.config["pt_to_mm_unit"].to_f
        totallength += cellwidth[n]
        warn "total length exceeds limit for table: #{id}" if totallength > tablewidth
      end
      if cellwidth.size < col
        cw = (tablewidth - totallength) / (col - cellwidth.size)
        warn "auto cell sizing exceeds limit for table: #{id}" if cw <= 0
        for i in cellwidth.size..(col - 1)
          cellwidth[i] = cw
        end
      end
    end
  end

  begin
    table_header id, caption unless caption.nil?
  rescue KeyError
    error "no such table: #{id}"
  end
  return if rows.empty?

  if tablewidth.nil?
    print "<tbody>"
  else
    print %Q[<tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="#{rows.length}" aid:tcols="#{col}">]
  end

  if sepidx
    sepidx.times do |y|
      if tablewidth.nil?
        puts %Q[<tr type="header">#{rows.shift}</tr>]
      else
        i = 0
        rows.shift.split(/\t/).each_with_index do |cell, x|
          print %Q[<td xyh="#{x + 1},#{y + 1},#{sepidx}" aid:table="cell" aid:theader="1" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf("%.3f", cellwidth[i])}">#{cell.sub("DUMMYCELLSPLITTER", "")}</td>]
          i += 1
        end
      end
    end
  end
  trputs(tablewidth, rows, cellwidth, sepidx)
  puts "</tbody></table>"
  @tsize = nil
end
table_begin(ncols) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 597
def table_begin(ncols)
end
table_end() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 612
def table_end
  print "<?dtp tablerow last?>"
end
table_header(id, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 589
def table_header(id, caption)
  if get_chap.nil?
  puts %Q[<caption>#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
  else
    puts %Q[<caption>#{I18n.t("table")}#{I18n.t("format_number", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{compile_inline(caption)}</caption>]
  end
end
td(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 608
def td(str)
  str
end
term(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 948
def term(lines)
  captionblock("term", lines, nil)
end
texequation(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 487
def texequation(lines)
  @texblockequation += 1
  puts %Q[<replace idref="texblock-#{@texblockequation}">]
  puts '<pre>'
  puts "#{lines.join("\n")}"
  puts '</pre>'
  puts '</replace>'
end
text(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1084
def text(str)
  str
end
th(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 604
def th(str)
  %Q[<?dtp tablerow header?>#{str}]
end
tip(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 916
def tip(lines, caption = nil)
  captionblock("tip", lines, caption)
end
tr(rows) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 600
def tr(rows)
  puts %Q[<tr>#{rows.join("\t")}</tr>]
end
trputs(tablewidth, rows, cellwidth, sepidx) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 572
def trputs(tablewidth, rows, cellwidth, sepidx)
  sepidx = 0 if sepidx.nil?
  if tablewidth.nil?
    lastline = rows.pop
    rows.each {|row| puts %Q[<tr>#{row}</tr>] }
    puts %Q[<tr type="lastline">#{lastline}</tr>] unless lastline.nil?
  else
    rows.each_with_index do |row, y|
      i = 0
      row.split(/\t/).each_with_index do |cell, x|
        print %Q[<td xyh="#{x + 1},#{y + 1 + sepidx},#{sepidx}" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf("%.3f", cellwidth[i])}">#{cell.sub("DUMMYCELLSPLITTER", "")}</td>]
        i += 1
      end
    end
  end
end
tsize(str) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1047
def tsize(str)
  @tsize = str
end
ul_begin() { |: ""| ... } click to toggle source
# File lib/review/idgxmlbuilder.rb, line 208
def ul_begin
  level = block_given? ? yield : ""
  level = nil if level == 1
  puts "<ul#{level == 1 ? nil : level}>"
end
ul_end() { |: ""| ... } click to toggle source
# File lib/review/idgxmlbuilder.rb, line 242
def ul_end
  level = block_given? ? yield : ""
  level = nil if level == 1
  puts "</ul#{level}>"
end
ul_item(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 214
def ul_item(lines)
  puts %Q(<li aid:pstyle="ul-item">#{lines.join.chomp}</li>)
end
ul_item_begin(lines) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 218
def ul_item_begin(lines)
  print %Q(<li aid:pstyle="ul-item">#{lines.join.chomp})
end
ul_item_end() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 222
def ul_item_end
  puts "</li>"
end
warn(msg) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 97
def warn(msg)
  if @no_error
    @warns.push [@location.filename, @location.lineno, msg]
    puts "----WARNING: #{escape_html(msg)}----"
  else
    $stderr.puts "#{@location}: warning: #{msg}"
  end
end
warning(lines, caption = nil) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 944
def warning(lines, caption = nil)
  captionblock("warning", lines, caption)
end
warning_messages() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 129
def warning_messages
  return '' if @warns.empty?
  "<h2>Warnings</h2>\n" +
  "<ul>\n" +
  @warns.map {|file, line, msg|
    "<li>#{escape_html(file)}:#{line}: #{escape_html(msg)}</li>\n"
  }.join('') +
  "</ul>\n"
end
world_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 836
def world_begin(level, label, caption)
  common_column_begin("world", caption)
end
world_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 840
def world_end(level)
  common_column_end("world")
end
xcolumn_begin(level, label, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 828
def xcolumn_begin(level, label, caption)
  common_column_begin("x", caption)
end
xcolumn_end(level) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 832
def xcolumn_end(level)
  common_column_end("x")
end

Private Instance Methods

builder_init(no_error = false) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 50
def builder_init(no_error = false)
  @no_error = no_error
end
builder_init_file() click to toggle source
# File lib/review/idgxmlbuilder.rb, line 55
def builder_init_file
  @warns = []
  @errors = []
  @section = 0
  @subsection = 0
  @subsubsection = 0
  @subsubsubsection = 0
  @sec_counter = SecCounter.new(5, @chapter)
  @column = 0
  @noindent = nil
  @ol_num = nil
  @rootelement = "doc"
  @secttags = nil
  @tsize = nil
  @texblockequation = 0
  @texinlineequation = 0
  print %Q(<?xml version="1.0" encoding="UTF-8"?>\n)
  print %Q(<#{@rootelement} xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">)
  @secttags = true unless @book.config["structuredxml"].nil?
end
column_label(id) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 304
def column_label(id)
  num = @chapter.column(id).number
  "column-#{num}"
end
quotedlist(lines, css_class, caption) click to toggle source
# File lib/review/idgxmlbuilder.rb, line 392
def quotedlist(lines, css_class, caption)
  print %Q[<list type='#{css_class}'>]
  puts "<caption aid:pstyle='#{css_class}-title'>#{compile_inline(caption)}</caption>" if caption.present?
  print %Q[<pre>]
  no = 1
  lines.each do |line|
    unless @book.config["listinfo"].nil?
      print "<listinfo line=\"#{no}\""
      print " begin=\"1\"" if no == 1
      print " end=\"#{no}\"" if no == lines.size
      print ">"
    end
    print detab(line)
    print "\n"
    print "</listinfo>" unless @book.config["listinfo"].nil?
    no += 1
  end
  puts '</pre></list>'
end