review 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-tex.yml +31 -0
- data/.github/workflows/ruby-win.yml +3 -3
- data/.github/workflows/ruby.yml +1 -1
- data/.rubocop.yml +15 -7
- data/NEWS.ja.md +108 -0
- data/NEWS.md +108 -0
- data/README.md +7 -6
- data/Rakefile +7 -2
- data/bin/review +2 -4
- data/bin/review-catalog-converter +3 -3
- data/bin/review-check +6 -8
- data/bin/review-checkdep +1 -4
- data/bin/review-compile +2 -5
- data/bin/review-epub2html +1 -4
- data/bin/review-epubmaker +3 -4
- data/bin/review-idgxmlmaker +1 -3
- data/bin/review-index +11 -5
- data/bin/review-init +1 -4
- data/bin/review-pdfmaker +1 -3
- data/bin/review-preproc +2 -4
- data/bin/review-textmaker +1 -3
- data/bin/review-update +1 -4
- data/bin/review-validate +3 -3
- data/bin/review-vol +1 -4
- data/bin/review-webmaker +1 -3
- data/doc/config.yml.sample +21 -5
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +21 -10
- data/doc/format.md +21 -10
- data/doc/quickstart.ja.md +11 -1
- data/doc/quickstart.md +11 -2
- data/lib/review.rb +1 -1
- data/lib/review/book/base.rb +4 -0
- data/lib/review/book/book_unit.rb +3 -0
- data/lib/review/book/chapter.rb +3 -0
- data/lib/review/book/index.rb +1 -0
- data/lib/review/book/volume.rb +1 -0
- data/lib/review/builder.rb +8 -1
- data/lib/review/call_hook.rb +20 -0
- data/lib/review/catalog.rb +1 -0
- data/lib/review/compiler.rb +27 -10
- data/lib/review/configure.rb +64 -7
- data/lib/review/epubmaker.rb +93 -96
- data/lib/review/epubmaker/content.rb +113 -0
- data/lib/review/epubmaker/epubcommon.rb +372 -0
- data/lib/review/epubmaker/epubv2.rb +178 -0
- data/lib/review/epubmaker/epubv3.rb +231 -0
- data/lib/review/epubmaker/producer.rb +168 -0
- data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
- data/lib/review/epubmaker/zip_exporter.rb +84 -0
- data/lib/review/exception.rb +6 -0
- data/lib/review/htmlbuilder.rb +36 -49
- data/lib/review/htmlutils.rb +1 -1
- data/lib/review/i18n.rb +1 -0
- data/lib/review/idgxmlbuilder.rb +33 -30
- data/lib/review/idgxmlmaker.rb +3 -1
- data/lib/review/img_math.rb +245 -0
- data/lib/review/index_builder.rb +1 -0
- data/lib/review/init.rb +4 -4
- data/lib/review/latexbox.rb +58 -0
- data/lib/review/latexbuilder.rb +30 -19
- data/lib/review/latexutils.rb +9 -1
- data/lib/review/lineinput.rb +112 -2
- data/lib/review/logger.rb +41 -2
- data/lib/review/makerhelper.rb +2 -205
- data/lib/review/markdownbuilder.rb +32 -1
- data/lib/review/pdfmaker.rb +31 -29
- data/lib/review/plaintextbuilder.rb +9 -1
- data/lib/review/preprocessor.rb +12 -6
- data/lib/review/rstbuilder.rb +1 -1
- data/lib/review/sec_counter.rb +1 -0
- data/lib/review/template.rb +6 -0
- data/lib/review/textmaker.rb +11 -7
- data/lib/review/textutils.rb +2 -10
- data/lib/review/tocprinter.rb +85 -68
- data/lib/review/topbuilder.rb +18 -11
- data/lib/review/update.rb +5 -6
- data/lib/review/version.rb +1 -1
- data/lib/review/volumeprinter.rb +4 -5
- data/lib/review/webmaker.rb +18 -13
- data/lib/review/webtocprinter.rb +10 -9
- data/lib/review/yamlloader.rb +2 -1
- data/review.gemspec +5 -3
- data/samples/sample-book/src/config-epub2.yml +1 -1
- data/samples/sample-book/src/config.yml +1 -1
- data/samples/sample-book/src/lib/tasks/review.rake +17 -1
- data/samples/syntax-book/ch01.re +1 -1
- data/samples/syntax-book/ch02.re +21 -6
- data/samples/syntax-book/ch03.re +1 -1
- data/samples/syntax-book/images/img3-2.png +0 -0
- data/templates/html/_colophon.html.erb +23 -0
- data/templates/html/_colophon_history.html.erb +9 -0
- data/templates/html/_cover.html.erb +10 -0
- data/templates/html/_part_body.html.erb +6 -0
- data/templates/html/_titlepage.html.erb +20 -0
- data/templates/html/layout-html5.html.erb +6 -0
- data/templates/html/layout-xhtml1.html.erb +6 -0
- data/templates/latex/config.erb +8 -0
- data/templates/latex/review-jlreq/review-base.sty +4 -5
- data/templates/latex/review-jlreq/review-jlreq.cls +10 -2
- data/templates/latex/review-jlreq/review-style.sty +6 -1
- data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
- data/templates/latex/review-jsbook/review-base.sty +5 -7
- data/templates/latex/review-jsbook/review-jsbook.cls +10 -2
- data/templates/latex/review-jsbook/review-style.sty +6 -1
- data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
- data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
- data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
- data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
- data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
- data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
- data/templates/web/html/layout-html5.html.erb +6 -5
- data/templates/web/html/layout-xhtml1.html.erb +6 -0
- data/test/assets/header_listener.html +35 -0
- data/test/assets/img_math/img1.png +0 -0
- data/test/assets/img_math/img2.png +0 -0
- data/test/assets/img_math/img3.png +0 -0
- data/test/assets/syntax_book_index_detail.txt +58 -0
- data/test/assets/test_template.tex +4 -1
- data/test/assets/test_template_backmatter.tex +4 -1
- data/test/run_test.rb +1 -1
- data/test/test_book_chapter.rb +2 -2
- data/test/test_catalog_converter_cmd.rb +1 -1
- data/test/test_epub3maker.rb +168 -124
- data/test/test_epubmaker.rb +243 -131
- data/test/test_epubmaker_cmd.rb +2 -2
- data/test/test_helper.rb +5 -4
- data/test/test_htmlbuilder.rb +64 -6
- data/test/test_idgxmlbuilder.rb +13 -0
- data/test/test_idgxmlmaker_cmd.rb +7 -3
- data/test/test_img_math.rb +111 -0
- data/test/test_indexbuilder.rb +5 -5
- data/test/test_latexbuilder.rb +107 -4
- data/test/test_lineinput.rb +20 -93
- data/test/test_markdownbuilder.rb +29 -0
- data/test/test_pdfmaker.rb +71 -0
- data/test/test_pdfmaker_cmd.rb +2 -2
- data/test/test_plaintextbuilder.rb +10 -18
- data/test/test_reviewheaderlistener.rb +49 -0
- data/test/test_template.rb +12 -2
- data/test/test_textmaker_cmd.rb +5 -1
- data/test/test_tocprinter.rb +46 -0
- data/test/test_topbuilder.rb +6 -1
- data/test/test_update.rb +34 -34
- data/test/test_zip_exporter.rb +5 -6
- metadata +91 -17
- data/lib/epubmaker.rb +0 -23
- data/lib/epubmaker/content.rb +0 -111
- data/lib/epubmaker/epubcommon.rb +0 -449
- data/lib/epubmaker/epubv2.rb +0 -142
- data/lib/epubmaker/epubv3.rb +0 -235
- data/lib/epubmaker/producer.rb +0 -375
- data/lib/epubmaker/zip_exporter.rb +0 -81
- data/lib/lineinput.rb +0 -155
data/lib/review/index_builder.rb
CHANGED
data/lib/review/init.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2018-
|
2
|
+
# Copyright (c) 2018-2021 Masanori Kado, Masayoshi Takahashi, Kenshi Muto
|
3
3
|
#
|
4
4
|
# This program is free software.
|
5
5
|
# You can distribute or modify this program under the terms of
|
@@ -209,9 +209,9 @@ EOT
|
|
209
209
|
FileUtils.cp(Dir.glob(File.join(tdir, '*.*')), texmacrodir)
|
210
210
|
|
211
211
|
if @template == 'review-jsbook'
|
212
|
-
# provide jsbook from vendor/. current version is
|
212
|
+
# provide jsbook from vendor/. current version is 2020/10/09
|
213
213
|
FileUtils.cp(File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls'))
|
214
|
-
# provide gentombow from vendor/. current version is
|
214
|
+
# provide gentombow from vendor/. current version is 2019/07/21 v0.9k
|
215
215
|
FileUtils.cp(File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty'))
|
216
216
|
end
|
217
217
|
end
|
@@ -286,7 +286,7 @@ EOS
|
|
286
286
|
begin
|
287
287
|
Zip::File.open(filename) do |zip|
|
288
288
|
zip.each do |entry|
|
289
|
-
fname = entry.name.
|
289
|
+
fname = entry.name.tr('\\', '/')
|
290
290
|
if fname =~ /__MACOSX/ || fname =~ /\.DS_Store/
|
291
291
|
next
|
292
292
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (c) 2021 Kenshi Muto
|
2
|
+
#
|
3
|
+
# This program is free software.
|
4
|
+
# You can distribute or modify this program under the terms of
|
5
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
6
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
7
|
+
#
|
8
|
+
require 'review/logger'
|
9
|
+
module ReVIEW
|
10
|
+
class LaTeXBox
|
11
|
+
def initialize
|
12
|
+
@logger = ReVIEW.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def tcbox(config)
|
16
|
+
ret = ''
|
17
|
+
|
18
|
+
%w[column note memo tip info warning important caution notice].each do |name|
|
19
|
+
if config['pdfmaker'].nil? || config['pdfmaker']['boxsetting'].nil? ||
|
20
|
+
config['pdfmaker']['boxsetting'][name].nil? ||
|
21
|
+
config['pdfmaker']['boxsetting'][name]['style'].nil?
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
options = '[]'
|
26
|
+
options_with_caption = '[]'
|
27
|
+
if config['pdfmaker']['boxsetting'][name]['options']
|
28
|
+
options = "[#{config['pdfmaker']['boxsetting'][name]['options']}]"
|
29
|
+
options_with_caption = options
|
30
|
+
end
|
31
|
+
|
32
|
+
if config['pdfmaker']['boxsetting'][name]['options_with_caption']
|
33
|
+
options_with_caption = "[#{config['pdfmaker']['boxsetting'][name]['options_with_caption']}]"
|
34
|
+
end
|
35
|
+
|
36
|
+
ret << <<EOT
|
37
|
+
\\renewenvironment{review#{name}}[1][]{%
|
38
|
+
\\csdef{rv@tmp@withcaption}{true}
|
39
|
+
\\notblank{##1}{
|
40
|
+
\\begin{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@caption}{##1}#{options_with_caption}
|
41
|
+
}{
|
42
|
+
\\csundef{rv@tmp@withcaption}
|
43
|
+
\\begin{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@nocaption}#{options}
|
44
|
+
}
|
45
|
+
}{
|
46
|
+
\\ifcsdef{rv@tmp@withcaption}{
|
47
|
+
\\end{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@caption}
|
48
|
+
}{
|
49
|
+
\\end{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@nocaption}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
EOT
|
53
|
+
end
|
54
|
+
|
55
|
+
ret
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/review/latexbuilder.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Copyright (c) 2002-2007 Minero Aoki
|
2
2
|
# 2008-2009 Minero Aoki, Kenshi Muto
|
3
|
-
# 2010-
|
3
|
+
# 2010-2021 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
|
4
4
|
#
|
5
5
|
# This program is free software.
|
6
6
|
# You can distribute or modify this program under the terms of
|
@@ -51,6 +51,7 @@ module ReVIEW
|
|
51
51
|
@index_db = load_idxdb(@book.config['pdfmaker']['makeindex_dic'])
|
52
52
|
end
|
53
53
|
return true unless @book.config['pdfmaker']['makeindex_mecab']
|
54
|
+
|
54
55
|
begin
|
55
56
|
begin
|
56
57
|
require 'MeCab'
|
@@ -180,10 +181,10 @@ module ReVIEW
|
|
180
181
|
end
|
181
182
|
|
182
183
|
def nodisp_begin(level, _label, caption)
|
183
|
-
if @output.pos
|
184
|
-
blank
|
185
|
-
else
|
184
|
+
if @output.pos == 0
|
186
185
|
puts macro('clearpage')
|
186
|
+
else
|
187
|
+
blank
|
187
188
|
end
|
188
189
|
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
|
189
190
|
# FIXME: headings
|
@@ -334,6 +335,7 @@ module ReVIEW
|
|
334
335
|
blank
|
335
336
|
puts '\begin{enumerate}'
|
336
337
|
return true unless @ol_num
|
338
|
+
|
337
339
|
puts "\\setcounter{enumi}{#{@ol_num - 1}}"
|
338
340
|
@ol_num = nil
|
339
341
|
end
|
@@ -557,6 +559,7 @@ module ReVIEW
|
|
557
559
|
if @book.config['pdfmaker']['use_original_image_size'] && s.empty? && !metric.present?
|
558
560
|
return ' ' # pass empty to \reviewincludegraphics
|
559
561
|
end
|
562
|
+
|
560
563
|
s
|
561
564
|
end
|
562
565
|
|
@@ -564,6 +567,7 @@ module ReVIEW
|
|
564
567
|
if @book.config['pdfmaker']['image_scale2width'] && str =~ /\Ascale=([\d.]+)\Z/
|
565
568
|
return "width=#{$1}\\maxwidth"
|
566
569
|
end
|
570
|
+
|
567
571
|
str
|
568
572
|
end
|
569
573
|
|
@@ -571,13 +575,13 @@ module ReVIEW
|
|
571
575
|
array.join(',')
|
572
576
|
end
|
573
577
|
|
574
|
-
def image_image(id, caption, metric)
|
578
|
+
def image_image(id, caption = '', metric = nil)
|
575
579
|
captionstr = nil
|
576
580
|
@doc_status[:caption] = true
|
577
581
|
if @book.config.check_version('2', exception: false)
|
578
|
-
captionstr = macro('caption', compile_inline(caption)) + "\n"
|
582
|
+
captionstr = macro('caption', compile_inline(caption)) + "\n"
|
579
583
|
else
|
580
|
-
captionstr = macro('reviewimagecaption', compile_inline(caption)) + "\n"
|
584
|
+
captionstr = macro('reviewimagecaption', compile_inline(caption)) + "\n"
|
581
585
|
end
|
582
586
|
captionstr << macro('label', image_label(id))
|
583
587
|
@doc_status[:caption] = nil
|
@@ -586,7 +590,7 @@ module ReVIEW
|
|
586
590
|
# image is always bound here
|
587
591
|
puts "\\begin{reviewimage}%%#{id}"
|
588
592
|
|
589
|
-
if caption_top?('image')
|
593
|
+
if caption_top?('image')
|
590
594
|
puts captionstr
|
591
595
|
end
|
592
596
|
|
@@ -601,7 +605,7 @@ module ReVIEW
|
|
601
605
|
puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}"
|
602
606
|
end
|
603
607
|
|
604
|
-
|
608
|
+
unless caption_top?('image')
|
605
609
|
puts captionstr
|
606
610
|
end
|
607
611
|
|
@@ -1007,6 +1011,7 @@ module ReVIEW
|
|
1007
1011
|
|
1008
1012
|
def direct(lines, fmt)
|
1009
1013
|
return unless fmt == 'latex'
|
1014
|
+
|
1010
1015
|
lines.each do |line|
|
1011
1016
|
puts line
|
1012
1017
|
end
|
@@ -1014,6 +1019,7 @@ module ReVIEW
|
|
1014
1019
|
|
1015
1020
|
def comment(lines, comment = nil)
|
1016
1021
|
return true unless @book.config['draft']
|
1022
|
+
|
1017
1023
|
lines ||= []
|
1018
1024
|
unless comment.blank?
|
1019
1025
|
lines.unshift(escape(comment))
|
@@ -1045,7 +1051,7 @@ module ReVIEW
|
|
1045
1051
|
def inline_chapref(id)
|
1046
1052
|
title = super
|
1047
1053
|
if @book.config['chapterlink']
|
1048
|
-
"\\
|
1054
|
+
"\\reviewchapref{#{title}}{chap:#{id}}"
|
1049
1055
|
else
|
1050
1056
|
title
|
1051
1057
|
end
|
@@ -1056,7 +1062,7 @@ module ReVIEW
|
|
1056
1062
|
|
1057
1063
|
def inline_chap(id)
|
1058
1064
|
if @book.config['chapterlink']
|
1059
|
-
"\\
|
1065
|
+
"\\reviewchapref{#{@book.chapter_index.number(id)}}{chap:#{id}}"
|
1060
1066
|
else
|
1061
1067
|
@book.chapter_index.number(id)
|
1062
1068
|
end
|
@@ -1068,7 +1074,7 @@ module ReVIEW
|
|
1068
1074
|
def inline_title(id)
|
1069
1075
|
title = super
|
1070
1076
|
if @book.config['chapterlink']
|
1071
|
-
"\\
|
1077
|
+
"\\reviewchapref{#{title}}{chap:#{id}}"
|
1072
1078
|
else
|
1073
1079
|
title
|
1074
1080
|
end
|
@@ -1231,6 +1237,10 @@ module ReVIEW
|
|
1231
1237
|
end
|
1232
1238
|
end
|
1233
1239
|
|
1240
|
+
def inline_ins(str)
|
1241
|
+
macro('reviewinsert', escape(str))
|
1242
|
+
end
|
1243
|
+
|
1234
1244
|
def inline_del(str)
|
1235
1245
|
macro('reviewstrike', escape(str))
|
1236
1246
|
end
|
@@ -1263,7 +1273,7 @@ module ReVIEW
|
|
1263
1273
|
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
|
1264
1274
|
end
|
1265
1275
|
if @book.config['chapterlink']
|
1266
|
-
anchor = n.
|
1276
|
+
anchor = n.tr('.', '-')
|
1267
1277
|
macro('reviewsecref', str, sec_label(anchor))
|
1268
1278
|
else
|
1269
1279
|
str
|
@@ -1361,22 +1371,23 @@ module ReVIEW
|
|
1361
1371
|
end
|
1362
1372
|
|
1363
1373
|
def index(str)
|
1374
|
+
# XXX: mendex/upmendex specific
|
1364
1375
|
sa = str.split('<<>>')
|
1365
1376
|
|
1366
1377
|
sa.map! do |item|
|
1367
1378
|
if @index_db[item]
|
1368
|
-
escape_index(
|
1379
|
+
escape_mendex_key(escape_index(@index_db[item])) + '@' + escape_mendex_display(escape_index(escape(item)))
|
1369
1380
|
else
|
1370
1381
|
if item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil?
|
1371
|
-
esc_item = escape_index(escape(item))
|
1372
|
-
if esc_item
|
1373
|
-
"#{escape_index(item)}@#{esc_item}"
|
1374
|
-
else
|
1382
|
+
esc_item = escape_mendex_display(escape_index(escape(item)))
|
1383
|
+
if esc_item == item
|
1375
1384
|
esc_item
|
1385
|
+
else
|
1386
|
+
"#{escape_mendex_key(escape_index(item))}@#{esc_item}"
|
1376
1387
|
end
|
1377
1388
|
else
|
1378
1389
|
yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)
|
1379
|
-
escape_index(
|
1390
|
+
escape_mendex_key(escape_index(yomi)) + '@' + escape_mendex_display(escape_index(escape(item)))
|
1380
1391
|
end
|
1381
1392
|
end
|
1382
1393
|
end
|
data/lib/review/latexutils.rb
CHANGED
@@ -59,7 +59,7 @@ module ReVIEW
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
@metachars_re = /[#{Regexp.escape(@metachars.keys.join(''))}]/u
|
62
|
+
@metachars_re = /[#{Regexp.escape(@metachars.keys.join(''))}]/u # rubocop:disable Style/RedundantArgument
|
63
63
|
|
64
64
|
@metachars_invert = @metachars.invert
|
65
65
|
end
|
@@ -81,6 +81,14 @@ module ReVIEW
|
|
81
81
|
str.gsub(/[@!|"]/) { |s| '"' + s }
|
82
82
|
end
|
83
83
|
|
84
|
+
def escape_mendex_key(str)
|
85
|
+
str.gsub('"|', '|').tr('{', '{').tr('}', '}')
|
86
|
+
end
|
87
|
+
|
88
|
+
def escape_mendex_display(str)
|
89
|
+
str.gsub('\{', '\reviewleftcurlybrace{}').gsub('\}', '\reviewrightcurlybrace{}')
|
90
|
+
end
|
91
|
+
|
84
92
|
def escape_url(str)
|
85
93
|
str.gsub(/[\#%]/) { |s| '\\' + s }
|
86
94
|
end
|
data/lib/review/lineinput.rb
CHANGED
@@ -1,7 +1,33 @@
|
|
1
|
-
|
1
|
+
#
|
2
|
+
# Copyright (c) 2002-2020 Minero Aoki, Masayoshi Takahashi, Kenshi Muto
|
3
|
+
#
|
4
|
+
# This program is free software.
|
5
|
+
# You can distribute/modify this program under the terms of
|
6
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
7
|
+
#
|
8
|
+
require 'review/exception'
|
2
9
|
|
3
10
|
module ReVIEW
|
4
|
-
class LineInput
|
11
|
+
class LineInput
|
12
|
+
INVALID_CHARACTER_PATTERN = /[\x00-\x08\x0b-\x0c\x0e-\x1f]/ # accept 0x09: TAB, 0x0a: LF, 0x0d: CR
|
13
|
+
|
14
|
+
attr_reader :lineno
|
15
|
+
|
16
|
+
def initialize(f)
|
17
|
+
@input = f
|
18
|
+
@buf = []
|
19
|
+
@lineno = 0
|
20
|
+
@eof_p = false
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
"\#<#{self.class} file=#{@input.inspect} line=#{lineno}>"
|
25
|
+
end
|
26
|
+
|
27
|
+
def eof?
|
28
|
+
@eof_p
|
29
|
+
end
|
30
|
+
|
5
31
|
def skip_comment_lines
|
6
32
|
n = 0
|
7
33
|
while line = gets
|
@@ -13,5 +39,89 @@ module ReVIEW
|
|
13
39
|
end
|
14
40
|
n
|
15
41
|
end
|
42
|
+
|
43
|
+
def gets
|
44
|
+
unless @buf.empty?
|
45
|
+
@lineno += 1
|
46
|
+
return @buf.pop
|
47
|
+
end
|
48
|
+
return nil if @eof_p # to avoid ARGF blocking.
|
49
|
+
|
50
|
+
line = @input.gets
|
51
|
+
@eof_p = true unless line
|
52
|
+
@lineno += 1
|
53
|
+
invalid_char = lookup_invalid_char(line)
|
54
|
+
if invalid_char
|
55
|
+
raise SyntaxError, "found invalid control-sequence character (#{sprintf('%#x', invalid_char.codepoints[0])})."
|
56
|
+
end
|
57
|
+
|
58
|
+
line
|
59
|
+
end
|
60
|
+
|
61
|
+
def peek
|
62
|
+
line = gets
|
63
|
+
ungets(line) if line
|
64
|
+
line
|
65
|
+
end
|
66
|
+
|
67
|
+
def next?
|
68
|
+
peek ? true : false
|
69
|
+
end
|
70
|
+
|
71
|
+
def skip_blank_lines
|
72
|
+
n = 0
|
73
|
+
while line = gets
|
74
|
+
unless line.strip.empty?
|
75
|
+
ungets(line)
|
76
|
+
return n
|
77
|
+
end
|
78
|
+
n += 1
|
79
|
+
end
|
80
|
+
n
|
81
|
+
end
|
82
|
+
|
83
|
+
def each
|
84
|
+
while line = gets
|
85
|
+
yield line
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def while_match(re)
|
90
|
+
while line = gets
|
91
|
+
unless re =~ line
|
92
|
+
ungets(line)
|
93
|
+
return
|
94
|
+
end
|
95
|
+
yield line
|
96
|
+
end
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
|
100
|
+
def until_match(re)
|
101
|
+
while line = gets
|
102
|
+
if re =~ line
|
103
|
+
ungets(line)
|
104
|
+
return
|
105
|
+
end
|
106
|
+
yield line
|
107
|
+
end
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def ungets(line)
|
114
|
+
return unless line
|
115
|
+
|
116
|
+
@lineno -= 1
|
117
|
+
@buf.push(line)
|
118
|
+
line
|
119
|
+
end
|
120
|
+
|
121
|
+
def lookup_invalid_char(line)
|
122
|
+
if line =~ INVALID_CHARACTER_PATTERN
|
123
|
+
$&
|
124
|
+
end
|
125
|
+
end
|
16
126
|
end
|
17
127
|
end
|
data/lib/review/logger.rb
CHANGED
@@ -6,10 +6,49 @@ module ReVIEW
|
|
6
6
|
super(io, progname: progname)
|
7
7
|
self.formatter = ->(severity, _datetime, name, msg) { "#{severity} #{name}: #{msg}\n" }
|
8
8
|
end
|
9
|
+
|
10
|
+
def ttylogger?
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def success(_log)
|
15
|
+
# empty (for backward compatibility)
|
16
|
+
end
|
9
17
|
end
|
10
18
|
|
11
|
-
|
12
|
-
|
19
|
+
begin
|
20
|
+
require 'tty-logger'
|
21
|
+
class TTYLogger < ::TTY::Logger
|
22
|
+
def ttylogger?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.logger(level: 'info')
|
31
|
+
if const_defined?(:TTYLogger)
|
32
|
+
@logger ||= TTYLogger.new do |config|
|
33
|
+
config.level = level.to_sym
|
34
|
+
config.handlers = [
|
35
|
+
[:console,
|
36
|
+
{
|
37
|
+
styles: {
|
38
|
+
debug: { label: 'DEBUG' },
|
39
|
+
info: { label: 'INFO', color: :magenta },
|
40
|
+
success: { label: 'SUCCESS' },
|
41
|
+
wait: { label: 'WAIT' },
|
42
|
+
warn: { label: 'WARN' },
|
43
|
+
error: { label: 'ERROR' },
|
44
|
+
fatal: { label: 'FATAL' }
|
45
|
+
}
|
46
|
+
}]
|
47
|
+
]
|
48
|
+
end
|
49
|
+
else
|
50
|
+
@logger ||= ReVIEW::Logger.new($stderr, progname: File.basename($PROGRAM_NAME, '.*'))
|
51
|
+
end
|
13
52
|
end
|
14
53
|
|
15
54
|
def self.logger=(logger)
|