review 3.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -4
- data/.travis.yml +1 -1
- data/NEWS.ja.md +97 -1
- data/NEWS.md +97 -1
- data/bin/review-catalog-converter +1 -1
- data/bin/review-check +5 -5
- data/bin/review-checkdep +1 -1
- data/bin/review-compile +5 -5
- data/bin/review-idgxmlmaker +16 -0
- data/bin/review-index +7 -7
- data/bin/review-preproc +9 -9
- data/bin/review-validate +2 -2
- data/bin/review-vol +5 -5
- data/doc/config.yml.sample +14 -6
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +15 -5
- data/doc/format.md +30 -18
- data/doc/pdfmaker.ja.md +1 -1
- data/doc/pdfmaker.md +1 -1
- data/lib/review/book.rb +1 -1
- data/lib/review/book/base.rb +23 -63
- data/lib/review/book/chapter.rb +18 -3
- data/lib/review/book/compilable.rb +5 -0
- data/lib/review/book/index.rb +26 -65
- data/lib/review/book/index/item.rb +40 -0
- data/lib/review/book/part.rb +22 -2
- data/lib/review/builder.rb +60 -40
- data/lib/review/catalog.rb +12 -15
- data/lib/review/compiler.rb +68 -36
- data/lib/review/configure.rb +10 -7
- data/lib/review/epubmaker.rb +5 -2
- data/lib/review/htmlbuilder.rb +24 -71
- data/lib/review/htmlutils.rb +2 -3
- data/lib/review/i18n.rb +2 -2
- data/lib/review/idgxmlbuilder.rb +101 -55
- data/lib/review/idgxmlmaker.rb +184 -0
- data/lib/review/init-web/finish.html +10 -0
- data/lib/review/init-web/index.html +190 -0
- data/lib/review/init-web/review-layout-design.js +691 -0
- data/lib/review/init.rb +110 -26
- data/lib/review/latexbuilder.rb +76 -54
- data/lib/review/lineinput.rb +1 -1
- data/lib/review/logger.rb +4 -8
- data/lib/review/makerhelper.rb +6 -4
- data/lib/review/markdownbuilder.rb +25 -38
- data/lib/review/md2inaobuilder.rb +3 -5
- data/lib/review/pdfmaker.rb +15 -15
- data/lib/review/plaintextbuilder.rb +67 -76
- data/lib/review/preprocessor.rb +13 -13
- data/lib/review/rstbuilder.rb +31 -31
- data/lib/review/textmaker.rb +13 -3
- data/lib/review/textutils.rb +77 -2
- data/lib/review/tocparser.rb +17 -17
- data/lib/review/tocprinter.rb +8 -8
- data/lib/review/topbuilder.rb +76 -57
- data/lib/review/update.rb +16 -16
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +2 -2
- data/lib/review/yamlloader.rb +3 -0
- data/review.gemspec +4 -3
- data/samples/sample-book/README.md +7 -2
- data/samples/sample-book/src/.gitignore +153 -0
- data/samples/sample-book/src/config-jlreq.yml +6 -0
- data/samples/sample-book/src/lib/tasks/review.rake +20 -9
- data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
- data/samples/syntax-book/ch03.re +3 -6
- data/samples/syntax-book/config-jlreq.yml +5 -0
- data/samples/syntax-book/lib/tasks/review.rake +7 -7
- data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
- data/templates/latex/config.erb +6 -0
- data/templates/latex/layout.tex.erb +1 -0
- data/templates/latex/review-jlreq/review-base.sty +93 -31
- data/templates/latex/review-jlreq/review-jlreq.cls +6 -0
- data/templates/latex/review-jlreq/review-style.sty +3 -0
- data/templates/latex/review-jsbook/README.md +39 -0
- data/templates/latex/review-jsbook/review-base.sty +65 -10
- data/templates/latex/review-jsbook/review-jsbook.cls +4 -0
- data/templates/latex/review-jsbook/review-style.sty +4 -1
- data/test/assets/test_template.tex +11 -3
- data/test/assets/test_template_backmatter.tex +11 -3
- data/test/test_book.rb +65 -19
- data/test/test_catalog.rb +18 -42
- data/test/test_catalog_converter_cmd.rb +1 -1
- data/test/test_epubmaker_cmd.rb +2 -2
- data/test/test_helper.rb +1 -1
- data/test/test_htmlbuilder.rb +144 -55
- data/test/test_i18n.rb +25 -25
- data/test/test_idgxmlbuilder.rb +60 -18
- data/test/test_image_finder.rb +6 -6
- data/test/test_latexbuilder.rb +128 -24
- data/test/test_latexbuilder_v2.rb +23 -23
- data/test/test_logger.rb +14 -1
- data/test/test_makerhelper.rb +3 -3
- data/test/test_markdownbuilder.rb +45 -4
- data/test/test_md2inaobuilder.rb +12 -2
- data/test/test_pdfmaker.rb +1 -1
- data/test/test_pdfmaker_cmd.rb +1 -1
- data/test/test_plaintextbuilder.rb +31 -6
- data/test/test_rstbuilder.rb +33 -4
- data/test/test_textutils.rb +109 -2
- data/test/test_topbuilder.rb +35 -7
- data/test/test_update.rb +17 -8
- data/test/test_yamlloader.rb +13 -0
- metadata +26 -2
data/bin/review-validate
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
# Copyright (c) 2010-
|
|
2
|
+
# Copyright (c) 2010-2019 Kenshi Muto
|
|
3
3
|
#
|
|
4
4
|
# This program is free software
|
|
5
5
|
# You can distribute or modify this program under the terms of
|
|
@@ -48,7 +48,7 @@ ARGF.each do |line|
|
|
|
48
48
|
@logger.warn "#{ln}: found '*' without the head space. Is it correct?"
|
|
49
49
|
end
|
|
50
50
|
elsif line =~ /\A\s+(\d+\.)\s+/ && line =~ /\A\s+\*\s+/
|
|
51
|
-
unless
|
|
51
|
+
unless %w[list emlist listnum emlistnum cmd image table].include?(block)
|
|
52
52
|
@logger.warn "#{ln}: found itemized list or numbered list in #{block}. Is it correct?"
|
|
53
53
|
end
|
|
54
54
|
elsif block == 'table'
|
data/bin/review-vol
CHANGED
|
@@ -69,23 +69,23 @@ def main
|
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
puts '============================='
|
|
72
|
-
print_volume
|
|
72
|
+
print_volume(book.volume) # puts "Total #{book.volume}"
|
|
73
73
|
rescue ReVIEW::ApplicationError, Errno::ENOENT => e
|
|
74
74
|
raise if $DEBUG
|
|
75
|
-
@logger.error
|
|
75
|
+
@logger.error e.message
|
|
76
76
|
exit 1
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def print_chapter_volume(chap)
|
|
80
80
|
vol = chap.volume
|
|
81
81
|
title = chap.title
|
|
82
|
-
printf
|
|
82
|
+
printf("%s %3dKB %6dC %5dL %3dP %s %-s\n",
|
|
83
83
|
chapnumstr(chap.number), vol.kbytes, vol.chars, vol.lines, vol.page,
|
|
84
|
-
"#{chap.name} ".ljust(25, '.'), title
|
|
84
|
+
"#{chap.name} ".ljust(25, '.'), title)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def print_volume(vol)
|
|
88
|
-
printf
|
|
88
|
+
printf(" %3dKB %6dC %5dL %3dP\n", vol.kbytes, vol.chars, vol.lines, vol.page)
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def chapnumstr(n)
|
data/doc/config.yml.sample
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# このファイルはUTF-8エンコーディングで記述してください。
|
|
6
6
|
|
|
7
7
|
# この設定ファイルでサポートするRe:VIEWのバージョン番号。
|
|
8
|
-
review_version:
|
|
8
|
+
review_version: 4.0
|
|
9
9
|
|
|
10
10
|
# ほかの設定ファイルの継承を指定できる。同じパラメータに異なる値がある場合は、
|
|
11
11
|
# 呼び出し元の値が優先される。
|
|
@@ -111,7 +111,7 @@ toclevel: 3
|
|
|
111
111
|
secnolevel: 2
|
|
112
112
|
|
|
113
113
|
# 本文中に目次ページを作成するか。省略した場合はnull (作成しない)
|
|
114
|
-
|
|
114
|
+
toc: true
|
|
115
115
|
|
|
116
116
|
# EPUB2標準の目次(NCX)以外に物理目次ファイルを作成するか。省略した場合はnull (作成しない)
|
|
117
117
|
# ePUB3においてはこの設定によらず必ず作成される
|
|
@@ -184,7 +184,7 @@ secnolevel: 2
|
|
|
184
184
|
# 各数字の意味は、順にリストの行数、リストの1行字数、テキストの行数、テキストの1行字数、1kバイトごとのページ数
|
|
185
185
|
# page_metric: [40,80,40,80,2]
|
|
186
186
|
|
|
187
|
-
# EPUB
|
|
187
|
+
# EPUB・Web、およびテキスト生成時における数式の画像化指定
|
|
188
188
|
# TeXの数式を画像化するか。省略した場合はnull (作成しない)
|
|
189
189
|
# imgmath: true
|
|
190
190
|
|
|
@@ -211,14 +211,20 @@ secnolevel: 2
|
|
|
211
211
|
# pdfcrop_cmd: "pdfcrop --hires %i %o"
|
|
212
212
|
# PDFから画像化するコマンドのコマンドライン。プレースホルダは
|
|
213
213
|
# %i: 入力ファイル、%o: 出力ファイル、%O: 出力ファイルから拡張子を除いたもの
|
|
214
|
-
# %p:
|
|
215
|
-
# pdfcrop_pixelize_cmd: "pdftocairo
|
|
214
|
+
# %p: 対象ページ番号、%t: フォーマット
|
|
215
|
+
# pdfcrop_pixelize_cmd: "pdftocairo -%t -r 90 -f %p -l %p -singlefile %i %O"
|
|
216
216
|
# pdfcrop_pixelize_cmdが複数ページの処理に対応していない場合に単ページ化するか
|
|
217
217
|
# extract_singlepage: null
|
|
218
218
|
# extract_singlepageがtrueの場合に単ページ化するコマンドのコマンドライン
|
|
219
219
|
# pdfextract_cmd: "pdfjam -q --outfile %o %i %p"
|
|
220
220
|
# converterにdvipngを指定したときのdvipngコマンドのコマンドライン
|
|
221
221
|
# dvipng_cmd: "dvipng -T tight -z 9 -p %p -l %p -o %o %i"
|
|
222
|
+
#
|
|
223
|
+
# PDFで保存したいときにはたとえば以下のようにする
|
|
224
|
+
# format: pdf
|
|
225
|
+
# extract_singlepage: true
|
|
226
|
+
# pdfextract_cmd: "pdftk A=%i cat A%p output %o"
|
|
227
|
+
# pdfcrop_pixelize_cmd: "mv %i %o"
|
|
222
228
|
|
|
223
229
|
# EPUBにおけるページ送りの送り方向、page-progression-directionの値("ltr"|"rtl"|"default")
|
|
224
230
|
# direction: "ltr"
|
|
@@ -322,7 +328,7 @@ epubmaker:
|
|
|
322
328
|
# texcommand: "uplatex"
|
|
323
329
|
#
|
|
324
330
|
# LaTeXのコマンドに渡すオプションを指定する
|
|
325
|
-
# texoptions: "-interaction=nonstopmode -file-line-error"
|
|
331
|
+
# texoptions: "-interaction=nonstopmode -file-line-error -halt-on-error"
|
|
326
332
|
#
|
|
327
333
|
# LaTeX用のdvi変換コマンドを指定する(dvipdfmx)
|
|
328
334
|
# dvicommand: "dvipdfmx"
|
|
@@ -388,4 +394,6 @@ pdfmaker:
|
|
|
388
394
|
# makeindex_mecab_opts: "-Oyomi"
|
|
389
395
|
# 奥付を作成するか。trueを指定するとデフォルトの奥付、ファイル名を指定するとそれがcolophon.htmlとしてコピーされる
|
|
390
396
|
colophon: true
|
|
397
|
+
# 表紙挿入時に表紙のページ番号名を「cover」とし、偶数ページ扱いにして大扉前に白ページが入るのを防ぐ。デフォルトはtrue
|
|
398
|
+
# use_cover_nombre: true
|
|
391
399
|
# pdfmaker:階層を使うものはここまで
|
data/doc/format.ja.md
CHANGED
|
@@ -505,14 +505,13 @@ complexmatrixという識別子に基づく画像ファイルが貼り込まれ
|
|
|
505
505
|
|
|
506
506
|
本文中のインライン命令「`@<fn>{site}`」は脚注番号に置換され、「本書のサポートサイト……」という文は実際の脚注に変換されます。
|
|
507
507
|
|
|
508
|
-
注意: TeX PDF
|
|
508
|
+
注意: TeX PDF において、コラムの中で脚注を利用する場合、`//footnote` 行はコラムの終わり(`==[/column]` など)の後ろに記述することをお勧めします。Re:VIEW の標準提供のコラム表現では問題ありませんが、サードパーティのコラムの実装によってはおかしな採番表現になることがあります。
|
|
509
509
|
|
|
510
510
|
### footnotetext オプション
|
|
511
|
+
TeX PDF において、コラム以外の `//note` などの囲み記事の中で「`@<fn>{~}`」を使うには、`footnotetext` オプションを使う必要があります。
|
|
511
512
|
|
|
512
513
|
`footnotetext` オプションを使うには、`config.yml` ファイルに`footnotetext: true` を追加します。
|
|
513
514
|
|
|
514
|
-
これで PDF のコラムや表のなかでも脚注が使えるようになります。
|
|
515
|
-
|
|
516
515
|
ただし、通常の脚注(footnote)ではなく、footnotemark と footnotetext を使うため、本文と脚注が別ページに分かれる可能性があるなど、いろいろな制約があります。また、採番が別々になるため、footnote と footnotemark/footnotetext を両立させることはできません。
|
|
517
516
|
|
|
518
517
|
## 参考文献の定義
|
|
@@ -638,8 +637,8 @@ imgmath_options:
|
|
|
638
637
|
pdfcrop_cmd: "pdfcrop --hires %i %o"
|
|
639
638
|
# PDFから画像化するコマンドのコマンドライン。プレースホルダは
|
|
640
639
|
# %i: 入力ファイル、%o: 出力ファイル、%O: 出力ファイルから拡張子を除いたもの
|
|
641
|
-
# %p:
|
|
642
|
-
pdfcrop_pixelize_cmd: "pdftocairo
|
|
640
|
+
# %p: 対象ページ番号、%t: フォーマット
|
|
641
|
+
pdfcrop_pixelize_cmd: "pdftocairo -%t -r 90 -f %p -l %p -singlefile %i %O"
|
|
643
642
|
# pdfcrop_pixelize_cmdが複数ページの処理に対応していない場合に単ページ化するか
|
|
644
643
|
extract_singlepage: null
|
|
645
644
|
# 単ページ化するコマンドのコマンドライン
|
|
@@ -673,6 +672,17 @@ imgmath_options:
|
|
|
673
672
|
pdfcrop_pixelize_cmd: "sips -s format png --out %o %i"
|
|
674
673
|
```
|
|
675
674
|
|
|
675
|
+
textmaker 向けに PDF 形式の数式ファイルを作成したいときには、たとえば以下のように設定します(ページの抽出には pdftk を利用)。
|
|
676
|
+
|
|
677
|
+
```
|
|
678
|
+
imgmath: true
|
|
679
|
+
imgmath_options:
|
|
680
|
+
format: pdf
|
|
681
|
+
extract_singlepage: true
|
|
682
|
+
pdfextract_cmd: "pdftk A=%i cat A%p output %o"
|
|
683
|
+
pdfcrop_pixelize_cmd: "mv %i %o"
|
|
684
|
+
```
|
|
685
|
+
|
|
676
686
|
Re:VIEW 2 以前の dvipng の設定に合わせるには、次のようにします。
|
|
677
687
|
|
|
678
688
|
```
|
data/doc/format.md
CHANGED
|
@@ -98,11 +98,11 @@ Nested itemize is like ` **`, ` ***`.
|
|
|
98
98
|
Usage:
|
|
99
99
|
|
|
100
100
|
```
|
|
101
|
-
* 1st item
|
|
102
|
-
** nested 1st item
|
|
103
|
-
* 2nd item
|
|
104
|
-
** nested 2nd item
|
|
105
|
-
* 3rd item
|
|
101
|
+
* 1st item
|
|
102
|
+
** nested 1st item
|
|
103
|
+
* 2nd item
|
|
104
|
+
** nested 2nd item
|
|
105
|
+
* 3rd item
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
In itemize, you must write one more space character at line head.
|
|
@@ -118,34 +118,34 @@ They aren't nested.
|
|
|
118
118
|
Usage:
|
|
119
119
|
|
|
120
120
|
```
|
|
121
|
-
1. 1st condition
|
|
122
|
-
2. 2nd condition
|
|
123
|
-
3. 3rd condition
|
|
121
|
+
1. 1st condition
|
|
122
|
+
2. 2nd condition
|
|
123
|
+
3. 3rd condition
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
The value of Number is ignored.
|
|
127
127
|
|
|
128
128
|
```
|
|
129
|
-
1. 1st condition
|
|
130
|
-
1. 2nd condition
|
|
131
|
-
1. 3rd condition
|
|
129
|
+
1. 1st condition
|
|
130
|
+
1. 2nd condition
|
|
131
|
+
1. 3rd condition
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
You must write one more space character at line head like itemize.
|
|
135
135
|
|
|
136
136
|
## Definition List
|
|
137
137
|
|
|
138
|
-
Definition list (dl in HTML)
|
|
138
|
+
Definition list (dl in HTML) uses ` : ` and indented lines.
|
|
139
139
|
|
|
140
140
|
Usage:
|
|
141
141
|
|
|
142
142
|
```review
|
|
143
|
-
: Alpha
|
|
143
|
+
: Alpha
|
|
144
144
|
RISC CPU made by DEC.
|
|
145
|
-
: POWER
|
|
145
|
+
: POWER
|
|
146
146
|
RSIC CPU made by IBM and Motolora.
|
|
147
147
|
POWER PC is delivered from this.
|
|
148
|
-
: SPARC
|
|
148
|
+
: SPARC
|
|
149
149
|
RISC CPU made by SUN.
|
|
150
150
|
```
|
|
151
151
|
|
|
@@ -546,9 +546,10 @@ You should get and install it before reading the book.
|
|
|
546
546
|
`@<fn>{site}` in source are replaced by footnote marks, and the phrase "support site of .."
|
|
547
547
|
is in footnotes.
|
|
548
548
|
|
|
549
|
-
Note that
|
|
549
|
+
Note that in LATEXBuilder, it is highly recommended to place `//footnote` after the end line of column (`==[/column]`) to avoid problems when using third party's style file.
|
|
550
550
|
|
|
551
551
|
### `footnotetext` option
|
|
552
|
+
Note that in LATEXBuilder, you should use `footnotetext` option to use `@<fn>{...}` in `//note` or other short column blocks.
|
|
552
553
|
|
|
553
554
|
By adding `footnotetext:true` in config.yml, you can use footnote in tables and short notes.
|
|
554
555
|
|
|
@@ -682,8 +683,8 @@ imgmath_options:
|
|
|
682
683
|
pdfcrop_cmd: "pdfcrop --hires %i %o"
|
|
683
684
|
# imaging command.
|
|
684
685
|
# %i: filename for input %o: filename for output %O: filename for output without the extension
|
|
685
|
-
# %p: page number
|
|
686
|
-
pdfcrop_pixelize_cmd: "pdftocairo
|
|
686
|
+
# %p: page number, %t: format
|
|
687
|
+
pdfcrop_pixelize_cmd: "pdftocairo -%t -r 90 -f %p -l %p -singlefile %i %O"
|
|
687
688
|
# whether to generate a single PDF page for pdfcrop_pixelize_cmd.
|
|
688
689
|
extract_singlepage: null
|
|
689
690
|
# command line to generate a single PDF page file.
|
|
@@ -717,6 +718,17 @@ imgmath_options:
|
|
|
717
718
|
pdfcrop_pixelize_cmd: "sips -s format png --out %o %i"
|
|
718
719
|
```
|
|
719
720
|
|
|
721
|
+
To create PDF math images:
|
|
722
|
+
|
|
723
|
+
```
|
|
724
|
+
imgmath: true
|
|
725
|
+
imgmath_options:
|
|
726
|
+
format: pdf
|
|
727
|
+
extract_singlepage: true
|
|
728
|
+
pdfextract_cmd: "pdftk A=%i cat A%p output %o"
|
|
729
|
+
pdfcrop_pixelize_cmd: "mv %i %o"
|
|
730
|
+
```
|
|
731
|
+
|
|
720
732
|
To set the same setting as Re:VIEW 2:
|
|
721
733
|
|
|
722
734
|
```
|
data/doc/pdfmaker.ja.md
CHANGED
|
@@ -121,7 +121,7 @@ LaTeX コンパイラコマンドおよびオプションについて、Re:VIEW
|
|
|
121
121
|
|
|
122
122
|
```yaml
|
|
123
123
|
texcommand: uplatex
|
|
124
|
-
texoptions: "-interaction=nonstopmode -file-line-error"
|
|
124
|
+
texoptions: "-interaction=nonstopmode -file-line-error -halt-on-error"
|
|
125
125
|
texdocumentclass: ["jsbook", "uplatex,oneside"]
|
|
126
126
|
dvicommand: dvipdfmx
|
|
127
127
|
dvioptions: "-d 5"
|
data/doc/pdfmaker.md
CHANGED
|
@@ -100,7 +100,7 @@ Default settings of Re:VIEW is below:
|
|
|
100
100
|
|
|
101
101
|
```yaml
|
|
102
102
|
texcommand: uplatex
|
|
103
|
-
texoptions: "-interaction=nonstopmode -file-line-error"
|
|
103
|
+
texoptions: "-interaction=nonstopmode -file-line-error -halt-on-error"
|
|
104
104
|
texdocumentclass: ["review-jsbook", "uplatex,twoside"]
|
|
105
105
|
dvicommand: dvipdfmx
|
|
106
106
|
dvioptions: "-d 5"
|
data/lib/review/book.rb
CHANGED
data/lib/review/book/base.rb
CHANGED
|
@@ -29,7 +29,6 @@ module ReVIEW
|
|
|
29
29
|
@chapter_index = nil
|
|
30
30
|
@config = ReVIEW::Configure.values
|
|
31
31
|
@catalog = nil
|
|
32
|
-
@read_part = nil
|
|
33
32
|
@warn_old_files = {} # XXX for checking CHAPS, PREDEF, POSTDEF
|
|
34
33
|
@basedir_seen = {}
|
|
35
34
|
update_rubyenv
|
|
@@ -189,8 +188,8 @@ module ReVIEW
|
|
|
189
188
|
return @catalog if @catalog.present?
|
|
190
189
|
|
|
191
190
|
catalogfile_path = filename_join(@basedir, config['catalogfile'])
|
|
192
|
-
if File.file?
|
|
193
|
-
@catalog = File.open(catalogfile_path, '
|
|
191
|
+
if File.file?(catalogfile_path)
|
|
192
|
+
@catalog = File.open(catalogfile_path, 'rt:BOM|utf-8') { |f| Catalog.new(f) }
|
|
194
193
|
end
|
|
195
194
|
if @catalog
|
|
196
195
|
@catalog.validate!(@config, basedir)
|
|
@@ -202,7 +201,7 @@ module ReVIEW
|
|
|
202
201
|
if catalog
|
|
203
202
|
catalog.chaps
|
|
204
203
|
else
|
|
205
|
-
read_file(config['chapter_file'])
|
|
204
|
+
read_file(config['chapter_file']).split("\n")
|
|
206
205
|
end
|
|
207
206
|
end
|
|
208
207
|
|
|
@@ -210,7 +209,7 @@ module ReVIEW
|
|
|
210
209
|
if catalog
|
|
211
210
|
catalog.predef
|
|
212
211
|
else
|
|
213
|
-
read_file(config['predef_file'])
|
|
212
|
+
read_file(config['predef_file']).split("\n")
|
|
214
213
|
end
|
|
215
214
|
end
|
|
216
215
|
|
|
@@ -218,7 +217,7 @@ module ReVIEW
|
|
|
218
217
|
if catalog
|
|
219
218
|
catalog.appendix
|
|
220
219
|
else
|
|
221
|
-
read_file(config['postdef_file']) # for backward compatibility
|
|
220
|
+
read_file(config['postdef_file']).split("\n") # for backward compatibility
|
|
222
221
|
end
|
|
223
222
|
end
|
|
224
223
|
|
|
@@ -226,17 +225,15 @@ module ReVIEW
|
|
|
226
225
|
if catalog
|
|
227
226
|
catalog.postdef
|
|
228
227
|
else
|
|
229
|
-
|
|
228
|
+
[]
|
|
230
229
|
end
|
|
231
230
|
end
|
|
232
231
|
|
|
233
232
|
def read_part
|
|
234
|
-
return @read_part if @read_part
|
|
235
|
-
|
|
236
233
|
if catalog
|
|
237
|
-
|
|
234
|
+
catalog.parts
|
|
238
235
|
else
|
|
239
|
-
|
|
236
|
+
File.read(File.join(@basedir, config['part_file'])).split("\n")
|
|
240
237
|
end
|
|
241
238
|
end
|
|
242
239
|
|
|
@@ -258,13 +255,13 @@ module ReVIEW
|
|
|
258
255
|
|
|
259
256
|
def prefaces
|
|
260
257
|
if catalog
|
|
261
|
-
return mkpart_from_namelist(catalog.predef
|
|
258
|
+
return Part.mkpart_from_namelist(self, catalog.predef)
|
|
262
259
|
end
|
|
263
260
|
|
|
264
261
|
begin
|
|
265
262
|
predef_file = filename_join(@basedir, config['predef_file'])
|
|
266
263
|
if File.file?(predef_file)
|
|
267
|
-
mkpart_from_namelistfile(predef_file)
|
|
264
|
+
Part.mkpart_from_namelistfile(self, predef_file)
|
|
268
265
|
end
|
|
269
266
|
rescue FileNotFound => e
|
|
270
267
|
raise FileNotFound, "preface #{e.message}"
|
|
@@ -273,15 +270,15 @@ module ReVIEW
|
|
|
273
270
|
|
|
274
271
|
def appendix
|
|
275
272
|
if catalog
|
|
276
|
-
names = catalog.appendix
|
|
277
|
-
chaps = names.each_with_index.map { |
|
|
278
|
-
return mkpart(chaps)
|
|
273
|
+
names = catalog.appendix
|
|
274
|
+
chaps = names.each_with_index.map { |name, number| Chapter.mkchap_ifexist(self, name, number + 1) }.compact
|
|
275
|
+
return Part.mkpart(chaps)
|
|
279
276
|
end
|
|
280
277
|
|
|
281
278
|
begin
|
|
282
279
|
postdef_file = filename_join(@basedir, config['postdef_file'])
|
|
283
280
|
if File.file?(postdef_file)
|
|
284
|
-
mkpart_from_namelistfile(postdef_file)
|
|
281
|
+
Part.mkpart_from_namelistfile(self, postdef_file)
|
|
285
282
|
end
|
|
286
283
|
rescue FileNotFound => e
|
|
287
284
|
raise FileNotFound, "postscript #{e.message}"
|
|
@@ -290,7 +287,7 @@ module ReVIEW
|
|
|
290
287
|
|
|
291
288
|
def postscripts
|
|
292
289
|
if catalog
|
|
293
|
-
mkpart_from_namelist(catalog.postdef
|
|
290
|
+
Part.mkpart_from_namelist(self, catalog.postdef)
|
|
294
291
|
end
|
|
295
292
|
end
|
|
296
293
|
|
|
@@ -300,13 +297,13 @@ module ReVIEW
|
|
|
300
297
|
list = parse_chapters
|
|
301
298
|
# NOTE: keep this = style to work this logic.
|
|
302
299
|
if pre = prefaces
|
|
303
|
-
list.unshift
|
|
300
|
+
list.unshift(pre)
|
|
304
301
|
end
|
|
305
302
|
if app = appendix
|
|
306
|
-
list.push
|
|
303
|
+
list.push(app)
|
|
307
304
|
end
|
|
308
305
|
if post = postscripts
|
|
309
|
-
list.push
|
|
306
|
+
list.push(post)
|
|
310
307
|
end
|
|
311
308
|
list
|
|
312
309
|
end
|
|
@@ -324,7 +321,7 @@ module ReVIEW
|
|
|
324
321
|
chap = Chapter.new(self, num += 1, chap, File.join(contentdir, chap))
|
|
325
322
|
chap
|
|
326
323
|
end
|
|
327
|
-
Part.new(self, part += 1, chaps, read_part
|
|
324
|
+
Part.new(self, part += 1, chaps, read_part[part - 1])
|
|
328
325
|
else
|
|
329
326
|
chap = Chapter.new(self, num += 1, entry, File.join(contentdir, entry))
|
|
330
327
|
if chap.number
|
|
@@ -337,12 +334,11 @@ module ReVIEW
|
|
|
337
334
|
end
|
|
338
335
|
end
|
|
339
336
|
|
|
340
|
-
chap = read_chaps.
|
|
341
|
-
strip.lines.map(&:strip).join("\n").split(/\n{2,}/).
|
|
337
|
+
chap = read_chaps.map(&:strip).join("\n").split(/\n{2,}/).
|
|
342
338
|
map do |part_chunk|
|
|
343
339
|
chaps = part_chunk.split.map { |chapid| Chapter.new(self, num += 1, chapid, File.join(contentdir, chapid)) }
|
|
344
|
-
if part_exist? && read_part.
|
|
345
|
-
Part.new(self, part += 1, chaps, read_part
|
|
340
|
+
if part_exist? && read_part.size > part
|
|
341
|
+
Part.new(self, part += 1, chaps, read_part[part - 1])
|
|
346
342
|
else
|
|
347
343
|
Part.new(self, nil, chaps)
|
|
348
344
|
end
|
|
@@ -350,42 +346,6 @@ module ReVIEW
|
|
|
350
346
|
chap
|
|
351
347
|
end
|
|
352
348
|
|
|
353
|
-
def mkpart_from_namelistfile(path)
|
|
354
|
-
chaps = []
|
|
355
|
-
File.read(path, mode: 'r:BOM|utf-8').split.each_with_index do |name, idx|
|
|
356
|
-
if path =~ /PREDEF/
|
|
357
|
-
chaps << mkchap(name)
|
|
358
|
-
else
|
|
359
|
-
chaps << mkchap(name, idx + 1)
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
mkpart(chaps)
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
def mkpart_from_namelist(names)
|
|
366
|
-
mkpart(names.map { |n| mkchap_ifexist(n) }.compact)
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
def mkpart(chaps)
|
|
370
|
-
chaps.empty? ? nil : Part.new(self, nil, chaps)
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
def mkchap(name, number = nil)
|
|
374
|
-
name += ext if File.extname(name).empty?
|
|
375
|
-
path = File.join(contentdir, name)
|
|
376
|
-
raise FileNotFound, "file not exist: #{path}" unless File.file?(path)
|
|
377
|
-
Chapter.new(self, number, name, path)
|
|
378
|
-
end
|
|
379
|
-
|
|
380
|
-
def mkchap_ifexist(name, idx = nil)
|
|
381
|
-
name += ext if File.extname(name).empty?
|
|
382
|
-
path = File.join(contentdir, name)
|
|
383
|
-
if File.file?(path)
|
|
384
|
-
idx += 1 if idx
|
|
385
|
-
Chapter.new(self, idx, name, path)
|
|
386
|
-
end
|
|
387
|
-
end
|
|
388
|
-
|
|
389
349
|
def read_file(filename)
|
|
390
350
|
unless @warn_old_files[filename]
|
|
391
351
|
@warn_old_files[filename] = true
|
|
@@ -394,7 +354,7 @@ module ReVIEW
|
|
|
394
354
|
end
|
|
395
355
|
end
|
|
396
356
|
res = ''
|
|
397
|
-
File.open(filename_join(@basedir, filename), '
|
|
357
|
+
File.open(filename_join(@basedir, filename), 'rt:BOM|utf-8') do |f|
|
|
398
358
|
f.each_line do |line|
|
|
399
359
|
next if /\A#/ =~ line
|
|
400
360
|
line.gsub!(/#.*\Z/, '')
|