Class: ReVIEW::HTMLBuilder
Constant Summary
Constants included
from HTMLUtils
ReVIEW::HTMLUtils::ESC
Constants inherited
from Builder
Builder::CAPTION_TITLES
Instance Method Summary
collapse
-
#best(lines, caption = nil) ⇒ Object
-
#bibpaper(lines, id, caption) ⇒ Object
-
#bibpaper_bibpaper(_id, _caption, lines) ⇒ Object
-
#bibpaper_header(id, caption) ⇒ Object
-
#box(lines, caption = nil) ⇒ Object
-
#bpo(lines) ⇒ Object
-
#captionblock(type, lines, caption) ⇒ Object
-
#caution(lines, caption = nil) ⇒ Object
-
#centering(lines) ⇒ Object
-
#cmd(lines, caption = nil) ⇒ Object
-
#column_begin(level, label, caption) ⇒ Object
-
#column_end(_level) ⇒ Object
-
#comment(lines, comment = nil) ⇒ Object
-
#compile_href(url, label) ⇒ Object
-
#compile_kw(word, alt) ⇒ Object
-
#compile_ruby(base, ruby) ⇒ Object
-
#dd(lines) ⇒ Object
-
#dl_begin ⇒ Object
-
#dl_end ⇒ Object
-
#doorquote(lines, ref) ⇒ Object
-
#dt(line) ⇒ Object
-
#emlist(lines, caption = nil, lang = nil) ⇒ Object
-
#emlistnum(lines, caption = nil, lang = nil) ⇒ Object
-
#emtable(lines, caption = nil) ⇒ Object
-
#extname ⇒ Object
-
#flushright(lines) ⇒ Object
-
#footnote(id, str) ⇒ Object
-
#handle_metric(str) ⇒ Object
-
#headline(level, label, caption) ⇒ Object
-
#hr ⇒ Object
-
#image_dummy(id, caption, lines) ⇒ Object
-
#image_ext ⇒ Object
-
#image_header(id, caption) ⇒ Object
-
#image_image(id, caption, metric) ⇒ Object
-
#imgtable(lines, id, caption = nil, metric = nil) ⇒ Object
-
#imgtable_image(id, caption, metric) ⇒ Object
-
#important(lines, caption = nil) ⇒ Object
-
#indepimage(lines, id, caption = '', metric = nil) ⇒ Object
(also: #numberlessimage)
-
#info(lines, caption = nil) ⇒ Object
-
#inline_abbr(str) ⇒ Object
-
#inline_acronym(str) ⇒ Object
-
#inline_ami(str) ⇒ Object
-
#inline_asis(str, tag) ⇒ Object
-
#inline_b(str) ⇒ Object
-
#inline_bib(id) ⇒ Object
-
#inline_big(str) ⇒ Object
-
#inline_bou(str) ⇒ Object
-
#inline_br(_str) ⇒ Object
-
#inline_chap(id) ⇒ Object
-
#inline_chapref(id) ⇒ Object
-
#inline_cite(str) ⇒ Object
-
#inline_code(str) ⇒ Object
-
#inline_column_chap(chapter, id) ⇒ Object
-
#inline_comment(str) ⇒ Object
-
#inline_del(str) ⇒ Object
-
#inline_dfn(str) ⇒ Object
-
#inline_dtp(str) ⇒ Object
-
#inline_em(str) ⇒ Object
-
#inline_fn(id) ⇒ Object
-
#inline_hd_chap(chap, id) ⇒ Object
-
#inline_hidx(str) ⇒ Object
-
#inline_i(str) ⇒ Object
-
#inline_icon(id) ⇒ Object
-
#inline_idx(str) ⇒ Object
-
#inline_img(id) ⇒ Object
-
#inline_ins(str) ⇒ Object
-
#inline_kbd(str) ⇒ Object
-
#inline_labelref(idref) ⇒ Object
(also: #inline_ref)
-
#inline_list(id) ⇒ Object
-
#inline_m(str) ⇒ Object
-
#inline_pageref(id) ⇒ Object
-
#inline_raw(str) ⇒ Object
-
#inline_recipe(str) ⇒ Object
-
#inline_samp(str) ⇒ Object
-
#inline_small(str) ⇒ Object
-
#inline_strong(str) ⇒ Object
-
#inline_sub(str) ⇒ Object
-
#inline_sup(str) ⇒ Object
-
#inline_table(id) ⇒ Object
-
#inline_tcy(str) ⇒ Object
-
#inline_title(id) ⇒ Object
-
#inline_tt(str) ⇒ Object
-
#inline_ttb(str) ⇒ Object
-
#inline_tti(str) ⇒ Object
-
#inline_u(str) ⇒ Object
-
#inline_uchar(str) ⇒ Object
-
#inline_var(str) ⇒ Object
-
#label(id) ⇒ Object
-
#layoutfile ⇒ Object
-
#linebreak ⇒ Object
-
#list(lines, id, caption, lang = nil) ⇒ Object
-
#list_body(id, lines, lang) ⇒ Object
-
#list_header(id, caption, _lang) ⇒ Object
-
#listnum(lines, id, caption, lang = nil) ⇒ Object
-
#listnum_body(lines, lang) ⇒ Object
-
#make_math_image(str, path, fontsize = 12) ⇒ Object
-
#memo(lines, caption = nil) ⇒ Object
-
#nodisp_begin(level, label, caption) ⇒ Object
-
#nodisp_end(level) ⇒ Object
-
#nofunc_text(str) ⇒ Object
-
#noindent ⇒ Object
-
#nonum_begin(level, label, caption) ⇒ Object
-
#nonum_end(level) ⇒ Object
-
#note(lines, caption = nil) ⇒ Object
-
#notice(lines, caption = nil) ⇒ Object
-
#notoc_begin(level, label, caption) ⇒ Object
-
#notoc_end(level) ⇒ Object
-
#ol_begin ⇒ Object
-
#ol_end ⇒ Object
-
#ol_item(lines, _num) ⇒ Object
-
#olnum(num) ⇒ Object
-
#pagebreak ⇒ Object
-
#paragraph(lines) ⇒ Object
-
#parasep ⇒ Object
-
#planning(lines, caption = nil) ⇒ Object
-
#point(lines, caption = nil) ⇒ Object
-
#post_paragraph ⇒ Object
-
#pre_paragraph ⇒ Object
-
#quote(lines) ⇒ Object
-
#read(lines) ⇒ Object
(also: #lead)
-
#ref_begin(level, label, caption) ⇒ Object
-
#ref_end(_level) ⇒ Object
-
#result ⇒ Object
-
#result_metric(array) ⇒ Object
-
#security(lines, caption = nil) ⇒ Object
-
#shoot(lines, caption = nil) ⇒ Object
-
#source(lines, caption = nil, lang = nil) ⇒ Object
-
#source_body(id, lines, lang) ⇒ Object
-
#source_header(caption) ⇒ Object
-
#sup_begin(level, label, caption) ⇒ Object
-
#sup_end(_level) ⇒ Object
-
#table(lines, id = nil, caption = nil) ⇒ Object
-
#table_begin(_ncols) ⇒ Object
-
#table_end ⇒ Object
-
#table_header(id, caption) ⇒ Object
-
#talk(lines) ⇒ Object
-
#td(str) ⇒ Object
-
#texequation(lines) ⇒ Object
-
#text(str) ⇒ Object
-
#th(str) ⇒ Object
-
#tip(lines, caption = nil) ⇒ Object
-
#tr(rows) ⇒ Object
-
#ul_begin ⇒ Object
-
#ul_end ⇒ Object
-
#ul_item_begin(lines) ⇒ Object
-
#ul_item_end ⇒ Object
-
#warning(lines, caption = nil) ⇒ Object
-
#xcolumn_begin(level, label, caption) ⇒ Object
-
#xcolumn_end(_level) ⇒ Object
-
#xmlns_ops_prefix ⇒ Object
Methods included from HTMLUtils
#escape_comment, #escape_html, #highlight, #highlight?, #highlight_pygments, #highlight_rouge, #normalize_id, #strip_html, #unescape_html
Methods included from TextUtils
#detab, #split_paragraph
Methods inherited from Builder
#bind, #compile_inline, #detab, #embed, #error, #extract_chapter_id, #firstlinenum, #get_chap, #graph, #image, #include, #initialize, #inline_column, #inline_embed, #inline_hd, #inline_href, #inline_imgref, #inline_include, #inline_kw, #inline_ruby, #line_num, #parse_metric, #print, #puts, #raw, #target_name, #tsize, #warn
Instance Method Details
#best(lines, caption = nil) ⇒ Object
249
250
251
|
# File 'lib/review/htmlbuilder.rb', line 249
def best(lines, caption = nil)
captionblock('best', lines, caption)
end
|
#bibpaper(lines, id, caption) ⇒ Object
904
905
906
907
908
909
|
# File 'lib/review/htmlbuilder.rb', line 904
def bibpaper(lines, id, caption)
puts %Q(<div class="bibpaper">)
id, caption
bibpaper_bibpaper id, caption, lines unless lines.empty?
puts '</div>'
end
|
#bibpaper_bibpaper(_id, _caption, lines) ⇒ Object
918
919
920
|
# File 'lib/review/htmlbuilder.rb', line 918
def bibpaper_bibpaper(_id, _caption, lines)
print split_paragraph(lines).join
end
|
911
912
913
914
915
916
|
# File 'lib/review/htmlbuilder.rb', line 911
def (id, caption)
print %Q(<a id="bib-#{normalize_id(id)}">)
print "[#{@chapter.bibpaper(id).number}]"
print '</a>'
puts " #{compile_inline(caption)}"
end
|
#box(lines, caption = nil) ⇒ Object
281
282
283
284
285
286
287
288
|
# File 'lib/review/htmlbuilder.rb', line 281
def box(lines, caption = nil)
puts %Q(<div class="syntax">)
puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
print %Q(<pre class="syntax">)
lines.each { |line| puts detab(line) }
puts '</pre>'
puts '</div>'
end
|
#bpo(lines) ⇒ Object
745
746
747
748
749
|
# File 'lib/review/htmlbuilder.rb', line 745
def bpo(lines)
puts '<bpo>'
lines.each { |line| puts detab(line) }
puts '</bpo>'
end
|
#captionblock(type, lines, caption) ⇒ Object
225
226
227
228
229
230
231
|
# File 'lib/review/htmlbuilder.rb', line 225
def captionblock(type, lines, caption)
puts %Q(<div class="#{type}">)
puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
blocked_lines = split_paragraph(lines)
puts blocked_lines.join("\n")
puts '</div>'
end
|
#caution(lines, caption = nil) ⇒ Object
261
262
263
|
# File 'lib/review/htmlbuilder.rb', line 261
def caution(lines, caption = nil)
captionblock('caution', lines, caption)
end
|
#centering(lines) ⇒ Object
1137
1138
1139
|
# File 'lib/review/htmlbuilder.rb', line 1137
def centering(lines)
puts split_paragraph(lines).join("\n").gsub('<p>', %Q(<p class="center">))
end
|
#cmd(lines, caption = nil) ⇒ Object
480
481
482
483
484
485
486
487
488
489
|
# File 'lib/review/htmlbuilder.rb', line 480
def cmd(lines, caption = nil)
puts %Q(<div class="cmd-code">)
puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
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) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/review/htmlbuilder.rb', line 178
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 if label
elsif label
puts %Q(<h#{level} id="#{normalize_id(label)}">#{a_id}#{compile_inline(caption)}</h#{level}>)
else
puts %Q(<h#{level}>#{a_id}#{compile_inline(caption)}</h#{level}>)
end
end
|
#column_end(_level) ⇒ Object
194
195
196
|
# File 'lib/review/htmlbuilder.rb', line 194
def column_end(_level)
puts '</div>'
end
|
688
689
690
691
692
693
694
|
# File 'lib/review/htmlbuilder.rb', line 688
def (lines, = nil)
lines ||= []
lines.unshift unless .blank?
return unless @book.config['draft']
str = lines.join('<br />')
puts %Q(<div class="draft-comment">#{escape_html(str)}</div>)
end
|
#compile_href(url, label) ⇒ Object
1125
1126
1127
1128
1129
1130
1131
|
# File 'lib/review/htmlbuilder.rb', line 1125
def compile_href(url, label)
if @book.config['externallink']
%Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
else
label.nil? ? escape_html(url) : I18n.t('external_link', [escape_html(label), escape_html(url)])
end
end
|
#compile_kw(word, alt) ⇒ Object
816
817
818
819
820
821
822
823
|
# File 'lib/review/htmlbuilder.rb', line 816
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_html(word))} -->"
end
|
#compile_ruby(base, ruby) ⇒ Object
808
809
810
811
812
813
814
|
# File 'lib/review/htmlbuilder.rb', line 808
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) ⇒ Object
335
336
337
|
# File 'lib/review/htmlbuilder.rb', line 335
def dd(lines)
puts "<dd>#{lines.join}</dd>"
end
|
327
328
329
|
# File 'lib/review/htmlbuilder.rb', line 327
def dl_begin
puts '<dl>'
end
|
339
340
341
|
# File 'lib/review/htmlbuilder.rb', line 339
def dl_end
puts '</dl>'
end
|
#doorquote(lines, ref) ⇒ Object
503
504
505
506
507
508
509
|
# File 'lib/review/htmlbuilder.rb', line 503
def doorquote(lines, ref)
blocked_lines = split_paragraph(lines)
puts %Q(<blockquote style="text-align:right;">)
puts blocked_lines.join("\n")
puts %Q(<p>#{ref}より</p>)
puts '</blockquote>'
end
|
331
332
333
|
# File 'lib/review/htmlbuilder.rb', line 331
def dt(line)
puts "<dt>#{line}</dt>"
end
|
#emlist(lines, caption = nil, lang = nil) ⇒ Object
443
444
445
446
447
448
449
450
451
452
453
454
455
|
# File 'lib/review/htmlbuilder.rb', line 443
def emlist(lines, caption = nil, lang = nil)
puts %Q(<div class="emlist-code">)
puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
class_names = ['emlist']
class_names.push("language-#{lang}") unless lang.blank?
class_names.push('highlight') if highlight?
print %Q(<pre class="#{class_names.join(' ')}">)
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) ⇒ Object
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
# File 'lib/review/htmlbuilder.rb', line 457
def emlistnum(lines, caption = nil, lang = nil)
puts %Q(<div class="emlistnum-code">)
puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
if highlight?
body = lines.inject('') { |i, j| i + detab(j) + "\n" }
lexer = lang
first_line_number = line_num
puts highlight(body: body, lexer: lexer, format: 'html', linenum: true,
options: { linenostart: first_line_number })
else
class_names = ['emlist']
class_names.push("language-#{lang}") unless lang.blank?
class_names.push('highlight') if highlight?
print %Q(<pre class="#{class_names.join(' ')}">)
first_line_num = line_num
lines.each_with_index { |line, i| puts detab((i + first_line_num).to_s.rjust(2) + ': ' + line) }
puts '</pre>'
end
puts '</div>'
end
|
#emtable(lines, caption = nil) ⇒ Object
684
685
686
|
# File 'lib/review/htmlbuilder.rb', line 684
def emtable(lines, caption = nil)
table(lines, nil, caption)
end
|
38
39
40
|
# File 'lib/review/htmlbuilder.rb', line 38
def extname
".#{@book.config['htmlext']}"
end
|
#flushright(lines) ⇒ Object
1133
1134
1135
|
# File 'lib/review/htmlbuilder.rb', line 1133
def flushright(lines)
puts split_paragraph(lines).join("\n").gsub('<p>', %Q(<p class="flushright">))
end
|
696
697
698
699
700
701
702
|
# File 'lib/review/htmlbuilder.rb', line 696
def (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.(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.(id).number}</a>] #{compile_inline(str)}</p></div>)
end
end
|
#handle_metric(str) ⇒ Object
543
544
545
546
547
548
|
# File 'lib/review/htmlbuilder.rb', line 543
def handle_metric(str)
return { 'class' => sprintf('width-%03dper', ($1.to_f * 100).round) } if str =~ /\Ascale=([\d.]+)\Z/
k, v = str.split('=', 2)
{ k => v.sub(/\A["']/, '').sub(/["']\Z/, '') }
end
|
#headline(level, label, caption) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/review/htmlbuilder.rb', line 117
def headline(level, label, caption)
prefix, anchor = headline_prefix(level)
prefix = %Q(<span class="secno">#{prefix}</span>) if prefix
puts '' if level > 1
a_id = ''
a_id = %Q(<a id="h#{anchor}"></a>) if anchor
if caption.empty?
puts a_id if label
elsif label
puts %Q(<h#{level} id="#{normalize_id(label)}">#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>)
else
puts %Q(<h#{level}>#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>)
end
end
|
729
730
731
|
# File 'lib/review/htmlbuilder.rb', line 729
def hr
puts '<hr />'
end
|
#image_dummy(id, caption, lines) ⇒ Object
571
572
573
574
575
576
577
578
579
|
# File 'lib/review/htmlbuilder.rb', line 571
def image_dummy(id, caption, lines)
warn "image not bound: #{id}"
puts %Q(<div id="#{normalize_id(id)}" class="image">)
puts %Q(<pre class="dummyimage">)
lines.each { |line| puts detab(line) }
puts '</pre>'
id, caption
puts '</div>'
end
|
#image_ext ⇒ Object
1141
1142
1143
|
# File 'lib/review/htmlbuilder.rb', line 1141
def image_ext
'png'
end
|
581
582
583
584
585
586
587
588
589
|
# File 'lib/review/htmlbuilder.rb', line 581
def (id, caption)
puts %Q(<p class="caption">)
if get_chap
puts %Q(#{I18n.t('image')}#{I18n.t('format_number_header', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
else
puts %Q(#{I18n.t('image')}#{I18n.t('format_number_header_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
end
puts '</p>'
end
|
#image_image(id, caption, metric) ⇒ Object
563
564
565
566
567
568
569
|
# File 'lib/review/htmlbuilder.rb', line 563
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(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
id, caption
puts '</div>'
end
|
#imgtable(lines, id, caption = nil, metric = nil) ⇒ Object
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
# File 'lib/review/htmlbuilder.rb', line 660
def imgtable(lines, id, caption = nil, metric = nil)
unless @chapter.image(id).bound?
warn "image not bound: #{id}"
image_dummy id, caption, lines
return
end
puts %Q(<div id="#{normalize_id(id)}" class="imgtable image">)
begin
id, caption if caption.present?
rescue KeyError
error "no such table: #{id}"
end
imgtable_image(id, caption, metric)
puts '</div>'
end
|
#imgtable_image(id, caption, metric) ⇒ Object
679
680
681
682
|
# File 'lib/review/htmlbuilder.rb', line 679
def imgtable_image(id, caption, metric)
metrics = parse_metric('html', metric)
puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
end
|
#important(lines, caption = nil) ⇒ Object
253
254
255
|
# File 'lib/review/htmlbuilder.rb', line 253
def important(lines, caption = nil)
captionblock('important', lines, caption)
end
|
#indepimage(lines, id, caption = '', metric = nil) ⇒ Object
Also known as:
numberlessimage
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
|
# File 'lib/review/htmlbuilder.rb', line 704
def indepimage(lines, id, caption = '', metric = nil)
metrics = parse_metric('html', metric)
caption = '' unless caption.present?
puts %Q(<div id="#{normalize_id(id)}" class="image">)
begin
puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
rescue
warn "image not bound: #{id}"
if lines
puts %Q(<pre class="dummyimage">)
lines.each { |line| puts detab(line) }
puts '</pre>'
end
end
if caption.present?
puts %Q(<p class="caption">)
puts %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
puts '</p>'
end
puts '</div>'
end
|
#info(lines, caption = nil) ⇒ Object
241
242
243
|
# File 'lib/review/htmlbuilder.rb', line 241
def info(lines, caption = nil)
captionblock('info', lines, caption)
end
|
#inline_abbr(str) ⇒ Object
1013
1014
1015
|
# File 'lib/review/htmlbuilder.rb', line 1013
def inline_abbr(str)
inline_asis(str, 'abbr')
end
|
#inline_acronym(str) ⇒ Object
1017
1018
1019
|
# File 'lib/review/htmlbuilder.rb', line 1017
def inline_acronym(str)
inline_asis(str, 'acronym')
end
|
#inline_ami(str) ⇒ Object
833
834
835
|
# File 'lib/review/htmlbuilder.rb', line 833
def inline_ami(str)
%Q(<span class="ami">#{escape_html(str)}</span>)
end
|
#inline_asis(str, tag) ⇒ Object
1009
1010
1011
|
# File 'lib/review/htmlbuilder.rb', line 1009
def inline_asis(str, tag)
%Q(<#{tag}>#{escape_html(str)}</#{tag}>)
end
|
#inline_b(str) ⇒ Object
829
830
831
|
# File 'lib/review/htmlbuilder.rb', line 829
def inline_b(str)
%Q(<b>#{escape_html(str)}</b>)
end
|
#inline_bib(id) ⇒ Object
922
923
924
|
# File 'lib/review/htmlbuilder.rb', line 922
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) ⇒ Object
1049
1050
1051
|
# File 'lib/review/htmlbuilder.rb', line 1049
def inline_big(str)
inline_asis(str, 'big')
end
|
#inline_bou(str) ⇒ Object
837
838
839
|
# File 'lib/review/htmlbuilder.rb', line 837
def inline_bou(str)
%Q(<span class="bou">#{escape_html(str)}</span>)
end
|
#inline_br(_str) ⇒ Object
877
878
879
|
# File 'lib/review/htmlbuilder.rb', line 877
def inline_br(_str)
'<br />'
end
|
#inline_chap(id) ⇒ Object
777
778
779
780
781
782
783
784
785
786
|
# File 'lib/review/htmlbuilder.rb', line 777
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) ⇒ Object
765
766
767
768
769
770
771
772
773
774
775
|
# File 'lib/review/htmlbuilder.rb', line 765
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) ⇒ Object
1021
1022
1023
|
# File 'lib/review/htmlbuilder.rb', line 1021
def inline_cite(str)
inline_asis(str, 'cite')
end
|
#inline_code(str) ⇒ Object
861
862
863
864
865
866
867
|
# File 'lib/review/htmlbuilder.rb', line 861
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_chap(chapter, id) ⇒ Object
947
948
949
950
951
952
953
|
# File 'lib/review/htmlbuilder.rb', line 947
def inline_column_chap(chapter, id)
if @book.config['chapterlink']
%Q(<a href="\##{column_label(id, chapter)}" class="columnref">#{I18n.t('column', compile_inline(chapter.column(id).caption))}</a>)
else
I18n.t('column', compile_inline(chapter.column(id).caption))
end
end
|
1102
1103
1104
1105
1106
1107
1108
|
# File 'lib/review/htmlbuilder.rb', line 1102
def (str)
if @book.config['draft']
%Q(<span class="draft-comment">#{escape_html(str)}</span>)
else
''
end
end
|
#inline_del(str) ⇒ Object
1073
1074
1075
|
# File 'lib/review/htmlbuilder.rb', line 1073
def inline_del(str)
inline_asis(str, 'del')
end
|
#inline_dfn(str) ⇒ Object
1025
1026
1027
|
# File 'lib/review/htmlbuilder.rb', line 1025
def inline_dfn(str)
inline_asis(str, 'dfn')
end
|
#inline_dtp(str) ⇒ Object
857
858
859
|
# File 'lib/review/htmlbuilder.rb', line 857
def inline_dtp(str)
"<?dtp #{str} ?>"
end
|
#inline_em(str) ⇒ Object
1029
1030
1031
|
# File 'lib/review/htmlbuilder.rb', line 1029
def inline_em(str)
inline_asis(str, 'em')
end
|
#inline_fn(id) ⇒ Object
800
801
802
803
804
805
806
|
# File 'lib/review/htmlbuilder.rb', line 800
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.(id).number}</a>)
else
%Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref">*#{@chapter.(id).number}</a>)
end
end
|
#inline_hd_chap(chap, id) ⇒ Object
926
927
928
929
930
931
932
933
934
935
936
937
938
939
|
# File 'lib/review/htmlbuilder.rb', line 926
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) ⇒ Object
873
874
875
|
# File 'lib/review/htmlbuilder.rb', line 873
def inline_hidx(str)
%Q(<!-- IDX:#{(escape_html(str))} -->)
end
|
#inline_i(str) ⇒ Object
825
826
827
|
# File 'lib/review/htmlbuilder.rb', line 825
def inline_i(str)
%Q(<i>#{escape_html(str)}</i>)
end
|
#inline_icon(id) ⇒ Object
1089
1090
1091
1092
1093
1094
1095
1096
|
# File 'lib/review/htmlbuilder.rb', line 1089
def inline_icon(id)
begin
%Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="[#{id}]" />)
rescue
warn "image not bound: #{id}"
%Q(<pre>missing image: #{id}</pre>)
end
end
|
#inline_idx(str) ⇒ Object
869
870
871
|
# File 'lib/review/htmlbuilder.rb', line 869
def inline_idx(str)
%Q(#{escape_html(str)}<!-- IDX:#{(escape_html(str))} -->)
end
|
#inline_img(id) ⇒ Object
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
|
# File 'lib/review/htmlbuilder.rb', line 991
def inline_img(id)
chapter, id = (id)
str =
if get_chap(chapter)
"#{I18n.t('image')}#{I18n.t('format_number', [get_chap(chapter), chapter.image(id).number])}"
else
"#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [chapter.image(id).number])}"
end
if @book.config['chapterlink']
%Q(<span class="imgref"><a href="./#{chapter.id}#{extname}##{normalize_id(id)}">#{str}</a></span>)
else
%Q(<span class="imgref">#{str}</span>)
end
rescue KeyError
error "unknown image: #{id}"
nofunc_text("[UnknownImage:#{id}]")
end
|
#inline_ins(str) ⇒ Object
1077
1078
1079
|
# File 'lib/review/htmlbuilder.rb', line 1077
def inline_ins(str)
inline_asis(str, 'ins')
end
|
#inline_kbd(str) ⇒ Object
1033
1034
1035
|
# File 'lib/review/htmlbuilder.rb', line 1033
def inline_kbd(str)
inline_asis(str, 'kbd')
end
|
#inline_labelref(idref) ⇒ Object
Also known as:
inline_ref
755
756
757
|
# File 'lib/review/htmlbuilder.rb', line 755
def inline_labelref(idref)
%Q(<a target='#{escape_html(idref)}'>「#{I18n.t('label_marker')}#{escape_html(idref)}」</a>)
end
|
#inline_list(id) ⇒ Object
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
|
# File 'lib/review/htmlbuilder.rb', line 955
def inline_list(id)
chapter, id = (id)
str =
if get_chap(chapter)
"#{I18n.t('list')}#{I18n.t('format_number', [get_chap(chapter), chapter.list(id).number])}"
else
"#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [chapter.list(id).number])}"
end
if @book.config['chapterlink']
%Q(<span class="listref"><a href="./#{chapter.id}#{extname}##{id}">#{str}</a></span>)
else
%Q(<span class="listref">#{str}</span>)
end
rescue KeyError
error "unknown list: #{id}"
nofunc_text("[UnknownList:#{id}]")
end
|
#inline_m(str) ⇒ Object
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
|
# File 'lib/review/htmlbuilder.rb', line 881
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>)
elsif @book.config['imgmath']
math_str = '$' + str + '$'
key = Digest::SHA256.hexdigest(str)
math_dir = "./#{@book.config['imagedir']}/_review_math"
Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
img_path = "./#{math_dir}/_gen_#{key}.png"
make_math_image(math_str, img_path)
%Q(<span class="equation"><img src="#{img_path}" /></span>)
else
%Q(<span class="equation">#{escape_html(str)}</span>)
end
end
|
761
762
763
|
# File 'lib/review/htmlbuilder.rb', line 761
def (id)
error "pageref op is unsupported on this builder: #{id}"
end
|
#inline_raw(str) ⇒ Object
1117
1118
1119
|
# File 'lib/review/htmlbuilder.rb', line 1117
def inline_raw(str)
super(str)
end
|
#inline_recipe(str) ⇒ Object
1085
1086
1087
|
# File 'lib/review/htmlbuilder.rb', line 1085
def inline_recipe(str)
%Q(<span class="recipe">「#{escape_html(str)}」</span>)
end
|
#inline_samp(str) ⇒ Object
1037
1038
1039
|
# File 'lib/review/htmlbuilder.rb', line 1037
def inline_samp(str)
inline_asis(str, 'samp')
end
|
#inline_small(str) ⇒ Object
1053
1054
1055
|
# File 'lib/review/htmlbuilder.rb', line 1053
def inline_small(str)
inline_asis(str, 'small')
end
|
#inline_strong(str) ⇒ Object
1041
1042
1043
|
# File 'lib/review/htmlbuilder.rb', line 1041
def inline_strong(str)
inline_asis(str, 'strong')
end
|
#inline_sub(str) ⇒ Object
1057
1058
1059
|
# File 'lib/review/htmlbuilder.rb', line 1057
def inline_sub(str)
inline_asis(str, 'sub')
end
|
#inline_sup(str) ⇒ Object
1061
1062
1063
|
# File 'lib/review/htmlbuilder.rb', line 1061
def inline_sup(str)
inline_asis(str, 'sup')
end
|
#inline_table(id) ⇒ Object
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
|
# File 'lib/review/htmlbuilder.rb', line 973
def inline_table(id)
chapter, id = (id)
str =
if get_chap(chapter)
"#{I18n.t('table')}#{I18n.t('format_number', [get_chap(chapter), chapter.table(id).number])}"
else
"#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [chapter.table(id).number])}"
end
if @book.config['chapterlink']
%Q(<span class="tableref"><a href="./#{chapter.id}#{extname}##{id}">#{str}</a></span>)
else
%Q(<span class="tableref">#{str}</span>)
end
rescue KeyError
error "unknown table: #{id}"
nofunc_text("[UnknownTable:#{id}]")
end
|
#inline_tcy(str) ⇒ Object
1110
1111
1112
1113
1114
1115
|
# File 'lib/review/htmlbuilder.rb', line 1110
def inline_tcy(str)
style = 'tcy'
style = 'upright' if str.size == 1 && str.match(/[[:ascii:]]/)
%Q(<span class="#{style}">#{escape_html(str)}</span>)
end
|
#inline_title(id) ⇒ Object
788
789
790
791
792
793
794
795
796
797
798
|
# File 'lib/review/htmlbuilder.rb', line 788
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) ⇒ Object
1065
1066
1067
1068
1069
1070
1071
|
# File 'lib/review/htmlbuilder.rb', line 1065
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) ⇒ Object
849
850
851
852
853
854
855
|
# File 'lib/review/htmlbuilder.rb', line 849
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) ⇒ Object
841
842
843
844
845
846
847
|
# File 'lib/review/htmlbuilder.rb', line 841
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) ⇒ Object
1081
1082
1083
|
# File 'lib/review/htmlbuilder.rb', line 1081
def inline_u(str)
%Q(<u>#{escape_html(str)}</u>)
end
|
#inline_uchar(str) ⇒ Object
1098
1099
1100
|
# File 'lib/review/htmlbuilder.rb', line 1098
def inline_uchar(str)
%Q(&#x#{str};)
end
|
#inline_var(str) ⇒ Object
1045
1046
1047
|
# File 'lib/review/htmlbuilder.rb', line 1045
def inline_var(str)
inline_asis(str, 'var')
end
|
#label(id) ⇒ Object
733
734
735
|
# File 'lib/review/htmlbuilder.rb', line 733
def label(id)
puts %Q(<a id="#{normalize_id(id)}"></a>)
end
|
#layoutfile ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/review/htmlbuilder.rb', line 64
def layoutfile
if @book.config.maker == 'webmaker'
htmldir = 'web/html'
localfilename = 'layout-web.html.erb'
else
htmldir = 'html'
localfilename = 'layout.html.erb'
end
if @book.htmlversion == 5
htmlfilename = File.join(htmldir, 'layout-html5.html.erb')
else
htmlfilename = File.join(htmldir, 'layout-xhtml1.html.erb')
end
layout_file = File.join(@book.basedir, 'layouts', localfilename)
if !File.exist?(layout_file) && File.exist?(File.join(@book.basedir, 'layouts', 'layout.erb'))
raise ReVIEW::ConfigError, 'layout.erb is obsoleted. Please use layout.html.erb.'
end
if File.exist?(layout_file)
if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
warn %Q(user's layout is prohibited in safe mode. ignored.)
layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
end
else
layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
end
layout_file
end
|
#linebreak ⇒ Object
737
738
739
|
# File 'lib/review/htmlbuilder.rb', line 737
def linebreak
puts '<br />'
end
|
#list(lines, id, caption, lang = nil) ⇒ Object
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/review/htmlbuilder.rb', line 363
def list(lines, id, caption, lang = nil)
puts %Q(<div id="#{normalize_id(id)}" class="caption-code">)
begin
id, caption, lang
rescue KeyError
error "no such list: #{id}"
end
list_body id, lines, lang
puts '</div>'
end
|
#list_body(id, lines, lang) ⇒ Object
382
383
384
385
386
387
388
389
390
391
392
|
# File 'lib/review/htmlbuilder.rb', line 382
def list_body(id, lines, lang)
id ||= ''
class_names = ['list']
lexer = lang || File.extname(id).gsub('.', '')
class_names.push("language-#{lexer}") unless lexer.blank?
class_names.push('highlight') if highlight?
print %Q(<pre class="#{class_names.join(' ')}">)
body = lines.inject('') { |i, j| i + detab(j) + "\n" }
puts highlight(body: body, lexer: lexer, format: 'html')
puts '</pre>'
end
|
374
375
376
377
378
379
380
|
# File 'lib/review/htmlbuilder.rb', line 374
def (id, caption, _lang)
if get_chap
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>)
else
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>)
end
end
|
#listnum(lines, id, caption, lang = nil) ⇒ Object
414
415
416
417
418
419
420
421
422
423
|
# File 'lib/review/htmlbuilder.rb', line 414
def listnum(lines, id, caption, lang = nil)
puts %Q(<div id="#{normalize_id(id)}" class="code">)
begin
id, caption, lang
rescue KeyError
error "no such list: #{id}"
end
listnum_body lines, lang
puts '</div>'
end
|
#listnum_body(lines, lang) ⇒ Object
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
# File 'lib/review/htmlbuilder.rb', line 425
def listnum_body(lines, lang)
if highlight?
body = lines.inject('') { |i, j| i + detab(j) + "\n" }
lexer = lang
first_line_number = line_num
puts highlight(body: body, lexer: lexer, format: 'html', linenum: true,
options: { linenostart: first_line_number })
else
class_names = ['list']
class_names.push("language-#{lang}") unless lang.blank?
class_names.push('highlight') if highlight?
print %Q(<pre class="#{class_names.join(' ')}">)
first_line_num = line_num
lines.each_with_index { |line, i| puts detab((i + first_line_num).to_s.rjust(2) + ': ' + line) }
puts '</pre>'
end
end
|
#make_math_image(str, path, fontsize = 12) ⇒ Object
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
|
# File 'lib/review/htmlbuilder.rb', line 1149
def make_math_image(str, path, fontsize = 12)
fontsize2 = (fontsize * 1.2).round.to_i
texsrc = <<-EOB
\\documentclass[12pt]{article}
\\usepackage[utf8]{inputenc}
\\usepackage{amsmath}
\\usepackage{amsthm}
\\usepackage{amssymb}
\\usepackage{amsfonts}
\\usepackage{anyfontsize}
\\usepackage{bm}
\\pagestyle{empty}
\\begin{document}
\\fontsize{#{fontsize}}{#{fontsize2}}\\selectfont #{str}
\\end{document}
EOB
Dir.mktmpdir do |tmpdir|
tex_path = File.join(tmpdir, 'tmpmath.tex')
dvi_path = File.join(tmpdir, 'tmpmath.dvi')
File.write(tex_path, texsrc)
system("latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}")
end
end
|
#memo(lines, caption = nil) ⇒ Object
233
234
235
|
# File 'lib/review/htmlbuilder.rb', line 233
def memo(lines, caption = nil)
captionblock('memo', lines, caption)
end
|
#nodisp_begin(level, label, caption) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/review/htmlbuilder.rb', line 163
def nodisp_begin(level, label, caption)
@nonum_counter += 1
puts '' if level > 1
return unless caption.present?
if label
puts %Q(<a id="#{normalize_id(label)}" /><h#{level} id="#{normalize_id(label)}" hidden="true">#{compile_inline(caption)}</h#{level}>)
else
id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
puts %Q(<a id="#{id}" /><h#{level} id="#{id}" hidden="true">#{compile_inline(caption)}</h#{level}>)
end
end
|
#nodisp_end(level) ⇒ Object
175
176
|
# File 'lib/review/htmlbuilder.rb', line 175
def nodisp_end(level)
end
|
#nofunc_text(str) ⇒ Object
1121
1122
1123
|
# File 'lib/review/htmlbuilder.rb', line 1121
def nofunc_text(str)
escape_html(str)
end
|
751
752
753
|
# File 'lib/review/htmlbuilder.rb', line 751
def noindent
@noindent = true
end
|
#nonum_begin(level, label, caption) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/review/htmlbuilder.rb', line 133
def nonum_begin(level, label, caption)
@nonum_counter += 1
puts if level > 1
return unless caption.present?
if label
puts %Q(<h#{level} id="#{normalize_id(label)}">#{compile_inline(caption)}</h#{level}>)
else
id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
puts %Q(<h#{level} id="#{id}">#{compile_inline(caption)}</h#{level}>)
end
end
|
#nonum_end(level) ⇒ Object
145
146
|
# File 'lib/review/htmlbuilder.rb', line 145
def nonum_end(level)
end
|
#note(lines, caption = nil) ⇒ Object
290
291
292
|
# File 'lib/review/htmlbuilder.rb', line 290
def note(lines, caption = nil)
captionblock('note', lines, caption)
end
|
#notice(lines, caption = nil) ⇒ Object
265
266
267
|
# File 'lib/review/htmlbuilder.rb', line 265
def notice(lines, caption = nil)
captionblock('notice', lines, caption)
end
|
#notoc_begin(level, label, caption) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/review/htmlbuilder.rb', line 148
def notoc_begin(level, label, caption)
@nonum_counter += 1
puts if level > 1
return unless caption.present?
if label
puts %Q(<h#{level} id="#{normalize_id(label)}" notoc="true">#{compile_inline(caption)}</h#{level}>)
else
id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}")
puts %Q(<h#{level} id="#{id}" notoc="true">#{compile_inline(caption)}</h#{level}>)
end
end
|
#notoc_end(level) ⇒ Object
160
161
|
# File 'lib/review/htmlbuilder.rb', line 160
def notoc_end(level)
end
|
310
311
312
313
314
315
316
317
|
# File 'lib/review/htmlbuilder.rb', line 310
def ol_begin
if @ol_num
puts %Q(<ol start="#{@ol_num}">) @ol_num = nil
else
puts '<ol>'
end
end
|
323
324
325
|
# File 'lib/review/htmlbuilder.rb', line 323
def ol_end
puts '</ol>'
end
|
#ol_item(lines, _num) ⇒ Object
319
320
321
|
# File 'lib/review/htmlbuilder.rb', line 319
def ol_item(lines, _num)
puts "<li>#{lines.join}</li>"
end
|
#olnum(num) ⇒ Object
1145
1146
1147
|
# File 'lib/review/htmlbuilder.rb', line 1145
def olnum(num)
@ol_num = num.to_i
end
|
#pagebreak ⇒ Object
741
742
743
|
# File 'lib/review/htmlbuilder.rb', line 741
def pagebreak
puts %Q(<br class="pagebreak" />)
end
|
#paragraph(lines) ⇒ Object
343
344
345
346
347
348
349
350
|
# File 'lib/review/htmlbuilder.rb', line 343
def paragraph(lines)
if @noindent
puts %Q(<p class="noindent">#{lines.join}</p>)
@noindent = nil
else
puts "<p>#{lines.join}</p>"
end
end
|
352
353
354
|
# File 'lib/review/htmlbuilder.rb', line 352
def parasep
puts '<br />'
end
|
#planning(lines, caption = nil) ⇒ Object
245
246
247
|
# File 'lib/review/htmlbuilder.rb', line 245
def planning(lines, caption = nil)
captionblock('planning', lines, caption)
end
|
#point(lines, caption = nil) ⇒ Object
273
274
275
|
# File 'lib/review/htmlbuilder.rb', line 273
def point(lines, caption = nil)
captionblock('point', lines, caption)
end
|
#post_paragraph ⇒ Object
34
35
36
|
# File 'lib/review/htmlbuilder.rb', line 34
def post_paragraph
'</p>'
end
|
#pre_paragraph ⇒ Object
30
31
32
|
# File 'lib/review/htmlbuilder.rb', line 30
def pre_paragraph
'<p>'
end
|
#quote(lines) ⇒ Object
498
499
500
501
|
# File 'lib/review/htmlbuilder.rb', line 498
def quote(lines)
blocked_lines = split_paragraph(lines)
puts %Q(<blockquote>#{blocked_lines.join("\n")}</blockquote>)
end
|
#read(lines) ⇒ Object
Also known as:
lead
356
357
358
359
|
# File 'lib/review/htmlbuilder.rb', line 356
def read(lines)
blocked_lines = split_paragraph(lines)
puts %Q(<div class="lead">\n#{blocked_lines.join("\n")}\n</div>)
end
|
#ref_begin(level, label, caption) ⇒ Object
207
208
209
210
|
# File 'lib/review/htmlbuilder.rb', line 207
def ref_begin(level, label, caption)
print %Q(<div class="reference">)
headline(level, label, caption)
end
|
#ref_end(_level) ⇒ Object
212
213
214
|
# File 'lib/review/htmlbuilder.rb', line 212
def ref_end(_level)
puts '</div>'
end
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/review/htmlbuilder.rb', line 93
def result
@title = strip_html(compile_inline(@chapter.title))
@body = @output.string
@language = @book.config['language']
@stylesheets = @book.config['stylesheet']
@next = @chapter.next_chapter
@prev = @chapter.prev_chapter
@next_title = @next ? compile_inline(@next.title) : ''
@prev_title = @prev ? compile_inline(@prev.title) : ''
@toc = ReVIEW::WEBTOCPrinter.book_to_string(@book) if @book.config.maker == 'webmaker'
ReVIEW::Template.load(layoutfile).result(binding)
end
|
#result_metric(array) ⇒ Object
550
551
552
553
554
555
556
557
558
559
560
561
|
# File 'lib/review/htmlbuilder.rb', line 550
def result_metric(array)
attrs = {}
array.each do |item|
k = item.keys[0]
if attrs[k]
attrs[k] << item[k]
else
attrs[k] = [item[k]]
end
end
' ' + attrs.map { |k, v| %Q(#{k}="#{v.join(' ')}") }.join(' ')
end
|
#security(lines, caption = nil) ⇒ Object
257
258
259
|
# File 'lib/review/htmlbuilder.rb', line 257
def security(lines, caption = nil)
captionblock('security', lines, caption)
end
|
#shoot(lines, caption = nil) ⇒ Object
277
278
279
|
# File 'lib/review/htmlbuilder.rb', line 277
def shoot(lines, caption = nil)
captionblock('shoot', lines, caption)
end
|
#source(lines, caption = nil, lang = nil) ⇒ Object
394
395
396
397
398
399
|
# File 'lib/review/htmlbuilder.rb', line 394
def source(lines, caption = nil, lang = nil)
puts %Q(<div class="source-code">)
caption
source_body caption, lines, lang
puts '</div>'
end
|
#source_body(id, lines, lang) ⇒ Object
405
406
407
408
409
410
411
412
|
# File 'lib/review/htmlbuilder.rb', line 405
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
|
401
402
403
|
# File 'lib/review/htmlbuilder.rb', line 401
def (caption)
puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
end
|
#sup_begin(level, label, caption) ⇒ Object
216
217
218
219
|
# File 'lib/review/htmlbuilder.rb', line 216
def sup_begin(level, label, caption)
print %Q(<div class="supplement">)
headline(level, label, caption)
end
|
#sup_end(_level) ⇒ Object
221
222
223
|
# File 'lib/review/htmlbuilder.rb', line 221
def sup_end(_level)
puts '</div>'
end
|
#table(lines, id = nil, caption = nil) ⇒ Object
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
|
# File 'lib/review/htmlbuilder.rb', line 591
def table(lines, id = nil, caption = nil)
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
if /\A[\=\-]{12}/ =~ line
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
id, caption if caption.present?
rescue KeyError
error "no such table: #{id}"
end
table_begin rows.first.size
return if rows.empty?
if sepidx
sepidx.times { tr(rows.shift.map { |s| th(s) }) }
rows.each { |cols| tr(cols.map { |s| td(s) }) }
else
rows.each do |cols|
h, *cs = *cols
tr([th(h)] + cs.map { |s| td(s) })
end
end
table_end
puts '</div>'
end
|
#table_begin(_ncols) ⇒ Object
640
641
642
|
# File 'lib/review/htmlbuilder.rb', line 640
def table_begin(_ncols)
puts '<table>'
end
|
#table_end ⇒ Object
656
657
658
|
# File 'lib/review/htmlbuilder.rb', line 656
def table_end
puts '</table>'
end
|
630
631
632
633
634
635
636
637
638
|
# File 'lib/review/htmlbuilder.rb', line 630
def (id, caption)
if id.nil?
puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
elsif get_chap
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>)
else
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>)
end
end
|
#talk(lines) ⇒ Object
511
512
513
514
515
516
|
# File 'lib/review/htmlbuilder.rb', line 511
def talk(lines)
puts %Q(<div class="talk">)
blocked_lines = split_paragraph(lines)
puts blocked_lines.join("\n")
puts '</div>'
end
|
652
653
654
|
# File 'lib/review/htmlbuilder.rb', line 652
def td(str)
"<td>#{str}</td>"
end
|
#texequation(lines) ⇒ Object
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
# File 'lib/review/htmlbuilder.rb', line 518
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)
elsif @book.config['imgmath']
puts %Q(<div class="equation">)
math_str = "\\begin{equation*}\n" + unescape_html(lines.join("\n")) + "\n\\end{equation*}\n"
key = Digest::SHA256.hexdigest(math_str)
math_dir = "./#{@book.config['imagedir']}/_review_math"
Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
img_path = "./#{math_dir}/_gen_#{key}.png"
make_math_image(math_str, img_path)
puts %Q(<img src="#{img_path}" />)
puts '</div>'
else
print '<pre>'
puts lines.join("\n")
puts '</pre>'
end
puts '</div>'
end
|
#text(str) ⇒ Object
900
901
902
|
# File 'lib/review/htmlbuilder.rb', line 900
def text(str)
str
end
|
648
649
650
|
# File 'lib/review/htmlbuilder.rb', line 648
def th(str)
"<th>#{str}</th>"
end
|
#tip(lines, caption = nil) ⇒ Object
237
238
239
|
# File 'lib/review/htmlbuilder.rb', line 237
def tip(lines, caption = nil)
captionblock('tip', lines, caption)
end
|
644
645
646
|
# File 'lib/review/htmlbuilder.rb', line 644
def tr(rows)
puts "<tr>#{rows.join}</tr>"
end
|
294
295
296
|
# File 'lib/review/htmlbuilder.rb', line 294
def ul_begin
puts '<ul>'
end
|
306
307
308
|
# File 'lib/review/htmlbuilder.rb', line 306
def ul_end
puts '</ul>'
end
|
#ul_item_begin(lines) ⇒ Object
298
299
300
|
# File 'lib/review/htmlbuilder.rb', line 298
def ul_item_begin(lines)
print "<li>#{lines.join}"
end
|
#ul_item_end ⇒ Object
302
303
304
|
# File 'lib/review/htmlbuilder.rb', line 302
def ul_item_end
puts '</li>'
end
|
#warning(lines, caption = nil) ⇒ Object
269
270
271
|
# File 'lib/review/htmlbuilder.rb', line 269
def warning(lines, caption = nil)
captionblock('warning', lines, caption)
end
|
#xcolumn_begin(level, label, caption) ⇒ Object
198
199
200
201
|
# File 'lib/review/htmlbuilder.rb', line 198
def xcolumn_begin(level, label, caption)
puts %Q(<div class="xcolumn">)
headline(level, label, caption)
end
|
#xcolumn_end(_level) ⇒ Object
203
204
205
|
# File 'lib/review/htmlbuilder.rb', line 203
def xcolumn_end(_level)
puts '</div>'
end
|
#xmlns_ops_prefix ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/review/htmlbuilder.rb', line 109
def xmlns_ops_prefix
if @book.config['epubversion'].to_i == 3
'epub'
else
'ops'
end
end
|