Class: ReVIEW::Builder
Constant Summary
collapse
- CAPTION_TITLES =
Compiler.minicolumn_names
Instance Attribute Summary collapse
Attributes included from Loggable
#logger
Instance Method Summary
collapse
-
#beginchild ⇒ Object
-
#bibpaper(lines, id, caption) ⇒ Object
-
#bind(compiler, chapter, location) ⇒ Object
-
#blankline ⇒ Object
-
#caption_top?(type) ⇒ Boolean
-
#captionblock(_type, _lines, _caption, _specialstyle = nil) ⇒ Object
-
#check_nest ⇒ Object
-
#check_nested_minicolumn ⇒ Object
-
#check_printendnotes ⇒ Object
-
#compile_inline(s) ⇒ Object
-
#detab(str, num = nil) ⇒ Object
override TextUtils::detab.
-
#embed(lines, arg = nil) ⇒ Object
-
#emtable(lines, caption = nil) ⇒ Object
-
#endchild ⇒ Object
-
#endnote(_id, _str) ⇒ Object
-
#endnote_begin ⇒ Object
-
#endnote_end ⇒ Object
-
#endnote_item(id) ⇒ Object
-
#escape(str) ⇒ Object
-
#extract_chapter_id(chap_ref) ⇒ Object
-
#firstlinenum(num) ⇒ Object
-
#get_chap(chapter = @chapter) ⇒ Object
-
#graph(lines, id, command, caption = '') ⇒ Object
-
#graph_aafigure(id, file_path, _line, tf_path) ⇒ Object
-
#graph_blockdiag(id, file_path, _line, tf_path) ⇒ Object
-
#graph_gnuplot(id, file_path, line, tf_path) ⇒ Object
-
#graph_graphviz(id, file_path, _line, tf_path) ⇒ Object
-
#graph_plantuml(id, file_path, _line, tf_path) ⇒ Object
-
#handle_metric(str) ⇒ Object
-
#highlight? ⇒ Boolean
-
#image(lines, id, caption, metric = nil) ⇒ Object
-
#image_ext ⇒ Object
-
#in_minicolumn? ⇒ Boolean
-
#initialize(strict = false, *_args, img_math: nil) ⇒ Builder
constructor
A new instance of Builder.
-
#inline_balloon(arg) ⇒ Object
-
#inline_bou(str) ⇒ Object
-
#inline_chap(id) ⇒ Object
-
#inline_chapref(id) ⇒ Object
-
#inline_column(id) ⇒ Object
-
#inline_column_chap(chapter, id) ⇒ Object
-
#inline_embed(args) ⇒ Object
-
#inline_endnote(id) ⇒ Object
-
#inline_eq(id) ⇒ Object
-
#inline_fn(id) ⇒ Object
-
#inline_hd(id) ⇒ Object
(also: #inline_secref)
-
#inline_href(arg) ⇒ Object
-
#inline_img(id) ⇒ Object
-
#inline_imgref(id) ⇒ Object
-
#inline_include(file_name) ⇒ Object
-
#inline_kw(arg) ⇒ Object
-
#inline_list(id) ⇒ Object
-
#inline_pageref(id) ⇒ Object
-
#inline_raw(args) ⇒ Object
-
#inline_ruby(arg) ⇒ Object
-
#inline_sec(id) ⇒ Object
-
#inline_sectitle(id) ⇒ Object
-
#inline_table(id) ⇒ Object
-
#inline_tcy(arg) ⇒ Object
-
#inline_title(id) ⇒ Object
-
#inline_w(s) ⇒ Object
-
#inline_wb(s) ⇒ Object
-
#line_num ⇒ Object
-
#list(lines, id, caption, lang = nil) ⇒ Object
-
#listnum(lines, id, caption, lang = nil) ⇒ Object
-
#load_words(file) ⇒ Object
-
#minicolumn_block_name?(name) ⇒ Boolean
-
#over_secnolevel?(n) ⇒ Boolean
-
#parse_metric(type, metric) ⇒ Object
-
#parse_table_rows(lines) ⇒ Object
-
#post_paragraph ⇒ Object
-
#pre_paragraph ⇒ Object
-
#previous_list_type ⇒ Object
-
#print(*s) ⇒ Object
-
#printendnotes ⇒ Object
-
#puts(*s) ⇒ Object
-
#raw(str) ⇒ Object
-
#result ⇒ Object
(also: #raw_result)
-
#result_metric(array) ⇒ Object
-
#solve_nest(s) ⇒ Object
-
#source(lines, caption = nil, lang = nil) ⇒ Object
-
#system_graph(id, *args) ⇒ Object
-
#table(lines, id = nil, caption = nil) ⇒ Object
-
#table_row_separator_regexp ⇒ Object
-
#table_rows(sepidx, rows) ⇒ Object
-
#target_name ⇒ Object
-
#text(str) ⇒ Object
-
#tsize(str) ⇒ Object
-
#ul_item_begin(lines) ⇒ Object
-
#ul_item_end ⇒ Object
Methods included from Loggable
#app_error, #debug, #error, #error!, #warn
Methods included from TextUtils
#add_space?, #join_lines_to_paragraph, #split_paragraph
Constructor Details
#initialize(strict = false, *_args, img_math: nil) ⇒ Builder
Returns a new instance of Builder.
38
39
40
41
42
43
44
45
46
|
# File 'lib/review/builder.rb', line 38
def initialize(strict = false, *_args, img_math: nil)
@strict = strict
@output = nil
@logger = ReVIEW.logger
@doc_status = {}
@dictionary = {}
@img_math = img_math
@shown_endnotes = true
end
|
Instance Attribute Details
#doc_status ⇒ Object
Returns the value of attribute doc_status.
35
36
37
|
# File 'lib/review/builder.rb', line 35
def doc_status
@doc_status
end
|
Returns the value of attribute location.
36
37
38
|
# File 'lib/review/builder.rb', line 36
def location
@location
end
|
Instance Method Details
#beginchild ⇒ Object
779
780
781
782
783
784
785
786
|
# File 'lib/review/builder.rb', line 779
def beginchild
@children ||= []
unless previous_list_type
app_error "#{@location}: //beginchild is shown, but previous element isn't ul, ol, or dl"
end
puts "\x01→#{previous_list_type}←\x01"
@children.push(previous_list_type)
end
|
#bibpaper(lines, id, caption) ⇒ Object
431
432
433
434
435
436
437
438
|
# File 'lib/review/builder.rb', line 431
def bibpaper(lines, id, caption)
(id, caption)
unless lines.empty?
puts
bibpaper_bibpaper(id, caption, lines)
end
puts
end
|
#bind(compiler, chapter, location) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
|
# File 'lib/review/builder.rb', line 48
def bind(compiler, chapter, location)
@compiler = compiler
@chapter = chapter
@location = location
@output = StringIO.new
if @chapter.present?
@book = @chapter.book
end
@chapter.generate_indexes
if @book
@book.generate_indexes
end
@tabwidth = nil
@tsize = nil
if @book && @book.config
@img_math ||= ReVIEW::ImgMath.new(@book.config)
if words_file_path = @book.config['words_file']
words_files = if words_file_path.is_a?(String)
[words_file_path]
else
words_file_path
end
words_files.each do |f|
load_words(f)
end
end
if @book.config['tabwidth']
@tabwidth = @book.config['tabwidth']
end
if @book.config['join_lines_by_lang']
begin
require 'unicode/eaw'
rescue LoadError
warn 'not found unicode/eaw. disabled join_lines_by_lang feature.', location: @location
@book.config['join_lines_by_lang'] = nil
end
end
end
builder_init_file
end
|
#blankline ⇒ Object
306
307
308
|
# File 'lib/review/builder.rb', line 306
def blankline
puts ''
end
|
#caption_top?(type) ⇒ Boolean
796
797
798
799
800
801
|
# File 'lib/review/builder.rb', line 796
def caption_top?(type)
unless %w[top bottom].include?(@book.config['caption_position'][type])
warn "invalid caption_position/#{type} parameter. 'top' is assumed", location: @location
end
@book.config['caption_position'][type] != 'bottom'
end
|
#captionblock(_type, _lines, _caption, _specialstyle = nil) ⇒ Object
588
589
590
|
# File 'lib/review/builder.rb', line 588
def captionblock(_type, _lines, _caption, _specialstyle = nil)
raise NotImplementedError
end
|
#check_nest ⇒ Object
105
106
107
108
109
|
# File 'lib/review/builder.rb', line 105
def check_nest
if @children && !@children.empty?
app_error "#{@location}: //beginchild of #{@children.reverse.join(',')} misses //endchild"
end
end
|
#check_nested_minicolumn ⇒ Object
613
614
615
616
617
|
# File 'lib/review/builder.rb', line 613
def check_nested_minicolumn
if @doc_status[:minicolumn]
app_error "#{@location}: nested mini-column is not allowed"
end
end
|
#check_printendnotes ⇒ Object
111
112
113
114
115
|
# File 'lib/review/builder.rb', line 111
def check_printendnotes
if @shown_endnotes.nil?
app_error "#{@location}: //endnote is found but //printendnotes is not found."
end
end
|
#compile_inline(s) ⇒ Object
310
311
312
|
# File 'lib/review/builder.rb', line 310
def compile_inline(s)
@compiler.text(s)
end
|
#detab(str, num = nil) ⇒ Object
override TextUtils::detab
761
762
763
764
765
766
767
768
769
|
# File 'lib/review/builder.rb', line 761
def detab(str, num = nil)
if num
super(str, num)
elsif @tabwidth
super(str, @tabwidth)
else
super(str)
end
end
|
#embed(lines, arg = nil) ⇒ Object
531
532
533
534
535
536
537
538
539
|
# File 'lib/review/builder.rb', line 531
def embed(lines, arg = nil)
if arg
builders = arg.gsub(/^\s*\|/, '').gsub(/\|\s*$/, '').gsub(/\s/, '').split(',')
c = target_name
print lines.join("\n") + "\n" if builders.include?(c)
else
print lines.join("\n") + "\n"
end
end
|
#emtable(lines, caption = nil) ⇒ Object
279
280
281
|
# File 'lib/review/builder.rb', line 279
def emtable(lines, caption = nil)
table(lines, nil, caption)
end
|
788
789
790
791
792
793
794
|
# File 'lib/review/builder.rb', line 788
def endchild
if @children.nil? || @children.empty?
app_error "#{@location}: //endchild is shown, but any opened //beginchild doesn't exist"
else
puts "\x01→/#{@children.pop}←\x01"
end
end
|
#endnote(_id, _str) ⇒ Object
292
293
294
|
# File 'lib/review/builder.rb', line 292
def endnote(_id, _str)
@shown_endnotes = nil
end
|
#endnote_begin ⇒ Object
296
297
|
# File 'lib/review/builder.rb', line 296
def endnote_begin
end
|
#endnote_end ⇒ Object
299
300
|
# File 'lib/review/builder.rb', line 299
def endnote_end
end
|
#endnote_item(id) ⇒ Object
302
303
304
|
# File 'lib/review/builder.rb', line 302
def endnote_item(id)
puts "(#{@chapter.endnote(id).number}) #{compile_inline(@chapter.endnote(id).content)}"
end
|
#escape(str) ⇒ Object
771
772
773
|
# File 'lib/review/builder.rb', line 771
def escape(str)
str
end
|
577
578
579
580
581
582
583
584
585
586
|
# File 'lib/review/builder.rb', line 577
def (chap_ref)
m = /\A([\w+-]+)\|(.+)/.match(chap_ref)
if m
ch = @book.contents.detect { |chap| chap.id == m[1] }
raise KeyError unless ch
return [ch, m[2]]
end
[@chapter, chap_ref]
end
|
#firstlinenum(num) ⇒ Object
153
154
155
|
# File 'lib/review/builder.rb', line 153
def firstlinenum(num)
@first_line_num = num.to_i
end
|
#get_chap(chapter = @chapter) ⇒ Object
566
567
568
569
570
571
572
573
574
575
|
# File 'lib/review/builder.rb', line 566
def get_chap(chapter = @chapter)
if @book.config['secnolevel'] > 0 && !chapter.number.nil? && !chapter.number.to_s.empty?
if chapter.is_a?(ReVIEW::Book::Part)
return I18n.t('part_short', chapter.number)
else
return chapter.format_number(nil)
end
end
nil
end
|
#graph(lines, id, command, caption = '') ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
|
# File 'lib/review/builder.rb', line 627
def graph(lines, id, command, caption = '')
c = target_name
dir = File.join(@book.imagedir, c)
FileUtils.mkdir_p(dir)
file = "#{id}.#{image_ext}"
file_path = File.join(dir, file)
content = lines.join("\n") + "\n"
tf = Tempfile.new('review_graph')
tf.puts content
tf.close
begin
file_path = send("graph_#{command}".to_sym, id, file_path, content, tf.path)
ensure
tf.unlink
end
@chapter.image_index.image_finder.add_entry(file_path)
image(lines, id, caption)
end
|
676
677
678
679
|
# File 'lib/review/builder.rb', line 676
def graph_aafigure(id, file_path, _line, tf_path)
system_graph(id, 'aafigure', '-t', image_ext, '-o', file_path, tf_path)
file_path
end
|
#graph_blockdiag(id, file_path, _line, tf_path) ⇒ Object
671
672
673
674
|
# File 'lib/review/builder.rb', line 671
def graph_blockdiag(id, file_path, _line, tf_path)
system_graph(id, 'blockdiag', '-a', '-T', image_ext, '-o', file_path, tf_path)
file_path
end
|
#graph_gnuplot(id, file_path, line, tf_path) ⇒ Object
659
660
661
662
663
664
665
666
667
668
669
|
# File 'lib/review/builder.rb', line 659
def graph_gnuplot(id, file_path, line, tf_path)
File.open(tf_path, 'w') do |tf|
tf.puts <<EOTGNUPLOT
set terminal #{image_ext == 'eps' ? 'postscript eps' : image_ext}
set output "#{file_path}"
#{line}
EOTGNUPLOT
end
system_graph(id, 'gnuplot', tf_path)
file_path
end
|
#graph_graphviz(id, file_path, _line, tf_path) ⇒ Object
654
655
656
657
|
# File 'lib/review/builder.rb', line 654
def graph_graphviz(id, file_path, _line, tf_path)
system_graph(id, 'dot', "-T#{image_ext}", "-o#{file_path}", tf_path)
file_path
end
|
#graph_plantuml(id, file_path, _line, tf_path) ⇒ Object
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
|
# File 'lib/review/builder.rb', line 681
def graph_plantuml(id, file_path, _line, tf_path)
ext = image_ext
if ext == 'pdf'
ext = 'eps'
file_path.sub!(/\.pdf\Z/, '.eps')
end
plant_path = nil
if File.exist?('plantuml.jar')
plant_path = 'plantuml.jar'
elsif File.exist?('/usr/share/plantuml/plantuml.jar')
plant_path = '/usr/share/plantuml/plantuml.jar'
elsif File.exist?('/usr/share/java/plantuml.jar')
plant_path = '/usr/share/java/plantuml.jar'
else
error!('missing plantuml.jar. Please put plantuml.jar at the working folder.')
end
system_graph(id, 'java', '-jar', plant_path, "-t#{ext}", '-charset', 'UTF-8', tf_path)
FileUtils.mv("#{tf_path}.#{ext}", file_path)
file_path
end
|
#handle_metric(str) ⇒ Object
541
542
543
|
# File 'lib/review/builder.rb', line 541
def handle_metric(str)
str
end
|
#highlight? ⇒ Boolean
96
97
98
|
# File 'lib/review/builder.rb', line 96
def highlight?
false
end
|
#image(lines, id, caption, metric = nil) ⇒ Object
192
193
194
195
196
197
198
199
|
# File 'lib/review/builder.rb', line 192
def image(lines, id, caption, metric = nil)
if @chapter.image_bound?(id)
image_image(id, caption, metric)
else
warn "image not bound: #{id}", location: @location if @strict
image_dummy(id, caption, lines)
end
end
|
#image_ext ⇒ Object
702
703
704
|
# File 'lib/review/builder.rb', line 702
def image_ext
raise NotImplementedError
end
|
#in_minicolumn? ⇒ Boolean
619
620
621
|
# File 'lib/review/builder.rb', line 619
def in_minicolumn?
@doc_status[:minicolumn]
end
|
#inline_balloon(arg) ⇒ Object
501
502
503
|
# File 'lib/review/builder.rb', line 501
def inline_balloon(arg)
"← #{arg}"
end
|
#inline_bou(str) ⇒ Object
398
399
400
|
# File 'lib/review/builder.rb', line 398
def inline_bou(str)
text(str)
end
|
#inline_chap(id) ⇒ Object
320
321
322
323
324
|
# File 'lib/review/builder.rb', line 320
def inline_chap(id)
@book.chapter_index.number(id)
rescue KeyError
app_error "unknown chapter: #{id}"
end
|
#inline_chapref(id) ⇒ Object
314
315
316
317
318
|
# File 'lib/review/builder.rb', line 314
def inline_chapref(id)
compile_inline(@book.chapter_index.display_string(id))
rescue KeyError
app_error "unknown chapter: #{id}"
end
|
#inline_column(id) ⇒ Object
475
476
477
478
479
480
481
482
483
484
485
486
487
|
# File 'lib/review/builder.rb', line 475
def inline_column(id)
m = /\A([^|]+)\|(.+)/.match(id)
if m && m[1]
chapter = @book.chapters.detect { |chap| chap.id == m[1] }
end
if chapter
inline_column_chap(chapter, m[2])
else
inline_column_chap(@chapter, id)
end
rescue KeyError
app_error "unknown column: #{id}"
end
|
#inline_column_chap(chapter, id) ⇒ Object
489
490
491
|
# File 'lib/review/builder.rb', line 489
def inline_column_chap(chapter, id)
I18n.t('column', chapter.column(id).caption)
end
|
#inline_embed(args) ⇒ Object
743
744
745
746
747
748
749
750
751
752
753
754
|
# File 'lib/review/builder.rb', line 743
def inline_embed(args)
if matched = args.match(/\|(.*?)\|(.*)/)
builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
if builders.include?(target_name)
matched[2]
else
''
end
else
args
end
end
|
#inline_endnote(id) ⇒ Object
392
393
394
395
396
|
# File 'lib/review/builder.rb', line 392
def inline_endnote(id)
"(#{@chapter.endnote(id).number})"
rescue KeyError
app_error "unknown endnote: #{id}"
end
|
#inline_eq(id) ⇒ Object
375
376
377
378
379
380
381
382
383
384
|
# File 'lib/review/builder.rb', line 375
def inline_eq(id)
chapter, id = (id)
if get_chap(chapter)
%Q(#{I18n.t('equation')}#{I18n.t('format_number', [get_chap(chapter), chapter.equation(id).number])})
else
%Q(#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [chapter.equation(id).number])})
end
rescue KeyError
app_error "unknown equation: #{id}"
end
|
#inline_fn(id) ⇒ Object
386
387
388
389
390
|
# File 'lib/review/builder.rb', line 386
def inline_fn(id)
@chapter.(id).content
rescue KeyError
app_error "unknown footnote: #{id}"
end
|
#inline_hd(id) ⇒ Object
Also known as:
inline_secref
440
441
442
443
444
445
446
447
448
449
450
451
452
|
# File 'lib/review/builder.rb', line 440
def inline_hd(id)
m = /\A([^|]+)\|(.+)/.match(id)
if m && m[1]
chapter = @book.contents.detect { |chap| chap.id == m[1] }
end
if chapter
inline_hd_chap(chapter, m[2])
else
inline_hd_chap(@chapter, id)
end
rescue KeyError
app_error "unknown headline: #{id}"
end
|
#inline_href(arg) ⇒ Object
418
419
420
421
422
423
424
425
|
# File 'lib/review/builder.rb', line 418
def inline_href(arg)
url, label = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/).map(&:lstrip)
url = url.gsub(/\\,/, ',').strip
if label
label = label.gsub(/\\,/, ',').strip
end
compile_href(url, label)
end
|
#inline_img(id) ⇒ Object
343
344
345
346
347
348
349
350
351
352
|
# File 'lib/review/builder.rb', line 343
def inline_img(id)
chapter, id = (id)
if get_chap(chapter)
%Q(#{I18n.t('image')}#{I18n.t('format_number', [get_chap(chapter), chapter.image(id).number])})
else
%Q(#{I18n.t('image')}#{I18n.t('format_number_without_chapter', [chapter.image(id).number])})
end
rescue KeyError
app_error "unknown image: #{id}"
end
|
#inline_imgref(id) ⇒ Object
354
355
356
357
358
359
360
361
362
|
# File 'lib/review/builder.rb', line 354
def inline_imgref(id)
img = inline_img(id)
if @chapter.image(id).caption
"#{img}#{I18n.t('image_quote', @chapter.image(id).caption)}"
else
img
end
end
|
#inline_include(file_name) ⇒ Object
706
707
708
|
# File 'lib/review/builder.rb', line 706
def inline_include(file_name)
compile_inline(File.read(file_name, mode: 'rt:BOM|utf-8').chomp)
end
|
#inline_kw(arg) ⇒ Object
413
414
415
416
|
# File 'lib/review/builder.rb', line 413
def inline_kw(arg)
word, alt = *arg.split(',', 2)
compile_kw(word, alt)
end
|
#inline_list(id) ⇒ Object
332
333
334
335
336
337
338
339
340
341
|
# File 'lib/review/builder.rb', line 332
def inline_list(id)
chapter, id = (id)
if get_chap(chapter)
%Q(#{I18n.t('list')}#{I18n.t('format_number', [get_chap(chapter), chapter.list(id).number])})
else
%Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [chapter.list(id).number])})
end
rescue KeyError
app_error "unknown list: #{id}"
end
|
493
494
495
|
# File 'lib/review/builder.rb', line 493
def (id)
"[link:#{id}]"
end
|
#inline_raw(args) ⇒ Object
729
730
731
732
733
734
735
736
737
738
739
740
741
|
# File 'lib/review/builder.rb', line 729
def inline_raw(args)
if matched = args.match(/\|(.*?)\|(.*)/)
builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
c = self.class.to_s.gsub('ReVIEW::', '').gsub('Builder', '').downcase
if builders.include?(c)
matched[2].gsub('\\n', "\n")
else
''
end
else
args.gsub('\\n', "\n")
end
end
|
#inline_ruby(arg) ⇒ Object
402
403
404
405
406
407
408
409
410
411
|
# File 'lib/review/builder.rb', line 402
def inline_ruby(arg)
base, *ruby = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/)
if base
base = base.gsub(/\\,/, ',').strip
end
if ruby
ruby = ruby.join(',').gsub(/\\,/, ',').strip
end
compile_ruby(base, ruby)
end
|
#inline_sec(id) ⇒ Object
456
457
458
459
460
461
462
463
464
465
466
|
# File 'lib/review/builder.rb', line 456
def inline_sec(id)
chapter, id = (id)
n = chapter.headline_index.number(id)
if n.present? && chapter.number && over_secnolevel?(n)
n
else
app_error "the target headline doesn't have a number: #{id}"
end
rescue KeyError
app_error "unknown headline: #{id}"
end
|
#inline_sectitle(id) ⇒ Object
468
469
470
471
472
473
|
# File 'lib/review/builder.rb', line 468
def inline_sectitle(id)
chapter, id = (id)
compile_inline(chapter.headline(id).caption)
rescue KeyError
app_error "unknown headline: #{id}"
end
|
#inline_table(id) ⇒ Object
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/review/builder.rb', line 364
def inline_table(id)
chapter, id = (id)
if get_chap(chapter)
%Q(#{I18n.t('table')}#{I18n.t('format_number', [get_chap(chapter), chapter.table(id).number])})
else
%Q(#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [chapter.table(id).number])})
end
rescue KeyError
app_error "unknown table: #{id}"
end
|
#inline_tcy(arg) ⇒ Object
497
498
499
|
# File 'lib/review/builder.rb', line 497
def inline_tcy(arg)
"#{arg}[rotate 90 degree]"
end
|
#inline_title(id) ⇒ Object
326
327
328
329
330
|
# File 'lib/review/builder.rb', line 326
def inline_title(id)
compile_inline(@book.chapter_index.title(id))
rescue KeyError
app_error "unknown chapter: #{id}"
end
|
#inline_w(s) ⇒ Object
505
506
507
508
509
510
511
512
513
|
# File 'lib/review/builder.rb', line 505
def inline_w(s)
translated = @dictionary[s]
if translated
escape(translated)
else
warn "word not bound: #{s}", location: @location
escape("[missing word: #{s}]")
end
end
|
#inline_wb(s) ⇒ Object
515
516
517
|
# File 'lib/review/builder.rb', line 515
def inline_wb(s)
inline_b(@dictionary[s] || "[missing word: #{s}]")
end
|
157
158
159
160
161
162
163
164
|
# File 'lib/review/builder.rb', line 157
def line_num
return 1 unless @first_line_num
line_n = @first_line_num
@first_line_num = nil
line_n
end
|
#list(lines, id, caption, lang = nil) ⇒ Object
166
167
168
169
170
171
172
173
174
|
# File 'lib/review/builder.rb', line 166
def list(lines, id, caption, lang = nil)
begin
(id, caption, lang) if caption_top?('list')
list_body(id, lines, lang)
(id, caption, lang) unless caption_top?('list')
rescue KeyError
app_error "no such list: #{id}"
end
end
|
#listnum(lines, id, caption, lang = nil) ⇒ Object
176
177
178
179
180
181
182
183
184
|
# File 'lib/review/builder.rb', line 176
def listnum(lines, id, caption, lang = nil)
begin
(id, caption, lang) if caption_top?('list')
listnum_body(lines, lang)
(id, caption, lang) unless caption_top?('list')
rescue KeyError
app_error "no such list: #{id}"
end
end
|
#load_words(file) ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/review/builder.rb', line 136
def load_words(file)
if File.exist?(file) && /\.csv\Z/i.match?(file)
CSV.foreach(file) do |row|
@dictionary[row[0]] = row[1]
end
end
end
|
#minicolumn_block_name?(name) ⇒ Boolean
623
624
625
|
# File 'lib/review/builder.rb', line 623
def minicolumn_block_name?(name)
CAPTION_TITLES.include?(name)
end
|
#over_secnolevel?(n) ⇒ Boolean
756
757
758
|
# File 'lib/review/builder.rb', line 756
def over_secnolevel?(n)
@book.config['secnolevel'] >= n.to_s.split('.').size
end
|
#parse_metric(type, metric) ⇒ Object
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
# File 'lib/review/builder.rb', line 549
def parse_metric(type, metric)
return '' if metric.blank?
params = metric.split(/,\s*/)
results = []
params.each do |param|
if /\A.+?::/.match?(param)
next unless /\A#{type}::/.match?(param)
param.sub!(/\A#{type}::/, '')
end
param2 = handle_metric(param)
results.push(param2)
end
result_metric(results)
end
|
#parse_table_rows(lines) ⇒ Object
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/review/builder.rb', line 233
def parse_table_rows(lines)
sepidx = nil
rows = []
lines.each_with_index do |line, idx|
if /\A[=-]{12}/ =~ line || /\A[={}-]{12}/ =~ line
sepidx ||= idx
next
end
rows.push(line.strip.split(table_row_separator_regexp).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
app_error 'no rows in the table' if rows.empty?
[sepidx, rows]
end
|
#post_paragraph ⇒ Object
31
32
33
|
# File 'lib/review/builder.rb', line 31
def post_paragraph
nil
end
|
#pre_paragraph ⇒ Object
27
28
29
|
# File 'lib/review/builder.rb', line 27
def pre_paragraph
nil
end
|
#previous_list_type ⇒ Object
775
776
777
|
# File 'lib/review/builder.rb', line 775
def previous_list_type
@compiler.previous_list_type
end
|
#print(*s) ⇒ Object
124
125
126
|
# File 'lib/review/builder.rb', line 124
def print(*s)
@output.print(*s)
end
|
#printendnotes ⇒ Object
283
284
285
286
287
288
289
290
|
# File 'lib/review/builder.rb', line 283
def printendnotes
@shown_endnotes = true
endnote_begin
@chapter.endnotes.each do |en|
endnote_item(en.id)
end
endnote_end
end
|
128
129
130
|
# File 'lib/review/builder.rb', line 128
def puts(*s)
@output.puts(*s)
end
|
519
520
521
522
523
524
525
526
527
528
529
|
# File 'lib/review/builder.rb', line 519
def raw(str)
if matched = str.match(/\|(.*?)\|(.*)/)
builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
c = target_name
if builders.include?(c)
print matched[2].gsub('\\n', "\n")
end
else
print str.gsub('\\n', "\n")
end
end
|
#result ⇒ Object
Also known as:
raw_result
117
118
119
120
|
# File 'lib/review/builder.rb', line 117
def result
check_printendnotes
solve_nest(@output.string)
end
|
#result_metric(array) ⇒ Object
545
546
547
|
# File 'lib/review/builder.rb', line 545
def result_metric(array)
array.join(',')
end
|
#solve_nest(s) ⇒ Object
100
101
102
103
|
# File 'lib/review/builder.rb', line 100
def solve_nest(s)
check_nest
s.gsub(/\x01→.+?←\x01/, '')
end
|
#source(lines, caption = nil, lang = nil) ⇒ Object
186
187
188
189
190
|
# File 'lib/review/builder.rb', line 186
def source(lines, caption = nil, lang = nil)
(caption) if caption_top?('list')
source_body(lines, lang)
(caption) unless caption_top?('list')
end
|
#system_graph(id, *args) ⇒ Object
649
650
651
652
|
# File 'lib/review/builder.rb', line 649
def system_graph(id, *args)
@logger.info args.join(' ')
Kernel.system(*args) or @logger.error("failed to run command for id #{id}: #{args.join(' ')}")
end
|
#table(lines, id = nil, caption = nil) ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/review/builder.rb', line 201
def table(lines, id = nil, caption = nil)
sepidx, rows = parse_table_rows(lines)
begin
if caption_top?('table') && caption.present?
(id, caption)
end
table_begin(rows.first.size)
table_rows(sepidx, rows)
table_end
if !caption_top?('table') && caption.present?
(id, caption)
end
rescue KeyError
app_error "no such table: #{id}"
end
end
|
#table_row_separator_regexp ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/review/builder.rb', line 218
def table_row_separator_regexp
case @book.config['table_row_separator']
when 'tabs'
Regexp.new('\t+')
when 'singletab'
Regexp.new('\t')
when 'spaces'
Regexp.new('\s+')
when 'verticalbar'
Regexp.new('\s*\\' + escape('|') + '\s*')
else
app_error "Unknown value for 'table_row_separator', shold be: tabs, singletab, spaces, verticalbar"
end
end
|
#table_rows(sepidx, rows) ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
# File 'lib/review/builder.rb', line 249
def table_rows(sepidx, rows)
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
end
|
#target_name ⇒ Object
132
133
134
|
# File 'lib/review/builder.rb', line 132
def target_name
self.class.to_s.gsub(/ReVIEW::/, '').gsub(/Builder/, '').downcase
end
|
#text(str) ⇒ Object
427
428
429
|
# File 'lib/review/builder.rb', line 427
def text(str)
str
end
|
#tsize(str) ⇒ Object
717
718
719
720
721
722
723
724
725
726
727
|
# File 'lib/review/builder.rb', line 717
def tsize(str)
if matched = str.match(/\A\|(.*?)\|(.*)/)
builders = matched[1].split(',').map { |i| i.gsub(/\s/, '') }
c = self.class.to_s.gsub('ReVIEW::', '').gsub('Builder', '').downcase
if builders.include?(c)
@tsize = matched[2]
end
else
@tsize = str
end
end
|
#ul_item_begin(lines) ⇒ Object
710
711
712
|
# File 'lib/review/builder.rb', line 710
def ul_item_begin(lines)
ul_item(lines)
end
|
#ul_item_end ⇒ Object
714
715
|
# File 'lib/review/builder.rb', line 714
def ul_item_end
end
|