class ReVIEW::IDGXMLBuilder
Public Instance Methods
best(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 962 def best(lines, caption = nil) captionblock("best", lines, caption) end
bibpaper(lines, id, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1185 def bibpaper(lines, id, caption) buf = "" buf << bibpaper_header(id, caption) unless lines.empty? buf << bibpaper_bibpaper(id, caption, lines) end buf << %Q(</bibitem>) << @lf buf end
bibpaper_bibpaper(id, caption, lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1202 def bibpaper_bibpaper(id, caption, lines) lines.join("") end
bibpaper_header(id, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1195 def bibpaper_header(id, caption) buf = "" buf << %Q(<bibitem id="bib-#{id}">) << @lf buf << "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{caption}</caption>" << @lf buf end
box(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1057 def box(lines, caption = nil) syntaxblock("box", lines, caption) end
bpo(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1094 def bpo(lines) %Q[<bpo>#{lines.join("\n")}</bpo>] + @lf end
captionblock(type, lines, caption, specialstyle = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 928 def captionblock(type, lines, caption, specialstyle = nil) buf = "" buf << "<#{type}>" style = specialstyle.nil? ? "#{type}-title" : specialstyle buf << "<title aid:pstyle='#{style}'>#{(caption)}</title>" + @lf unless caption.nil? if @book.config["deprecated-blocklines"].nil? buf << "#{lines.join}</#{type}>" << @lf else str = lines.map{|l| l.sub(/^<p>/,"").sub(/<\/p>$/,"")}.join("\n") buf << "#{str}</#{type}>" << @lf end buf end
caution(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 974 def caution(lines, caption = nil) captionblock("caution", lines, caption) end
centering(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 924 def centering(lines) lines.join("").gsub("<p>", "<p align='center'>") + @lf end
choice_multi_begin()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 222 def choice_multi_begin "<choice type='multi'>" + @lf end
choice_multi_end()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 230 def choice_multi_end "</choice>" + @lf end
choice_single_begin()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 218 def choice_single_begin "<choice type='single'>" + @lf end
choice_single_end()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 226 def choice_single_end "</choice>" + @lf end
circle_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 823 def circle_begin(level, label, caption) %Q[<title aid:pstyle="smallcircle">•#{caption}</title>] + @lf end
circle_end(level)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 827 def circle_end(level) end
cmd(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 400 def cmd(lines, caption = nil) quotedlist lines, 'cmd', caption end
codelines_body(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 341 def codelines_body(lines) buf = "" no = 1 lines.each do |line| unless @book.config["listinfo"].nil? buf << "<listinfo line=\"#{no}\"" buf << " begin=\"1\"" if no == 1 buf << " end=\"#{no}\"" if no == lines.size buf << ">" end buf << detab(line) buf << "\n" buf << "</listinfo>" unless @book.config["listinfo"].nil? no += 1 end buf end
column_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 843 def column_begin(level, label, caption) common_column_begin("", caption) end
column_end(level)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 847 def column_end(level) common_column_end("") end
comment(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 647 def comment(str) %Q(<!-- [Comment] #{escape_html(str)} -->) end
common_column_begin(type, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 830 def common_column_begin(type, caption) buf = "" @column += 1 a_id = %Q[id="column-#{@column}"] buf << "<#{type}column #{a_id}>" buf << %Q[<title aid:pstyle="#{type}column-title">#{compile_inline(caption)}</title>] << @lf buf end
common_column_end(type)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 839 def common_column_end(type) "</#{type}column>" + @lf end
compile_href(url, label)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 680 def compile_href(url, label) %Q[<a linkurl='#{url}'>#{label.nil? ? url : label}</a>] end
compile_kw(word, alt)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 663 def compile_kw(word, alt) '<keyword>' + if alt then ("#{word}(#{alt.strip})") else (word) end + '</keyword>' + %Q[<index value="#{word}" />] + if alt alt.split(/\s*,\s*/).collect! {|e| %Q[<index value="#{(e.strip)}" />] }.join else "" end end
compile_ruby(base, ruby)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 659 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 270 def dd(lines) "<dd>#{lines.join.chomp}</dd>" + @lf end
dl_begin()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 262 def dl_begin '<dl>' + @lf end
dl_end()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 274 def dl_end '</dl>' + @lf end
dt(line)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 266 def dt(line) "<dt>#{line}</dt>" + @lf end
dtp(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1086 def dtp(str) %Q(<?dtp #{str} ?>) end
edition_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 875 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 879 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 367 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 371 def emlistnum(lines, caption = nil, lang = nil) _lines = [] lines.each_with_index do |line, i| line.chomp! ## new parser don't remove LF in table (code block) _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 102 def error(msg) if @no_error @errors.push [@location.filename, @location.lineno, msg] buf << "----ERROR: #{escape_html(msg)}----" << @lf else $stderr.puts "#{@location}: error: #{msg}" end end
error_messages()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 115 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 1018 def expert(lines) captionblock("expert", lines, nil) end
extname()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 45 def extname '.xml' end
flushright(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 915 def flushright(lines) if @book.config["deprecated-blocklines"].nil? lines.join("").gsub("<p>", "<p align='right'>") + @lf else str = lines.map{|l| l.sub(/^<p>/,"").sub(/<\/p>$/,"")}.join("\n") "<p align='right'>#{str}</p>" + @lf end end
footnote(id, str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 651 def footnote(id, str) # see inline_fn end
handle_metric(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 469 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 135 def headline(level, label, caption) buf = "" case level when 1 unless @secttags.nil? buf << "</sect4>" if @subsubsubsection > 0 buf << "</sect3>" if @subsubsection > 0 buf << "</sect2>" if @subsection > 0 buf << "</sect>" if @section > 0 end buf << %Q(<chapter id="chap:#{@chapter.number}">) unless @secttags.nil? @section = 0 @subsection = 0 @subsubsection = 0 @subsubsubsection = 0 when 2 unless @secttags.nil? buf << "</sect4>" if @subsubsubsection > 0 buf << "</sect3>" if @subsubsection > 0 buf << "</sect2>" if @subsection > 0 buf << "</sect>" if @section > 0 end @section += 1 buf << %Q(<sect id="sect:#{@chapter.number}.#{@section}">) unless @secttags.nil? @subsection = 0 @subsubsection = 0 @subsubsubsection = 0 when 3 unless @secttags.nil? buf << "</sect4>" if @subsubsubsection > 0 buf << "</sect3>" if @subsubsection > 0 buf << "</sect2>" if @subsection > 0 end @subsection += 1 buf << %Q(<sect2 id="sect:#{@chapter.number}.#{@section}.#{@subsection}">) unless @secttags.nil? @subsubsection = 0 @subsubsubsection = 0 when 4 unless @secttags.nil? buf << "</sect4>" if @subsubsubsection > 0 buf << "</sect3>" if @subsubsection > 0 end @subsubsection += 1 buf << %Q(<sect3 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}">) unless @secttags.nil? @subsubsubsection = 0 when 5 unless @secttags.nil? buf << "</sect4>" if @subsubsubsection > 0 end @subsubsubsection += 1 buf << %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(caption.gsub(/@<fn>\{.+?\}/, '').gsub(/<[^>]+>/, '')) buf << %Q(<title#{label} aid:pstyle="h#{level}">#{prefix}#{caption}</title><?dtp level="#{level}" section="#{prefix}#{toccaption}"?>) << @lf buf end
hood_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 867 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 871 def hood_end(level) common_column_end("hood") end
hr()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1090 def hr "<hr />" end
image_dummy(id, caption, lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 488 def image_dummy(id, caption, lines) buf << "<img>" << @lf buf << %Q[<pre aid:pstyle="dummyimage">] lines.each do |line| buf << detab(line) buf << "\n" end buf << %Q[</pre>] image_header id, caption buf << "</img>" << @lf warn "no such image: #{id}" buf end
image_ext()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1229 def image_ext "eps" end
image_header(id, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 502 def image_header(id, caption) if get_chap.nil? %Q[<caption>#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}</caption>] + @lf else %Q[<caption>#{I18n.t("image")}#{I18n.t("format_number", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}</caption>] + @lf end end
image_image(id, caption, metric=nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 478 def image_image(id, caption, metric=nil) buf = "" metrics = parse_metric("idgxml", metric) buf << "<img>" << @lf buf << %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A.\//, "")}"#{metrics} />] << @lf buf << image_header(id, caption) buf << "</img>" << @lf buf end
important(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 966 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 1061 def indepimage(id, caption=nil, metric=nil) buf = "" metrics = parse_metric("idgxml", metric) buf << "<img>" << @lf begin buf << %Q[<Image href="file://#{@chapter.image(id).path.sub(/\A\.\//, "")}"#{metrics} />] << @lf rescue warn %Q[no such image: #{id}] end buf << %Q[<caption>#{caption}</caption>] + @lf if caption.present? buf << "</img>" << @lf buf end
Also aliased as: numberlessimage
info(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 954 def info(lines, caption = nil) captionblock("info", lines, caption) end
inline_ami(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 732 def inline_ami(str) %Q(<ami>#{str}</ami>) end
inline_b(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 740 def inline_b(str) %Q(<b>#{str}</b>) end
inline_balloon(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 789 def inline_balloon(str) %Q[<balloon>#{str.gsub(/@maru\[(\d+)\]/) {|m| inline_maru($1)}}</balloon>] end
inline_bib(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1206 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 771 def inline_bou(str) %Q[<bou>#{str}</bou>] end
inline_br(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1106 def inline_br(str) "\n" end
inline_chap(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1147 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 1125 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 1102 def inline_code(str) %Q[<tt type='inline-code'>#{str}</tt>] end
inline_column(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 310 def inline_column(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 rescue KeyError error "unknown column: #{id}" nofunc_text("[UnknownColumn:#{id}]") end
inline_dtp(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1098 def inline_dtp(str) "<?dtp #{str} ?>" end
inline_fn(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 655 def inline_fn(id) %Q[<footnote>#{@chapter.footnote(id).content.strip}</footnote>] end
inline_hd_chap(chap, id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1210 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} #{chap.headline(id).caption}") end end I18n.t("chapter_quote", chap.headline(id).caption) end
inline_hidx(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 728 def inline_hidx(str) %Q(<index value="#{str}" />) end
inline_hint(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 696 def inline_hint(str) if @book.config["nolf"].nil? %Q[\n<hint>#{str}</hint>] else %Q[<hint>#{str}</hint>] end end
inline_i(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 736 def inline_i(str) %Q(<i>#{str}</i>) end
inline_icon(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 762 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 724 def inline_idx(str) %Q(#{str}<index value="#{str}" />) end
inline_keytop(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 775 def inline_keytop(str) %Q[<keytop>#{str}</keytop>] end
inline_labelref(idref)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 779 def inline_labelref(idref) %Q[<ref idref='#{(idref)}'>「#{I18n.t("label_marker")}#{(idref)}」</ref>] # FIXME:節名とタイトルも込みで要出力 end
Also aliased as: inline_ref
inline_list(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 321 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 797 def inline_m(str) @texinlineequation += 1 %Q[<replace idref="texinline-#{@texinlineequation}"><pre>#{str}</pre></replace>] end
inline_maru(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 704 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 785 def inline_pageref(idref) %Q[<pageref idref='#{(idref)}'>●●</pageref>] # ページ番号を参照 end
inline_raw(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 692 def inline_raw(str) %Q[#{super(str).gsub("\\n", "\n")}] end
inline_recipe(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1220 def inline_recipe(id) # FIXME %Q(<recipe idref="#{id}">[XXX]「#{id}」 p.XX</recipe>) end
inline_sub(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 688 def inline_sub(str) %Q[<sub>#{str}</sub>] end
inline_sup(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 684 def inline_sup(str) %Q[<sup>#{str}</sup>] end
inline_table(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 436 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 1158 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 744 def inline_tt(str) %Q(<tt>#{str}</tt>) end
inline_ttb(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 748 def inline_ttb(str) %Q(<tt style='bold'>#{str}</tt>) end
Also aliased as: inline_ttbold
inline_tti(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 754 def inline_tti(str) %Q(<tt style='italic'>#{str}</tt>) end
inline_u(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 758 def inline_u(str) %Q(<underline>#{str}</underline>) end
inline_uchar(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 793 def inline_uchar(str) %Q[&#x#{str};] end
insideout_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 883 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 887 def insideout_end(level) common_column_end("insideout") end
insn(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1053 def insn(lines, caption = nil) syntaxblock("insn", lines, caption) end
label(id)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1077 def label(id) # FIXME "<label id='#{id}' />" end
linebreak()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 807 def linebreak # FIXME:pが閉じちゃってるので一度戻らないといけないが、難しい…。 "<br />" + @lf end
link(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 982 def link(lines, caption = nil) captionblock("link", lines, caption) end
list_body(id, lines, lang)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 359 def list_body(id, lines, lang) buf = "" buf << %Q(<pre>) buf << codelines_body(lines) buf << "</pre></codelist>" << @lf buf end
list_header(id, caption, lang)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 330 def list_header(id, caption, lang) buf = "" buf << %Q[<codelist>] << @lf if get_chap.nil? buf << %Q[<caption>#{I18n.t("list")}#{I18n.t("format_number_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}</caption>] << @lf else buf << %Q[<caption>#{I18n.t("list")}#{I18n.t("format_number", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}</caption>] << @lf end buf end
listnum_body(lines, lang)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 380 def listnum_body(lines, lang) buf = "" buf << %Q(<pre>) no = 1 lines.each_with_index do |line, i| unless @book.config["listinfo"].nil? buf << "<listinfo line=\"#{no}\"" buf << " begin=\"1\"" if no == 1 buf << " end=\"#{no}\"" if no == lines.size buf << ">" end buf << detab("<span type='lineno'>" + (i + 1).to_s.rjust(2) + ": </span>" + line) buf << "\n" buf << "</listinfo>" unless @book.config["listinfo"].nil? no += 1 end buf << "</pre></codelist>" << @lf buf end
memo(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 946 def memo(lines, caption = nil) captionblock("memo", lines, caption) end
messages()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 111 def messages error_messages() + warning_messages() end
node_inline_img(node)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 445 def node_inline_img(node) id = node[0].to_raw 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
node_inline_imgref(node)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 455 def node_inline_imgref(node) id = node[0].to_raw chapter, id = extract_chapter_id(id) if chapter.image(id).caption.blank? node_inline_img(node) 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
nofunc_text(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1225 def nofunc_text(str) escape_html(str) end
noindent()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 802 def noindent @noindent = true "" end
nonum_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 816 def nonum_begin(level, label, caption) %Q[<title aid:pstyle="h#{level}">#{caption}</title><?dtp level="#{level}" section="#{caption}"?>] + @lf end
nonum_end(level)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 820 def nonum_end(level) end
note(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 942 def note(lines, caption = nil) captionblock("note", lines, caption) end
notice(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 986 def notice(lines, caption = nil) if caption.nil? captionblock("notice", lines, nil) else captionblock("notice-t", lines, caption, "notice-title") end end
ol_begin()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 240 def ol_begin if !@ol_num @ol_num = 1 end '<ol>' + @lf end
ol_end()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 253 def ol_end @ol_num = nil '</ol>' + @lf end
ol_item(lines, num)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 247 def ol_item(lines, num) buf = %Q(<li aid:pstyle="ol-item" olnum="#{@ol_num}" num="#{num}">#{lines.join.chomp}</li>) + @lf @ol_num += 1 buf end
olnum(num)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 258 def olnum(num) @ol_num = num.to_i end
pagebreak()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 812 def pagebreak "<pagebreak />" + @lf end
paragraph(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 278 def paragraph(lines) buf = "" if @noindent.nil? if lines[0] =~ /\A(\t+)/ buf << %Q(<p inlist="#{$1.size}">#{lines.join('').sub(/\A\t+/, "")}</p>) << @lf else buf << "<p>#{lines.join}</p>" << @lf end else buf << %Q(<p aid:pstyle="noindent" noindent='1'>#{lines.join}</p>) << @lf @noindent = nil end buf end
planning(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 958 def planning(lines, caption = nil) captionblock("planning", lines, caption) end
point(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 994 def point(lines, caption = nil) if caption.nil? captionblock("point", lines, nil) else captionblock("point-t", lines, caption, "point-title") end end
practice(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1014 def practice(lines) captionblock("practice", lines, nil) end
quote(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 427 def quote(lines) if @book.config["deprecated-blocklines"].nil? "<quote>#{lines.join("")}</quote>" + @lf else str = lines.map{|l| l.sub(/^<p>/,"").sub(/<\/p>$/,"")}.join("\n") "<quote>#{str}</quote>" + @lf end end
rawblock(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1110 def rawblock(lines) buf = "" no = 1 lines.each do |l| buf << l.gsub("<", "<").gsub(">", ">").gsub(""", "\"").gsub("&", "&") buf << "\n" unless lines.length == no no += 1 end buf end
read(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 293 def read(lines) if @book.config["deprecated-blocklines"].nil? %Q[<lead>#{lines.join}</lead>] + @lf else str = lines.map{|l| l.sub(/^<p>/,"").sub(/<\/p>$/,"")}.join() %Q[<p aid:pstyle="lead">#{str}</p>] + @lf end end
Also aliased as: lead
ref_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 891 def ref_begin(level, label, caption) if !label.nil? "<reference id='#{label}'>" + @lf else "<reference>" + @lf end end
ref_end(level)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 899 def ref_end(level) "</reference>" + @lf end
reference(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1010 def reference(lines) captionblock("reference", lines, nil) end
result()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 81 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 474 def result_metric(array) " #{array.join(' ')}" end
security(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 970 def security(lines, caption = nil) captionblock("security", lines, caption) end
shoot(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1002 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 1177 def source_body(lines, lang) buf = "" buf << %Q[<pre>] << @lf buf << codelines_body(lines) buf << %Q[</pre></source>] << @lf buf end
source_header(caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1170 def source_header(caption) buf = "" buf << %Q[<source>] << @lf buf << %Q[<caption>#{caption}</caption>] << @lf buf end
sup_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 903 def sup_begin(level, label, caption) if !label.nil? "<supplement id='#{label}'>" + @lf else "<supplement>" + @lf end end
sup_end(level)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 911 def sup_end(level) "</supplement>" + @lf end
syntaxblock(type, lines, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1022 def syntaxblock(type, lines, caption) buf = "" if caption.nil? buf << %Q[<#{type}>] << @lf else titleopentag = %Q[caption aid:pstyle="#{type}-title"] titleclosetag = "caption" if type == "insn" titleopentag = %Q[floattitle type="insn"] titleclosetag = "floattitle" end buf << %Q[<#{type}><#{titleopentag}>#{caption}</#{titleclosetag}>] << @lf end no = 1 lines.each do |line| line.chomp! unless @book.config["listinfo"].nil? buf << %Q[<listinfo line="#{no}"] buf << %Q[ begin="1"] if no == 1 buf << %Q[ end="#{no}"] if no == lines.size buf << %Q[>] end buf << detab(line) buf << "\n" buf << "</listinfo>" unless @book.config["listinfo"].nil? no += 1 end buf << "</#{type}>" << @lf buf end
table(lines, id = nil, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 520 def table(lines, id = nil, caption = nil) buf = "" tablewidth = nil col = 0 unless @book.config["tableopt"].nil? tablewidth = @book.config["tableopt"].split(",")[0].to_f / 0.351 # mm -> pt end buf << "<table>" rows = [] sepidx = nil lines.each_with_index do |line, idx| line.chomp! ## new parser don't remove LF in table (code block) 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 / 0.351 # mm -> pt 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 buf << table_header(id, caption) unless caption.nil? rescue KeyError error "no such table: #{id}" end return if rows.empty? if tablewidth.nil? buf << "<tbody>" else buf << %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? buf << %Q[<tr type="header">#{rows.shift}</tr>] << @lf else i = 0 rows.shift.split(/\t/).each_with_index do |cell, x| buf << %Q[<td xyh="#{x + 1},#{y + 1},#{sepidx}" aid:table="cell" aid:theader="1" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf("%.13f", cellwidth[i])}">#{cell.sub("DUMMYCELLSPLITTER", "")}</td>] i += 1 end end end end buf << trputs(tablewidth, rows, cellwidth, sepidx) buf << "</tbody></table>" << @lf @tsize = nil buf end
table_begin(ncols)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 628 def table_begin(ncols) end
table_end()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 643 def table_end "<?dtp tablerow last?>" end
table_header(id, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 618 def table_header(id, caption) buf = "" if get_chap.nil? buf << %Q[<caption>#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}</caption>] + @lf else buf << %Q[<caption>#{I18n.t("table")}#{I18n.t("format_number", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}</caption>] + @lf end buf end
td(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 639 def td(str) str end
term(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 978 def term(lines) captionblock("term", lines, nil) end
texequation(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 510 def texequation(lines) buf = "" @texblockequation += 1 buf << %Q[<replace idref="texblock-#{@texblockequation}">] << @lf buf << '<pre>' << @lf buf << "#{lines.join("\n")}" << @lf buf << '</pre>' << @lf buf << '</replace>' << @lf end
text(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1121 def text(str) str end
th(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 635 def th(str) %Q[<?dtp tablerow header?>#{str}] end
tip(lines, caption = nil)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 950 def tip(lines, caption = nil) captionblock("tip", lines, caption) end
tr(rows)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 631 def tr(rows) %Q[<tr>#{rows.join("\t")}</tr>] + @lf end
trputs(tablewidth, rows, cellwidth, sepidx)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 599 def trputs(tablewidth, rows, cellwidth, sepidx) buf = "" sepidx = 0 if sepidx.nil? if tablewidth.nil? lastline = rows.pop rows.each {|row| buf << %Q[<tr>#{row}</tr>] } buf << %Q[<tr type="lastline">#{lastline}</tr>] + @lf unless lastline.nil? else rows.each_with_index do |row, y| i = 0 row.split(/\t/).each_with_index do |cell, x| buf << %Q[<td xyh="#{x + 1},#{y + 1 + sepidx},#{sepidx}" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="#{sprintf("%.13f", cellwidth[i])}">#{cell.sub("DUMMYCELLSPLITTER", "")}</td>] i += 1 end end end buf end
tsize(str)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 1082 def tsize(str) @tsize = str end
ul_begin() { |: ""| ... }
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 200 def ul_begin level = block_given? ? yield : "" level = nil if level == 1 "<ul#{level == 1 ? nil : level}>" + @lf end
ul_end() { |: ""| ... }
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 234 def ul_end level = block_given? ? yield : "" level = nil if level == 1 "</ul#{level}>" + @lf end
ul_item(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 206 def ul_item(lines) %Q(<li aid:pstyle="ul-item">#{lines.join.chomp}</li>) + @lf end
ul_item_begin(lines)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 210 def ul_item_begin(lines) %Q(<li aid:pstyle="ul-item">#{lines.join.chomp}) end
ul_item_end()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 214 def ul_item_end "</li>" + @lf end
warn(msg)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 93 def warn(msg) if @no_error @warns.push [@location.filename, @location.lineno, msg] buf << "----WARNING: #{escape_html(msg)}----" << @lf else $stderr.puts "#{@location}: warning: #{msg}" end end
warning_messages()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 125 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 859 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 863 def world_end(level) common_column_end("world") end
xcolumn_begin(level, label, caption)
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 851 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 855 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 49 def builder_init(no_error = false) @no_error = no_error end
builder_init_file()
click to toggle source
# File lib/review/idgxmlbuilder.rb, line 54 def builder_init_file @warns = [] @errors = [] @section = 0 @subsection = 0 @subsubsection = 0 @subsubsubsection = 0 @sec_counter = SecCounter.new(5, @chapter) @column = 0 @noindent = nil @rootelement = "doc" @secttags = nil @tsize = nil @texblockequation = 0 @texinlineequation = 0 @output << %Q(<?xml version="1.0" encoding="UTF-8"?>\n) @output << %Q(<#{@rootelement} xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">) if @book.config["nolf"].present? @lf = "" else @lf = "\n" end @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 404 def quotedlist(lines, css_class, caption) buf = "" buf << %Q[<list type='#{css_class}'>] buf << "<caption aid:pstyle='#{css_class}-title'>#{caption}</caption>" + @lf unless caption.nil? buf << %Q[<pre>] no = 1 lines.each do |line| unless @book.config["listinfo"].nil? buf << "<listinfo line=\"#{no}\"" buf << " begin=\"1\"" if no == 1 buf << " end=\"#{no}\"" if no == lines.size buf << ">" end buf << detab(line) buf << "\n" buf << "</listinfo>" unless @book.config["listinfo"].nil? no += 1 end buf << '</pre></list>' << @lf buf end