class ReVIEW::HTMLBuilder
Public Instance Methods
best(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 289 def best(lines, caption = nil) captionblock("best", lines, caption) end
bibpaper(lines, id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 927 def bibpaper(lines, id, caption) buf = %Q[<div class="bibpaper">\n] buf << bibpaper_header(id, caption) unless lines.empty? buf << bibpaper_bibpaper(id, caption, lines) end buf << "</div>" << "\n" buf end
bibpaper_bibpaper(id, caption, lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 944 def bibpaper_bibpaper(id, caption, lines) lines.join("") end
bibpaper_header(id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 937 def bibpaper_header(id, caption) buf = %Q(<a id="bib-#{normalize_id(id)}">) buf << "[#{@chapter.bibpaper(id).number}]" buf << %Q(</a>) buf << " #{(caption)}" << "\n" end
box(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 317 def box(lines, caption = nil) buf = "" buf << %Q[<div class="syntax">\n] buf << %Q[<p class="caption">#{caption}</p>\n] unless caption.nil? buf << %Q[<pre class="syntax">] lines.each {|line| buf << detab(line) << "\n" } buf << "</pre>\n" buf << "</div>\n" buf end
bpo(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 776 def bpo(lines) buf = "<bpo>\n" lines.each do |line| buf << detab(line) + "\n" end buf << "</bpo>\n" buf end
captionblock(type, lines, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 259 def captionblock(type, lines, caption) buf = %Q[<div class="#{type}">\n] unless caption.nil? buf << %Q[<p class="caption">#{caption}</p>\n] end if @book.config["deprecated-blocklines"].nil? buf << lines.join("") else error "deprecated-blocklines is obsoleted." end buf << "</div>\n" buf end
caution(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 301 def caution(lines, caption = nil) captionblock("caution", lines, caption) end
centering(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1154 def centering(lines) lines.join("").gsub("<p>", "<p class=\"center\">") end
cmd(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 528 def cmd(lines, caption = nil) buf = %Q[<div class="cmd-code">\n] if caption.present? buf << %Q(<p class="caption">#{caption}</p>\n) end buf << %Q[<pre class="cmd">] body = lines.inject(''){|i, j| i + detab(j) + "\n"} lexer = 'shell-session' buf << highlight(:body => body, :lexer => lexer, :format => 'html') buf << "</pre>\n" buf << "</div>\n" buf end
column_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 202 def column_begin(level, label, caption) buf = %Q[<div class="column">\n] @column += 1 buf << "\n" if level > 1 a_id = %Q[<a id="column-#{@column}"></a>] if caption.empty? buf << a_id + "\n" unless label.nil? else if label.nil? buf << %Q[<h#{level}>#{a_id}#{caption}</h#{level}>\n] else buf << %Q[<h#{level} id="#{normalize_id(label)}">#{a_id}#{caption}</h#{level}>\n] end end buf end
column_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 221 def column_end(level) "</div>\n" end
comment(lines, comment = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 719 def comment(lines, comment = nil) lines ||= [] lines.unshift comment unless comment.blank? if @book.config["draft"] str = lines.map{|line| escape_html(line) }.join("<br />") return %Q(<div class="draft-comment">#{str}</div>\n) else str = lines.join("\n") return %Q(<!-- #{escape_comment(str)} -->\n) end end
compile_href(url, label)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1140 def compile_href(url, label) %Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? (url) : (label)}</a>) end
compile_kw(word, alt)
click to toggle source
# File lib/review/htmlbuilder.rb, line 846 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 838 def compile_ruby(base, ruby) if @book.htmlversion == 5 %Q[<ruby>#{base}<rp>#{I18n.t("ruby_prefix")}</rp><rt>#{ruby}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>] else %Q[<ruby><rb>#{(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 378 def dd(lines) "<dd>#{lines.join}</dd>\n" end
dl_begin()
click to toggle source
# File lib/review/htmlbuilder.rb, line 370 def dl_begin "<dl>\n" end
dl_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 382 def dl_end "</dl>\n" end
doorquote(lines, ref)
click to toggle source
# File lib/review/htmlbuilder.rb, line 559 def doorquote(lines, ref) buf = "" if @book.config["deprecated-blocklines"].nil? buf << %Q[<blockquote style="text-align:right;">\n] buf << "#{lines.join("")}\n" buf << %Q[<p>#{ref}より</p>\n] buf << %Q[</blockquote>\n] else error "deprecated-blocklines is obsoleted." end buf end
dt(line)
click to toggle source
# File lib/review/htmlbuilder.rb, line 374 def dt(line) "<dt>#{line}</dt>\n" end
emlist(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 492 def emlist(lines, caption = nil, lang = nil) buf = %Q[<div class="emlist-code">\n] if caption.present? buf << %Q(<p class="caption">#{caption}</p>\n) end buf << %Q[<pre class="emlist">] body = lines.inject(''){|i, j| i + detab(j) + "\n"} lexer = lang buf << highlight(:body => body, :lexer => lexer, :format => 'html') buf << "</pre>\n" buf << "</div>\n" buf end
emlistnum(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 506 def emlistnum(lines, caption = nil, lang = nil) buf = %Q[<div class="emlistnum-code">\n] if caption.present? buf << %Q(<p class="caption">#{caption}</p>\n) end if highlight? body = lines.inject(''){|i, j| i + detab(j) + "\n"} lexer = lang buf << highlight(:body => body, :lexer => lexer, :format => 'html', :options => {:linenos => 'inline', :nowrap => false}) else buf << '<pre class="emlist">' lines.each_with_index do |line, i| buf << detab((i+1).to_s.rjust(2) + ": " + line) << "\n" end buf << '</pre>' << "\n" end buf << '</div>' << "\n" buf end
error(msg)
click to toggle source
# File lib/review/htmlbuilder.rb, line 131 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 144 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 37 def extname ".#{@book.config["htmlext"]}" end
flushright(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1144 def flushright(lines) result = "" if @book.config["deprecated-blocklines"].nil? result << lines.join("").gsub("<p>", "<p class=\"flushright\">") else error "deprecated-blocklines is obsoleted." end result end
footnote(id, str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 731 def footnote(id, str) if @book.config["epubversion"].to_i == 3 %Q(<div class="footnote" epub:type="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[*#{@chapter.footnote(id).number}] #{str}</p></div>\n) else %Q(<div class="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[<a href="#fnb-#{normalize_id(id)}">*#{@chapter.footnote(id).number}</a>] #{str}</p></div>\n) end end
handle_metric(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 601 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(/\A["']/, '').sub(/"\Z/, '').sub(/["']\Z/, '')}\"| end end
headline(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 164 def headline(level, label, caption) buf = "" prefix, anchor = headline_prefix(level) unless prefix.nil? prefix = %Q[<span class="secno">#{prefix}</span>] end a_id = "" unless anchor.nil? a_id = %Q[<a id="h#{anchor}"></a>] end if caption.empty? buf << a_id+"\n" unless label.nil? else if label.nil? buf << %Q[<h#{level}>#{a_id}#{prefix}#{caption}</h#{level}>\n] else buf << %Q[<h#{level} id="#{normalize_id(label)}">#{a_id}#{prefix}#{caption}</h#{level}>\n] end end buf end
hr()
click to toggle source
# File lib/review/htmlbuilder.rb, line 760 def hr "<hr />\n" end
image_dummy(id, caption, lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 623 def image_dummy(id, caption, lines) buf = %Q[<div class="image">\n] buf << %Q[<pre class="dummyimage">\n] lines.each do |line| buf << detab(line) << "\n" end buf << %Q[</pre>\n] buf << image_header(id, caption) buf << %Q[</div>\n] warn "no such image: #{id}" buf end
image_ext()
click to toggle source
# File lib/review/htmlbuilder.rb, line 1158 def image_ext "png" end
image_header(id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 636 def image_header(id, caption) buf = %Q[<p class="caption">\n] if get_chap.nil? buf << %Q[#{I18n.t("image")}#{I18n.t("format_number_header_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix")}#{caption}\n] else buf << %Q[#{I18n.t("image")}#{I18n.t("format_number_header", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix")}#{caption}\n] end buf << %Q[</p>\n] buf end
image_image(id, caption, metric)
click to toggle source
# File lib/review/htmlbuilder.rb, line 614 def image_image(id, caption, metric) metrics = parse_metric("html", metric) buf = %Q[<div id="#{normalize_id(id)}" class="image">\n] buf << %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(caption)}"#{metrics} />\n] buf << image_header(id, caption) buf << %Q[</div>\n] buf end
important(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 293 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 739 def indepimage(id, caption="", metric=nil) metrics = parse_metric("html", metric) caption = "" if caption.nil? buf = %Q[<div class="image">\n] begin buf << %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(caption)}"#{metrics} />\n] rescue buf << %Q[<pre>missing image: #{id}</pre>\n] end unless caption.empty? buf << %Q[<p class="caption">\n] buf << %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{caption}\n] buf << %Q[</p>\n] end buf << %Q[</div>\n] buf end
Also aliased as: numberlessimage
info(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 281 def info(lines, caption = nil) captionblock("info", lines, caption) end
inline_abbr(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1036 def inline_abbr(str) inline_asis(str, "abbr") end
inline_acronym(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1040 def inline_acronym(str) inline_asis(str, "acronym") end
inline_ami(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 863 def inline_ami(str) %Q(<span class="ami">#{(str)}</span>) end
inline_asis(str, tag)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1032 def inline_asis(str, tag) %Q(<#{tag}>#{(str)}</#{tag}>) end
inline_b(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 859 def inline_b(str) %Q(<b>#{str}</b>) end
inline_bib(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 948 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 1072 def inline_big(str) inline_asis(str, "big") end
inline_bou(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 867 def inline_bou(str) %Q(<span class="bou">#{(str)}</span>) end
inline_br(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 907 def inline_br(str) %Q(<br />) end
inline_chap(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 807 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 795 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 1044 def inline_cite(str) inline_asis(str, "cite") end
inline_code(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 891 def inline_code(str) if @book.htmlversion == 5 %Q(<code class="inline-code tt">#{(str)}</code>) else %Q(<tt class="inline-code">#{(str)}</tt>) end end
inline_column(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 973 def inline_column(id) if @book.config["chapterlink"] %Q(<a href="\##{column_label(id)}" class="columnref">#{I18n.t("column", (@chapter.column(id).caption))}</a>) else I18n.t("column", (@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 1124 def inline_comment(str) if @book.config["draft"] %Q(<span class="draft-comment">#{(str)}</span>) else %Q(<!-- #{escape_comment(escape_html(str))} -->) end end
inline_del(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1096 def inline_del(str) inline_asis(str, "del") end
inline_dfn(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1048 def inline_dfn(str) inline_asis(str, "dfn") end
inline_dtp(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 887 def inline_dtp(str) "<?dtp #{str} ?>" end
inline_em(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1052 def inline_em(str) inline_asis(str, "em") end
inline_fn(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 830 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 952 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} #{chap.headline(id).caption}") else str = I18n.t("chapter_quote", 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 903 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 855 def inline_i(str) %Q(<i>#{str}</i>) end
inline_icon(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1112 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 899 def inline_idx(str) %Q(#{(str)}<!-- IDX:#{escape_comment(escape_html(str))} -->) end
inline_img(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1014 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 1100 def inline_ins(str) inline_asis(str, "ins") end
inline_kbd(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1056 def inline_kbd(str) inline_asis(str, "kbd") end
inline_labelref(idref)
click to toggle source
# File lib/review/htmlbuilder.rb, line 789 def inline_labelref(idref) %Q[<a target='#{(idref)}'>「#{I18n.t("label_marker")}#{(idref)}」</a>] end
Also aliased as: inline_ref
inline_list(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 984 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 911 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">#{(str)}</span>] end end
inline_raw(str)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_raw
# File lib/review/htmlbuilder.rb, line 1132 def inline_raw(str) super(str) end
inline_recipe(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1108 def inline_recipe(str) %Q(<span class="recipe">「#{(str)}」</span>) end
inline_samp(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1060 def inline_samp(str) inline_asis(str, "samp") end
inline_small(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1076 def inline_small(str) inline_asis(str, "small") end
inline_strong(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1064 def inline_strong(str) inline_asis(str, "strong") end
inline_sub(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1080 def inline_sub(str) inline_asis(str, "sub") end
inline_sup(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1084 def inline_sup(str) inline_asis(str, "sup") end
inline_table(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 996 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 818 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 1088 def inline_tt(str) if @book.htmlversion == 5 %Q(<code class="tt">#{(str)}</code>) else %Q(<tt>#{(str)}</tt>) end end
inline_ttb(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 879 def inline_ttb(str) if @book.htmlversion == 5 %Q(<code class="tt"><b>#{(str)}</b></code>) else %Q(<tt><b>#{(str)}</b></tt>) end end
inline_tti(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 871 def inline_tti(str) if @book.htmlversion == 5 %Q(<code class="tt"><i>#{(str)}</i></code>) else %Q(<tt><i>#{(str)}</i></tt>) end end
inline_u(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1104 def inline_u(str) %Q(<u>#{(str)}</u>) end
inline_uchar(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1120 def inline_uchar(str) %Q(&#x#{str};) end
inline_var(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1068 def inline_var(str) inline_asis(str, "var") end
label(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 764 def label(id) %Q(<a id="#{normalize_id(id)}"></a>\n) end
linebreak()
click to toggle source
# File lib/review/htmlbuilder.rb, line 768 def linebreak "<br />\n" end
list(lines, id, caption, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 409 def list(lines, id, caption, lang = nil) buf = %Q[<div class="caption-code">\n] begin buf << list_header(id, caption, lang) rescue KeyError error "no such list: #{id}" end buf << list_body(id, lines, lang) buf << "</div>\n" buf end
list_body(id, lines, lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 429 def list_body(id, lines, lang) id ||= '' buf = %Q[<pre class="list">] body = lines.inject(''){|i, j| i + detab(j) + "\n"} lexer = lang || File.extname(id).gsub(/\./, '') buf << highlight(:body => body, :lexer => lexer, :format => 'html') buf << "</pre>\n" buf end
list_header(id, caption, lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 421 def list_header(id, caption, lang) if get_chap.nil? %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}</p>\n] else %Q[<p class="caption">#{I18n.t("list")}#{I18n.t("format_number_header", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}</p>\n] end end
listnum(lines, id, caption, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 463 def listnum(lines, id, caption, lang = nil) buf = %Q[<div class="code">\n] begin buf << list_header(id, caption, lang) rescue KeyError error "no such list: #{id}" end buf << listnum_body(lines, lang) buf << "</div>" buf end
listnum_body(lines, lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 475 def listnum_body(lines, lang) buf = "" if highlight? body = lines.inject(''){|i, j| i + detab(j) + "\n"} lexer = lang buf << highlight(:body => body, :lexer => lexer, :format => 'html', :options => {:linenos => 'inline', :nowrap => false}) else buf << '<pre class="list">' lines.each_with_index do |line, i| buf << detab((i+1).to_s.rjust(2) + ": " + line) << "\n" end buf << '</pre>' << "\n" end buf end
memo(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 273 def memo(lines, caption = nil) captionblock("memo", lines, caption) end
messages()
click to toggle source
# File lib/review/htmlbuilder.rb, line 140 def messages error_messages() + warning_messages() end
node_texequation(node)
click to toggle source
# File lib/review/htmlbuilder.rb, line 584 def node_texequation(node) buf = "" buf << %Q[<div class="equation">\n] if @book.config["mathml"] require 'math_ml' require 'math_ml/symbol/character_reference' p = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::CharacterReference) buf << p.parse(node.to_raw, true).to_s << "\n" else buf << '<pre>' buf << lines.join("\n") << "\n" buf << "</pre>\n" end buf << "</div>\n" buf end
nofunc_text(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1136 def nofunc_text(str) escape_html(str) end
noindent()
click to toggle source
# File lib/review/htmlbuilder.rb, line 785 def noindent @noindent = true end
nonum_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 186 def nonum_begin(level, label, caption) buf = "" buf << "\n" if level > 1 unless caption.empty? if label.nil? buf << %Q[<h#{level}>#{caption}</h#{level}>\n] else buf << %Q[<h#{level} id="#{normalize_id(label)}">#{caption}</h#{level}>\n] end end buf end
nonum_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 199 def nonum_end(level) end
note(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 328 def note(lines, caption = nil) captionblock("note", lines, caption) end
notice(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 305 def notice(lines, caption = nil) captionblock("notice", lines, caption) end
ol_begin()
click to toggle source
# File lib/review/htmlbuilder.rb, line 352 def ol_begin if @ol_num num = @ol_num @ol_num = nil "<ol start=\"#{num}\">\n" ## it's OK in HTML5, but not OK in XHTML1.1 else "<ol>\n" end end
ol_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 366 def ol_end "</ol>\n" end
ol_item(lines, num)
click to toggle source
# File lib/review/htmlbuilder.rb, line 362 def ol_item(lines, num) "<li>#{lines.map(&:to_s).join}</li>\n" end
olnum(num)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1162 def olnum(num) @ol_num = num.to_i end
pagebreak()
click to toggle source
# File lib/review/htmlbuilder.rb, line 772 def pagebreak %Q(<br class="pagebreak" />\n) end
paragraph(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 386 def paragraph(lines) if @noindent.nil? "<p>#{lines.join}</p>\n" else @noindent = nil %Q[<p class="noindent">#{lines.join}</p>\n] end end
parasep()
click to toggle source
# File lib/review/htmlbuilder.rb, line 395 def parasep "<br />\n" end
planning(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 285 def planning(lines, caption = nil) captionblock("planning", lines, caption) end
point(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 309 def point(lines, caption = nil) captionblock("point", lines, caption) end
quote(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 551 def quote(lines) if @book.config["deprecated-blocklines"].nil? "<blockquote>#{lines.join("")}</blockquote>\n" else error "deprecated-blocklines is obsoleted." end end
read(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 399 def read(lines) if @book.config["deprecated-blocklines"].nil? %Q[<div class="lead">\n#{lines.join("")}\n</div>\n] else error "deprecated-blocklines is obsoleted." end end
Also aliased as: lead
ref_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 235 def ref_begin(level, label, caption) buf << %Q[<div class="reference">\n] buf << headline(level, label, caption) buf end
ref_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 241 def ref_end(level) "</div>\n" end
result()
click to toggle source
# File lib/review/htmlbuilder.rb, line 57 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(@chapter.title) toc = "" toc_level = 0 @chapter.headline_index.items.each do |i| caption = "<li>#{strip_html(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, '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(@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 610 def result_metric(array) " #{array.join(' ')}" end
security(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 297 def security(lines, caption = nil) captionblock("security", lines, caption) end
shoot(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 313 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) buf = %Q[<div class="source-code">\n] buf << source_header(caption) buf << source_body(caption, lines, lang) buf << "</div>\n" buf end
source_body(id, lines, lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 453 def source_body(id, lines, lang) id ||= '' buf = %Q[<pre class="source">] body = lines.inject(''){|i, j| i + detab(j) + "\n"} lexer = lang || File.extname(id).gsub(/\./, '') buf << highlight(:body => body, :lexer => lexer, :format => 'html') buf << "</pre>\n" buf end
source_header(caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 447 def source_header(caption) if caption.present? %Q[<p class="caption">#{caption}</p>\n] end end
sup_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 245 def sup_begin(level, label, caption) buf << %Q[<div class="supplement">\n] buf << headline(level, label, caption) buf end
sup_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 251 def sup_end(level) "</div>\n" end
table(lines, id = nil, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 647 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 buf = %Q[<div id="#{normalize_id(id)}" class="table">\n] else buf = %Q[<div class="table">\n] end begin buf << table_header(id, caption) unless caption.nil? rescue KeyError error "no such table: #{id}" end buf << table_begin(rows.first.size) return if rows.empty? if sepidx sepidx.times do buf << tr(rows.shift.map {|s| th(s) }) end rows.each do |cols| buf << tr(cols.map {|s| td(s) }) end else rows.each do |cols| h, *cs = *cols buf << tr([th(h)] + cs.map {|s| td(s) }) end end buf << table_end buf << %Q[</div>\n] buf end
table_begin(ncols)
click to toggle source
# File lib/review/htmlbuilder.rb, line 699 def table_begin(ncols) "<table>\n" end
table_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 715 def table_end "</table>\n" end
table_header(id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 691 def table_header(id, caption) if get_chap.nil? %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix")}#{caption}</p>\n] else %Q[<p class="caption">#{I18n.t("table")}#{I18n.t("format_number_header", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix")}#{caption}</p>\n] end end
talk(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 572 def talk(lines) buf = "" buf << %Q[<div class="talk">\n] if @book.config["deprecated-blocklines"].nil? buf << "#{lines.join("\n")}\n" else error "deprecated-blocklines is obsoleted." end buf << "</div>\n" buf end
td(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 711 def td(str) "<td>#{str}</td>" end
text(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 923 def text(str) str end
th(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 707 def th(str) "<th>#{str}</th>" end
tip(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 277 def tip(lines, caption = nil) captionblock("tip", lines, caption) end
tr(rows)
click to toggle source
# File lib/review/htmlbuilder.rb, line 703 def tr(rows) "<tr>#{rows.join}</tr>\n" end
tsize(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 255 def tsize(str) # null end
ul_begin()
click to toggle source
# File lib/review/htmlbuilder.rb, line 332 def ul_begin "<ul>\n" end
ul_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 348 def ul_end "</ul>\n" end
ul_item(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 336 def ul_item(lines) "<li>#{lines.map(&:to_s).join}</li>\n" end
ul_item_begin(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 340 def ul_item_begin(lines) "<li>#{lines.map(&:to_s).join}" end
ul_item_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 344 def ul_item_end "</li>\n" end
warn(msg)
click to toggle source
# File lib/review/htmlbuilder.rb, line 122 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 154 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 225 def xcolumn_begin(level, label, caption) buf << %Q[<div class="xcolumn">\n] buf << headline(level, label, caption) buf end
xcolumn_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 231 def xcolumn_end(level) "</div>\n" end
xmlns_ops_prefix()
click to toggle source
# File lib/review/htmlbuilder.rb, line 114 def xmlns_ops_prefix if @book.config["epubversion"].to_i == 3 "epub" else "ops" end end
Private Instance Methods
builder_init(no_error = false)
click to toggle source
# File lib/review/htmlbuilder.rb, line 41 def builder_init(no_error = false) @no_error = no_error @noindent = nil @ol_num = nil end
builder_init_file()
click to toggle source
# File lib/review/htmlbuilder.rb, line 48 def builder_init_file @warns = [] @errors = [] @chapter.book.image_types = %w( .png .jpg .jpeg .gif .svg ) @column = 0 @sec_counter = SecCounter.new(5, @chapter) end
column_label(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 967 def column_label(id) num = @chapter.column(id).number "column-#{num}" end
quotedlist(lines, css_class)
click to toggle source
# File lib/review/htmlbuilder.rb, line 542 def quotedlist(lines, css_class) buf = %Q[<blockquote><pre class="#{css_class}">\n] lines.each do |line| buf << detab(line) << "\n" end buf << "</pre></blockquote>\n" end