class ReVIEW::HTMLBuilder

Public Instance Methods

best(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 293
def best(lines, caption = nil)
  captionblock("best", lines, caption)
end
bibpaper(lines, id, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 919
def bibpaper(lines, id, caption)
  puts %Q[<div class="bibpaper">]
  bibpaper_header id, caption
  unless lines.empty?
    bibpaper_bibpaper id, caption, lines
  end
  puts "</div>"
end
bibpaper_bibpaper(id, caption, lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 935
def bibpaper_bibpaper(id, caption, lines)
  print split_paragraph(lines).join("")
end
bibpaper_header(id, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 928
def bibpaper_header(id, caption)
  print %Q(<a id="bib-#{normalize_id(id)}">)
  print "[#{@chapter.bibpaper(id).number}]"
  print %Q(</a>)
  puts " #{compile_inline(caption)}"
end
box(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 321
def box(lines, caption = nil)
  puts %Q[<div class="syntax">]
  puts %Q[<p class="caption">#{compile_inline(caption)}</p>] unless caption.nil?
  print %Q[<pre class="syntax">]
  lines.each {|line| puts detab(line) }
  puts '</pre>'
  puts '</div>'
end
bpo(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 769
def bpo(lines)
  puts "<bpo>"
  lines.each do |line|
    puts detab(line)
  end
  puts "</bpo>"
end
captionblock(type, lines, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 263
def captionblock(type, lines, caption)
  puts %Q[<div class="#{type}">]
  unless caption.nil?
    puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
  end
  if @book.config["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts blocked_lines.join("\n")
  else
    lines.each {|l| puts "<p>#{l}</p>" }
  end
  puts '</div>'
end
caution(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 305
def caution(lines, caption = nil)
  captionblock("caution", lines, caption)
end
centering(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1147
def centering(lines)
  puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"center\">")
end
cmd(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 522
def cmd(lines, caption = nil)
  puts %Q[<div class="cmd-code">]
  if caption.present?
    puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
  end
  print %Q[<pre class="cmd">]
  body = lines.inject(''){|i, j| i + detab(j) + "\n"}
  lexer = 'shell-session'
  puts highlight(:body => body, :lexer => lexer, :format => 'html')
  puts '</pre>'
  puts '</div>'
end
column_begin(level, label, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 209
    def column_begin(level, label, caption)
      puts %Q[<div class="column">]

      @column += 1
      puts '' if level > 1
      a_id = %Q[<a id="column-#{@column}"></a>]

      if caption.empty?
        puts a_id unless label.nil?
      else
        if label.nil?
          puts %Q[<h#{level}>#{a_id}#{compile_inline(caption)}</h#{level}>]
        else
          puts %Q[<h#{level} id="#{normalize_id(label)}">#{a_id}#{compile_inline(caption)}</h#{level}>]
        end
      end
#      headline(level, label, caption)
    end
column_end(level) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 228
def column_end(level)
  puts '</div>'
end
comment(lines, comment = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 713
def comment(lines, comment = nil)
  lines ||= []
  lines.unshift comment unless comment.blank?
  if @book.config["draft"]
    str = lines.join("<br />")
    puts %Q(<div class="draft-comment">#{str}</div>)
  else
    str = lines.join("\n")
    puts %Q(<!-- #{escape_comment(str)} -->)
  end
end
compile_href(url, label) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1131
def compile_href(url, label)
  %Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
end
compile_kw(word, alt) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 838
def compile_kw(word, alt)
  %Q[<b class="kw">] +
    if alt
    then escape_html(word + " (#{alt.strip})")
    else escape_html(word)
    end +
    "</b><!-- IDX:#{escape_comment(escape_html(word))} -->"
end
compile_ruby(base, ruby) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 830
def compile_ruby(base, ruby)
  if @book.htmlversion == 5
    %Q[<ruby>#{escape_html(base)}<rp>#{I18n.t("ruby_prefix")}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
  else
    %Q[<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t("ruby_prefix")}</rp><rt>#{ruby}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
  end
end
dd(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 379
def dd(lines)
  puts "<dd>#{lines.join}</dd>"
end
dl_begin() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 371
def dl_begin
  puts '<dl>'
end
dl_end() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 383
def dl_end
  puts '</dl>'
end
doorquote(lines, ref) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 553
    def doorquote(lines, ref)
      if @book.config["deprecated-blocklines"].nil?
        blocked_lines = split_paragraph(lines)
        puts %Q[<blockquote style="text-align:right;">]
        puts "#{blocked_lines.join("\n")}"
        puts %Q[<p>#{ref}より</p>]
        puts %Q[</blockquote>]
      else
        puts <<-QUOTE
<blockquote style="text-align:right;">
  <pre>#{lines.join("\n")}

#{ref}より</pre>
</blockquote>
QUOTE
      end
    end
dt(line) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 375
def dt(line)
  puts "<dt>#{line}</dt>"
end
emlist(lines, caption = nil, lang = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 487
def emlist(lines, caption = nil, lang = nil)
  puts %Q[<div class="emlist-code">]
  if caption.present?
    puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
  end
  print %Q[<pre class="emlist">]
  body = lines.inject(''){|i, j| i + detab(j) + "\n"}
  lexer = lang
  puts highlight(:body => body, :lexer => lexer, :format => 'html')
  puts '</pre>'
  puts '</div>'
end
emlistnum(lines, caption = nil, lang = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 500
def emlistnum(lines, caption = nil, lang = nil)
  puts %Q[<div class="emlistnum-code">]
  if caption.present?
    puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
  end

  if highlight?
    body = lines.inject(''){|i, j| i + detab(j) + "\n"}
    lexer = lang
    puts highlight(:body => body, :lexer => lexer, :format => 'html',
                   :options => {:linenos => 'inline', :nowrap => false})
  else
    print '<pre class="emlist">'
    lines.each_with_index do |line, i|
      puts detab((i+1).to_s.rjust(2) + ": " + line)
    end
    puts '</pre>'
  end

  puts '</div>'
end
error(msg) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 141
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/htmlbuilder.rb, line 154
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
extname() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 43
def extname
  ".#{@book.config["htmlext"]}"
end
flushright(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1135
def flushright(lines)
  if @book.config["deprecated-blocklines"].nil?
    puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"flushright\">")
  else
    puts %Q[<div style="text-align:right;">]
    print %Q[<pre class="flushright">]
    lines.each {|line| puts detab(line) }
    puts '</pre>'
    puts '</div>'
  end
end
footnote(id, str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 725
def footnote(id, str)
  if @book.config["epubversion"].to_i == 3
    puts %Q(<div class="footnote" epub:type="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[*#{@chapter.footnote(id).number}] #{compile_inline(str)}</p></div>)
  else
    puts %Q(<div class="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[<a href="#fnb-#{normalize_id(id)}">*#{@chapter.footnote(id).number}</a>] #{compile_inline(str)}</p></div>)
  end
end
handle_metric(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 599
def handle_metric(str)
  if str =~ /\Ascale=([\d.]+)\Z/
    return "width=\"#{($1.to_f * 100).round}%\""
  else
    k, v = str.split('=', 2)
    return %Q#{k}=\"#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}\"|
  end
end
headline(level, label, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 174
def headline(level, label, caption)
  prefix, anchor = headline_prefix(level)
  unless prefix.nil?
    prefix = %Q[<span class="secno">#{prefix}</span>]
  end
  puts '' if level > 1
  a_id = ""
  unless anchor.nil?
    a_id = %Q[<a id="h#{anchor}"></a>]
  end
  if caption.empty?
    puts a_id unless label.nil?
  else
    if label.nil?
      puts %Q[<h#{level}>#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
    else
      puts %Q[<h#{level} id="#{normalize_id(label)}">#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
    end
  end
end
hr() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 753
def hr
  puts "<hr />"
end
image_dummy(id, caption, lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 620
def image_dummy(id, caption, lines)
  puts %Q[<div class="image">]
  puts %Q[<pre class="dummyimage">]
  lines.each do |line|
    puts detab(line)
  end
  puts %Q[</pre>]
  image_header id, caption
  puts %Q[</div>]
  warn "no such image: #{id}"
end
image_ext() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1151
def image_ext
  "png"
end
image_header(id, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 632
def image_header(id, caption)
  puts %Q[<p class="caption">]
  if get_chap.nil?
    puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
  else
    puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
  end
  puts %Q[</p>]
end
image_image(id, caption, metric) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 612
def image_image(id, caption, metric)
  metrics = parse_metric("html", metric)
  puts %Q[<div id="#{normalize_id(id)}" class="image">]
  puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
  image_header id, caption
  puts %Q[</div>]
end
important(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 297
def important(lines, caption = nil)
  captionblock("important", lines, caption)
end
indepimage(id, caption="", metric=nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 733
def indepimage(id, caption="", metric=nil)
  metrics = parse_metric("html", metric)
  caption = "" if caption.nil?
  puts %Q[<div class="image">]
  begin
    puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
  rescue
    puts %Q[<pre>missing image: #{id}</pre>]
  end

  unless caption.empty?
    puts %Q[<p class="caption">]
    puts %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
    puts %Q[</p>]
  end
  puts %Q[</div>]
end
Also aliased as: numberlessimage, numberlessimage
info(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 285
def info(lines, caption = nil)
  captionblock("info", lines, caption)
end
inline_abbr(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1027
def inline_abbr(str)
  inline_asis(str, "abbr")
end
inline_acronym(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1031
def inline_acronym(str)
  inline_asis(str, "acronym")
end
inline_ami(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 855
def inline_ami(str)
  %Q(<span class="ami">#{escape_html(str)}</span>)
end
inline_asis(str, tag) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1023
def inline_asis(str, tag)
  %Q(<#{tag}>#{escape_html(str)}</#{tag}>)
end
inline_b(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 851
def inline_b(str)
  %Q(<b>#{escape_html(str)}</b>)
end
inline_bib(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 939
def inline_bib(id)
  %Q(<a href="#{@book.bib_file.gsub(/\.re\Z/, ".#{@book.config['htmlext']}")}#bib-#{normalize_id(id)}">[#{@chapter.bibpaper(id).number}]</a>)
end
inline_big(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1063
def inline_big(str)
  inline_asis(str, "big")
end
inline_bou(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 859
def inline_bou(str)
  %Q(<span class="bou">#{escape_html(str)}</span>)
end
inline_br(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 899
def inline_br(str)
  %Q(<br />)
end
inline_chap(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 799
def inline_chap(id)
  if @book.config["chapterlink"]
    %Q(<a href="./#{id}#{extname}">#{@book.chapter_index.number(id)}</a>)
  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
Calls superclass method ReVIEW::Builder#inline_chapref
# File ../../../../../lib/review/htmlbuilder.rb, line 787
def inline_chapref(id)
  title = super
  if @book.config["chapterlink"]
    %Q(<a href="./#{id}#{extname}">#{title}</a>)
  else
    title
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end
inline_cite(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1035
def inline_cite(str)
  inline_asis(str, "cite")
end
inline_code(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 883
def inline_code(str)
  if @book.htmlversion == 5
    %Q(<code class="inline-code tt">#{escape_html(str)}</code>)
  else
    %Q(<tt class="inline-code">#{escape_html(str)}</tt>)
  end
end
inline_column(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 964
def inline_column(id)
  if @book.config["chapterlink"]
    %Q(<a href="\##{column_label(id)}" class="columnref">#{I18n.t("column", escape_html(@chapter.column(id).caption))}</a>)
  else
    I18n.t("column", escape_html(@chapter.column(id).caption))
  end
rescue KeyError
  error "unknown column: #{id}"
  nofunc_text("[UnknownColumn:#{id}]")
end
inline_comment(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1115
def inline_comment(str)
  if @book.config["draft"]
    %Q(<span class="draft-comment">#{escape_html(str)}</span>)
  else
    %Q(<!-- #{escape_comment(escape_html(str))} -->)
  end
end
inline_del(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1087
def inline_del(str)
  inline_asis(str, "del")
end
inline_dfn(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1039
def inline_dfn(str)
  inline_asis(str, "dfn")
end
inline_dtp(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 879
def inline_dtp(str)
  "<?dtp #{str} ?>"
end
inline_em(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1043
def inline_em(str)
  inline_asis(str, "em")
end
inline_fn(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 822
def inline_fn(id)
  if @book.config["epubversion"].to_i == 3
    %Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref" epub:type="noteref">*#{@chapter.footnote(id).number}</a>)
  else
    %Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref">*#{@chapter.footnote(id).number}</a>)
  end
end
inline_hd_chap(chap, id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 943
def inline_hd_chap(chap, id)
  n = chap.headline_index.number(id)
  if chap.number and @book.config["secnolevel"] >= n.split('.').size
    str = I18n.t("chapter_quote", "#{n} #{compile_inline(chap.headline(id).caption)}")
  else
    str = I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
  end
  if @book.config["chapterlink"]
    anchor = "h"+n.gsub(/\./, "-")
    %Q(<a href="#{chap.id}#{extname}##{anchor}">#{str}</a>)
  else
    str
  end
end
inline_hidx(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 895
def inline_hidx(str)
  %Q(<!-- IDX:#{escape_comment(escape_html(str))} -->)
end
inline_i(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 847
def inline_i(str)
  %Q(<i>#{escape_html(str)}</i>)
end
inline_icon(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1103
def inline_icon(id)
  begin
    %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="[#{id}]" />]
  rescue
    %Q[<pre>missing image: #{id}</pre>]
  end
end
inline_idx(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 891
def inline_idx(str)
  %Q(#{escape_html(str)}<!-- IDX:#{escape_comment(escape_html(str))} -->)
end
inline_img(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1005
def inline_img(id)
  chapter, id = extract_chapter_id(id)
  str = nil
  if get_chap(chapter).nil?
    str = "#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}"
  else
    str = "#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}"
  end
  if @book.config["chapterlink"]
    %Q(<a href="./#{chapter.id}#{extname}##{normalize_id(id)}">#{str}</a>)
  else
    str
  end
rescue KeyError
  error "unknown image: #{id}"
  nofunc_text("[UnknownImage:#{id}]")
end
inline_ins(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1091
def inline_ins(str)
  inline_asis(str, "ins")
end
inline_kbd(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1047
def inline_kbd(str)
  inline_asis(str, "kbd")
end
inline_labelref(idref) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 781
def inline_labelref(idref)
  %Q[<a target='#{escape_html(idref)}'>「#{I18n.t("label_marker")}#{escape_html(idref)}」</a>]
end
Also aliased as: inline_ref, inline_ref
inline_list(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 975
def inline_list(id)
  chapter, id = extract_chapter_id(id)
  if get_chap(chapter).nil?
    "#{I18n.t("list")}#{I18n.t("format_number_without_header", [chapter.list(id).number])}"
  else
    "#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])}"
  end
rescue KeyError
  error "unknown list: #{id}"
  nofunc_text("[UnknownList:#{id}]")
end
inline_m(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 903
def inline_m(str)
  if @book.config["mathml"]
    require 'math_ml'
    require 'math_ml/symbol/character_reference'
    parser = MathML::LaTeX::Parser.new(
      :symbol => MathML::Symbol::CharacterReference)
    %Q[<span class="equation">#{parser.parse(str, nil)}</span>]
  else
    %Q[<span class="equation">#{escape_html(str)}</span>]
  end
end
inline_raw(str) click to toggle source
Calls superclass method ReVIEW::Builder#inline_raw
# File ../../../../../lib/review/htmlbuilder.rb, line 1123
def inline_raw(str)
  super(str)
end
inline_recipe(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1099
def inline_recipe(str)
  %Q(<span class="recipe">「#{escape_html(str)}」</span>)
end
inline_ref(idref)
Alias for: inline_labelref
inline_samp(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1051
def inline_samp(str)
  inline_asis(str, "samp")
end
inline_small(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1067
def inline_small(str)
  inline_asis(str, "small")
end
inline_strong(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1055
def inline_strong(str)
  inline_asis(str, "strong")
end
inline_sub(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1071
def inline_sub(str)
  inline_asis(str, "sub")
end
inline_sup(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1075
def inline_sup(str)
  inline_asis(str, "sup")
end
inline_table(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 987
def inline_table(id)
  chapter, id = extract_chapter_id(id)
  str = nil
  if get_chap(chapter).nil?
    str = "#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}"
  else
    str = "#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}"
  end
  if @book.config["chapterlink"]
    %Q(<a href="./#{chapter.id}#{extname}##{id}">#{str}</a>)
  else
    str
  end
rescue KeyError
  error "unknown table: #{id}"
  nofunc_text("[UnknownTable:#{id}]")
end
inline_title(id) click to toggle source
Calls superclass method ReVIEW::Builder#inline_title
# File ../../../../../lib/review/htmlbuilder.rb, line 810
def inline_title(id)
  title = super
  if @book.config["chapterlink"]
    %Q(<a href="./#{id}#{extname}">#{title}</a>)
  else
    title
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end
inline_tt(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1079
def inline_tt(str)
  if @book.htmlversion == 5
    %Q(<code class="tt">#{escape_html(str)}</code>)
  else
    %Q(<tt>#{escape_html(str)}</tt>)
  end
end
inline_ttb(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 871
def inline_ttb(str)
  if @book.htmlversion == 5
    %Q(<code class="tt"><b>#{escape_html(str)}</b></code>)
  else
    %Q(<tt><b>#{escape_html(str)}</b></tt>)
  end
end
inline_tti(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 863
def inline_tti(str)
  if @book.htmlversion == 5
    %Q(<code class="tt"><i>#{escape_html(str)}</i></code>)
  else
    %Q(<tt><i>#{escape_html(str)}</i></tt>)
  end
end
inline_u(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1095
def inline_u(str)
  %Q(<u>#{escape_html(str)}</u>)
end
inline_uchar(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1111
def inline_uchar(str)
  %Q(&#x#{str};)
end
inline_var(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1059
def inline_var(str)
  inline_asis(str, "var")
end
label(id) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 757
def label(id)
  puts %Q(<a id="#{normalize_id(id)}"></a>)
end
lead(lines)
Alias for: read
linebreak() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 761
def linebreak
  puts "<br />"
end
list(lines, id, caption, lang = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 411
def list(lines, id, caption, lang = nil)
  puts %Q[<div class="caption-code">]
  begin
    list_header id, caption, lang
  rescue KeyError
    error "no such list: #{id}"
  end
  list_body id, lines, lang
  puts '</div>'
end
list_body(id, lines, lang) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 430
def list_body(id, lines, lang)
  id ||= ''
  print %Q[<pre class="list">]
  body = lines.inject(''){|i, j| i + detab(j) + "\n"}
  lexer = lang || File.extname(id).gsub(/\./, '')
  puts highlight(:body => body, :lexer => lexer, :format => 'html')
  puts '</pre>'
end
list_header(id, caption, lang) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 422
def list_header(id, caption, lang)
  if get_chap.nil?
    puts %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
  else
    puts %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
  end
end
listnum(lines, id, caption, lang = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 461
def listnum(lines, id, caption, lang = nil)
  puts %Q[<div class="code">]
  begin
    list_header id, caption, lang
  rescue KeyError
    error "no such list: #{id}"
  end
  listnum_body lines, lang
  puts '</div>'
end
listnum_body(lines, lang) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 472
def listnum_body(lines, lang)
  if highlight?
    body = lines.inject(''){|i, j| i + detab(j) + "\n"}
    lexer = lang
    puts highlight(:body => body, :lexer => lexer, :format => 'html',
                   :options => {:linenos => 'inline', :nowrap => false})
  else
    print '<pre class="list">'
    lines.each_with_index do |line, i|
      puts detab((i+1).to_s.rjust(2) + ": " + line)
    end
    puts '</pre>'
  end
end
memo(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 277
def memo(lines, caption = nil)
  captionblock("memo", lines, caption)
end
messages() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 150
def messages
  error_messages() + warning_messages()
end
nofunc_text(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1127
def nofunc_text(str)
  escape_html(str)
end
noindent() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 777
def noindent
  @noindent = true
end
nonum_begin(level, label, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 195
def nonum_begin(level, label, caption)
  puts '' if level > 1
  unless caption.empty?
    if label.nil?
      puts %Q[<h#{level}>#{compile_inline(caption)}</h#{level}>]
    else
      puts %Q[<h#{level} id="#{normalize_id(label)}">#{compile_inline(caption)}</h#{level}>]
    end
  end
end
nonum_end(level) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 206
def nonum_end(level)
end
note(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 330
def note(lines, caption = nil)
  captionblock("note", lines, caption)
end
notice(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 309
def notice(lines, caption = nil)
  captionblock("notice", lines, caption)
end
numberlessimage(id, caption="", metric=nil)
Alias for: indepimage
ol_begin() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 354
def ol_begin
  if @ol_num
    puts "<ol start=\"#{@ol_num}\">" ## it's OK in HTML5, but not OK in XHTML1.1
    @ol_num = nil
  else
    puts '<ol>'
  end
end
ol_end() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 367
def ol_end
  puts '</ol>'
end
ol_item(lines, num) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 363
def ol_item(lines, num)
  puts "<li>#{lines.join}</li>"
end
olnum(num) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 1155
def olnum(num)
  @ol_num = num.to_i
end
pagebreak() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 765
def pagebreak
  puts %Q(<br class="pagebreak" />)
end
paragraph(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 387
def paragraph(lines)
  if @noindent.nil?
    puts "<p>#{lines.join}</p>"
  else
    puts %Q[<p class="noindent">#{lines.join}</p>]
    @noindent = nil
  end
end
parasep() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 396
def parasep
  puts '<br />'
end
planning(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 289
def planning(lines, caption = nil)
  captionblock("planning", lines, caption)
end
point(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 313
def point(lines, caption = nil)
  captionblock("point", lines, caption)
end
post_paragraph() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 39
def post_paragraph
  '</p>'
end
pre_paragraph() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 36
def pre_paragraph
  '<p>'
end
quote(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 544
def quote(lines)
  if @book.config["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts "<blockquote>#{blocked_lines.join("\n")}</blockquote>"
  else
    puts "<blockquote><pre>#{lines.join("\n")}</pre></blockquote>"
  end
end
read(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 400
def read(lines)
  if @book.config["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts %Q[<div class="lead">\n#{blocked_lines.join("\n")}\n</div>]
  else
    puts %Q[<p class="lead">\n#{lines.join("\n")}\n</p>]
  end
end
Also aliased as: lead, lead
ref_begin(level, label, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 241
def ref_begin(level, label, caption)
  print %Q[<div class="reference">]
  headline(level, label, caption)
end
ref_end(level) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 246
def ref_end(level)
  puts '</div>'
end
result() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 63
def result
  layout_file = File.join(@book.basedir, "layouts", "layout.html.erb")
  unless File.exist?(layout_file) # backward compatibility
    layout_file = File.join(@book.basedir, "layouts", "layout.erb")
  end
  if File.exist?(layout_file)
    if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
      warn "user's layout is prohibited in safe mode. ignored."
    else
      title = strip_html(compile_inline(@chapter.title))
      language = @book.config['language']
      stylesheets = @book.config["stylesheet"]

      toc = ""
      toc_level = 0
      @chapter.headline_index.items.each do |i|
        caption = "<li>#{strip_html(compile_inline(i.caption))}</li>\n"
        if toc_level == i.number.size
          # do nothing
        elsif toc_level < i.number.size
          toc += "<ul>\n" * (i.number.size - toc_level)
          toc_level = i.number.size
        elsif toc_level > i.number.size
          toc += "</ul>\n" * (toc_level - i.number.size)
          toc_level = i.number.size
          toc += "<ul>\n" * (toc_level - 1)
        end
        toc += caption
      end
      toc += "</ul>" * toc_level

      return messages() +
        HTMLLayout.new(
        {'body' => @output.string, 'title' => title, 'toc' => toc,
         'builder' => self,
         'language' => language,
         'stylesheets' => stylesheets,
         'next' => @chapter.next_chapter,
         'prev' => @chapter.prev_chapter},
        layout_file).result
    end
  end

  # default XHTML header/footer
  @error_messages = error_messages
  @warning_messages = warning_messages
  @title = strip_html(compile_inline(@chapter.title))
  @body = @output.string
  @language = @book.config['language']
  @stylesheets = @book.config["stylesheet"]

  if @book.htmlversion == 5
    htmlfilename = "layout-html5.html.erb"
  else
    htmlfilename = "layout-xhtml1.html.erb"
  end
  tmplfile = File.expand_path('./html/'+htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
  tmpl = ReVIEW::Template.load(tmplfile)
  tmpl.result(binding)
end
result_metric(array) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 608
def result_metric(array)
  " #{array.join(' ')}"
end
security(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 301
def security(lines, caption = nil)
  captionblock("security", lines, caption)
end
shoot(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 317
def shoot(lines, caption = nil)
  captionblock("shoot", lines, caption)
end
source(lines, caption = nil, lang = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 439
def source(lines, caption = nil, lang = nil)
  puts %Q[<div class="source-code">]
  source_header caption
  source_body caption, lines, lang
  puts '</div>'
end
source_body(id, lines, lang) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 452
def source_body(id, lines, lang)
  id ||= ''
  print %Q[<pre class="source">]
  body = lines.inject(''){|i, j| i + detab(j) + "\n"}
  lexer = lang || File.extname(id).gsub(/\./, '')
  puts highlight(:body => body, :lexer => lexer, :format => 'html')
  puts '</pre>'
end
source_header(caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 446
def source_header(caption)
  if caption.present?
    puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
  end
end
sup_begin(level, label, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 250
def sup_begin(level, label, caption)
  print %Q[<div class="supplement">]
  headline(level, label, caption)
end
sup_end(level) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 255
def sup_end(level)
  puts '</div>'
end
table(lines, id = nil, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 642
def table(lines, id = nil, caption = nil)
  rows = []
  sepidx = nil
  lines.each_with_index do |line, idx|
    if /\A[\=\-]{12}/ =~ line
      # just ignore
      #error "too many table separator" if sepidx
      sepidx ||= idx
      next
    end
    rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
  end
  rows = adjust_n_cols(rows)

  if id
    puts %Q[<div id="#{normalize_id(id)}" class="table">]
  else
    puts %Q[<div class="table">]
  end
  begin
    table_header id, caption unless caption.nil?
  rescue KeyError
    error "no such table: #{id}"
  end
  table_begin rows.first.size
  return if rows.empty?
  if sepidx
    sepidx.times do
      tr rows.shift.map {|s| th(s) }
    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
  table_end
  puts %Q[</div>]
end
table_begin(ncols) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 693
def table_begin(ncols)
  puts '<table>'
end
table_end() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 709
def table_end
  puts '</table>'
end
table_header(id, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 685
def table_header(id, caption)
  if get_chap.nil?
    puts %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
  else
    puts %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}</p>]
  end
end
talk(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 571
def talk(lines)
  puts %Q[<div class="talk">]
  if @book.config["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts "#{blocked_lines.join("\n")}"
  else
    print '<pre>'
    puts "#{lines.join("\n")}"
    puts '</pre>'
  end
  puts '</div>'
end
td(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 705
def td(str)
  "<td>#{str}</td>"
end
texequation(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 584
def texequation(lines)
  puts %Q[<div class="equation">]
  if @book.config["mathml"]
    require 'math_ml'
    require 'math_ml/symbol/character_reference'
    p = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::CharacterReference)
    puts p.parse(unescape_html(lines.join("\n")), true)
  else
    print '<pre>'
    puts "#{lines.join("\n")}"
    puts '</pre>'
  end
  puts '</div>'
end
text(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 915
def text(str)
  str
end
th(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 701
def th(str)
  "<th>#{str}</th>"
end
tip(lines, caption = nil) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 281
def tip(lines, caption = nil)
  captionblock("tip", lines, caption)
end
tr(rows) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 697
def tr(rows)
  puts "<tr>#{rows.join}</tr>"
end
tsize(str) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 259
def tsize(str)
  # null
end
ul_begin() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 334
def ul_begin
  puts '<ul>'
end
ul_end() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 350
def ul_end
  puts '</ul>'
end
ul_item(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 338
def ul_item(lines)
  puts "<li>#{lines.join}</li>"
end
ul_item_begin(lines) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 342
def ul_item_begin(lines)
  print "<li>#{lines.join}"
end
ul_item_end() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 346
def ul_item_end
  puts "</li>"
end
warn(msg) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 132
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_messages() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 164
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
xcolumn_begin(level, label, caption) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 232
def xcolumn_begin(level, label, caption)
  puts %Q[<div class="xcolumn">]
  headline(level, label, caption)
end
xcolumn_end(level) click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 237
def xcolumn_end(level)
  puts '</div>'
end
xmlns_ops_prefix() click to toggle source
# File ../../../../../lib/review/htmlbuilder.rb, line 124
def xmlns_ops_prefix
  if @book.config["epubversion"].to_i == 3
    "epub"
  else
    "ops"
  end
end