review 3.1.0 → 5.0.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-win.yml +45 -0
- data/.github/workflows/ruby.yml +27 -0
- data/.rubocop.yml +161 -34
- data/.travis.yml +16 -15
- data/Dockerfile +21 -5
- data/NEWS.ja.md +394 -0
- data/NEWS.md +395 -1
- data/README.md +10 -7
- data/appveyor.yml +1 -3
- data/bin/review-catalog-converter +5 -5
- data/bin/review-check +10 -12
- data/bin/review-checkdep +2 -2
- data/bin/review-compile +17 -23
- data/bin/review-epubmaker +3 -35
- data/bin/review-idgxmlmaker +16 -0
- data/bin/review-index +2 -89
- data/bin/review-preproc +13 -13
- data/bin/review-validate +4 -4
- data/bin/review-vol +4 -78
- data/doc/config.yml.sample +47 -12
- data/doc/config.yml.sample-simple +3 -2
- data/doc/format.ja.md +120 -17
- data/doc/format.md +119 -27
- data/doc/makeindex.ja.md +2 -2
- data/doc/pdfmaker.ja.md +43 -1
- data/doc/pdfmaker.md +42 -1
- data/doc/quickstart.ja.md +45 -25
- data/doc/quickstart.md +37 -16
- data/lib/epubmaker/content.rb +3 -2
- data/lib/epubmaker/epubcommon.rb +34 -27
- data/lib/epubmaker/epubv2.rb +5 -6
- data/lib/epubmaker/epubv3.rb +21 -18
- data/lib/epubmaker/producer.rb +2 -1
- data/lib/review/book.rb +2 -2
- data/lib/review/book/base.rb +91 -96
- data/lib/review/book/bib.rb +21 -0
- data/lib/review/book/book_unit.rb +155 -0
- data/lib/review/book/chapter.rb +48 -29
- data/lib/review/book/index.rb +46 -240
- data/lib/review/book/index/item.rb +46 -0
- data/lib/review/book/page_metric.rb +7 -7
- data/lib/review/book/part.rb +45 -10
- data/lib/review/book/volume.rb +4 -5
- data/lib/review/builder.rb +172 -56
- data/lib/review/catalog.rb +14 -17
- data/lib/review/compiler.rb +219 -121
- data/lib/review/configure.rb +39 -7
- data/lib/review/converter.rb +1 -1
- data/lib/review/epub2html.rb +43 -5
- data/lib/review/epubmaker.rb +69 -27
- data/lib/review/extentions/string.rb +0 -4
- data/lib/review/htmlbuilder.rb +112 -101
- data/lib/review/htmlutils.rb +9 -13
- data/lib/review/i18n.rb +3 -3
- data/lib/review/idgxmlbuilder.rb +202 -78
- data/lib/review/idgxmlmaker.rb +186 -0
- data/lib/review/index_builder.rb +653 -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 +129 -46
- data/lib/review/latexbuilder.rb +255 -92
- data/lib/review/lineinput.rb +1 -1
- data/lib/review/location.rb +32 -0
- data/lib/review/logger.rb +4 -8
- data/lib/review/makerhelper.rb +35 -5
- data/lib/review/markdownbuilder.rb +50 -38
- data/lib/review/md2inaobuilder.rb +3 -5
- data/lib/review/pdfmaker.rb +60 -57
- data/lib/review/plaintextbuilder.rb +154 -87
- data/lib/review/preprocessor.rb +20 -42
- data/lib/review/rstbuilder.rb +57 -38
- data/lib/review/sec_counter.rb +13 -0
- data/lib/review/textmaker.rb +23 -15
- data/lib/review/textutils.rb +76 -2
- data/lib/review/tocprinter.rb +230 -102
- data/lib/review/topbuilder.rb +139 -60
- data/lib/review/update.rb +24 -24
- data/lib/review/version.rb +1 -1
- data/lib/review/volumeprinter.rb +98 -0
- data/lib/review/webmaker.rb +20 -24
- data/lib/review/webtocprinter.rb +38 -35
- data/lib/review/yamlloader.rb +26 -16
- data/review.gemspec +6 -4
- data/samples/sample-book/README.md +7 -2
- data/samples/sample-book/src/.gitignore +154 -0
- data/samples/sample-book/src/config-ebook.yml +4 -0
- data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
- data/samples/sample-book/src/config-jlreq.yml +6 -0
- data/samples/sample-book/src/config.yml +2 -2
- data/samples/sample-book/src/lib/tasks/review.rake +29 -14
- data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
- data/samples/syntax-book/Gemfile +1 -1
- data/samples/syntax-book/ch01.re +4 -2
- data/samples/syntax-book/ch02.re +8 -16
- data/samples/syntax-book/ch03.re +3 -6
- data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
- data/samples/syntax-book/config-jlreq.yml +5 -0
- data/samples/syntax-book/config-print.yml +3 -0
- data/samples/syntax-book/config.yml +1 -1
- data/samples/syntax-book/lib/tasks/review.rake +30 -15
- data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
- data/templates/latex/config.erb +39 -25
- data/templates/latex/layout.tex.erb +1 -0
- data/templates/latex/review-jlreq/README.md +3 -1
- data/templates/latex/review-jlreq/review-base.sty +161 -50
- data/templates/latex/review-jlreq/review-jlreq.cls +21 -22
- data/templates/latex/review-jlreq/review-style.sty +4 -1
- data/templates/latex/review-jsbook/README.md +46 -5
- data/templates/latex/review-jsbook/review-base.sty +123 -35
- data/templates/latex/review-jsbook/review-jsbook.cls +10 -4
- data/templates/latex/review-jsbook/review-style.sty +5 -2
- data/templates/opf/epubv3.opf.erb +1 -0
- data/templates/web/html/layout-html5.html.erb +3 -3
- data/test/assets/test_template.tex +19 -7
- data/test/assets/test_template_backmatter.tex +19 -7
- data/test/book_test_helper.rb +11 -5
- data/test/test_book.rb +124 -79
- data/test/test_book_chapter.rb +97 -54
- data/test/test_book_part.rb +3 -3
- data/test/test_builder.rb +38 -13
- data/test/test_catalog.rb +24 -42
- data/test/test_catalog_converter_cmd.rb +1 -1
- data/test/test_converter.rb +1 -0
- data/test/test_epub3maker.rb +2 -2
- data/test/test_epubmaker.rb +8 -0
- data/test/test_epubmaker_cmd.rb +14 -7
- data/test/test_helper.rb +18 -7
- data/test/test_htmlbuilder.rb +1491 -205
- data/test/test_htmlutils.rb +0 -12
- data/test/test_i18n.rb +37 -37
- data/test/test_idgxmlbuilder.rb +744 -42
- data/test/test_idgxmlmaker_cmd.rb +46 -0
- data/test/test_image_finder.rb +52 -70
- data/test/test_index.rb +94 -44
- data/test/test_indexbuilder.rb +52 -0
- data/test/test_latexbuilder.rb +1784 -161
- data/test/test_latexbuilder_v2.rb +671 -102
- data/test/test_logger.rb +17 -4
- data/test/test_makerhelper.rb +2 -14
- data/test/test_markdownbuilder.rb +137 -16
- data/test/test_md2inaobuilder.rb +32 -9
- data/test/test_pdfmaker.rb +30 -12
- data/test/test_pdfmaker_cmd.rb +100 -6
- data/test/test_plaintextbuilder.rb +791 -30
- data/test/test_preprocessor.rb +2 -16
- data/test/test_review_ext.rb +2 -1
- data/test/test_rstbuilder.rb +274 -27
- data/test/test_sec_counter.rb +156 -0
- data/test/test_textmaker_cmd.rb +54 -0
- data/test/test_textutils.rb +109 -2
- data/test/test_topbuilder.rb +724 -34
- data/test/test_update.rb +20 -11
- data/test/test_webtocprinter.rb +75 -43
- data/test/test_yamlloader.rb +13 -0
- data/vendor/gentombow/LICENSE +1 -1
- data/vendor/gentombow/Makefile +0 -1
- data/vendor/gentombow/bounddvi-en.pdf +0 -0
- data/vendor/gentombow/bounddvi-en.tex +1 -0
- data/vendor/gentombow/bounddvi.pdf +0 -0
- data/vendor/gentombow/bounddvi.sty +30 -7
- data/vendor/gentombow/bounddvi.tex +1 -0
- data/vendor/gentombow/create_archive.sh +1 -0
- data/vendor/gentombow/gentombow-ja.pdf +0 -0
- data/vendor/gentombow/gentombow-ja.tex +9 -0
- data/vendor/gentombow/gentombow.pdf +0 -0
- data/vendor/gentombow/gentombow.sty +32 -10
- data/vendor/gentombow/gentombow.tex +8 -0
- data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
- data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
- data/vendor/jsclasses/LICENSE +1 -1
- data/vendor/jsclasses/Makefile +3 -2
- data/vendor/jsclasses/create_archive.sh +5 -5
- data/vendor/jsclasses/jis/Makefile +3 -2
- data/vendor/jsclasses/jis/jsarticle.cls +74 -31
- data/vendor/jsclasses/jis/jsbook.cls +74 -31
- data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
- data/vendor/jsclasses/jis/jsclasses.ins +15 -5
- data/vendor/jsclasses/jis/jslogo.dtx +4 -4
- data/vendor/jsclasses/jis/jslogo.ins +9 -0
- data/vendor/jsclasses/jis/jslogo.sty +4 -16
- data/vendor/jsclasses/jis/jspf.cls +73 -30
- data/vendor/jsclasses/jis/jsreport.cls +74 -31
- data/vendor/jsclasses/jis/jsverb.ins +9 -0
- data/vendor/jsclasses/jis/jsverb.sty +1 -13
- data/vendor/jsclasses/jis/kiyou.cls +74 -31
- data/vendor/jsclasses/jis/minijs.sty +65 -22
- data/vendor/jsclasses/jis/okumacro.dtx +4 -5
- data/vendor/jsclasses/jis/okumacro.ins +9 -0
- data/vendor/jsclasses/jis/okumacro.sty +4 -17
- data/vendor/jsclasses/jis/okuverb.ins +9 -0
- data/vendor/jsclasses/jis/okuverb.sty +1 -13
- data/vendor/jsclasses/jis/winjis.sty +23 -19
- data/vendor/jsclasses/jsarticle.cls +74 -31
- data/vendor/jsclasses/jsbook.cls +74 -31
- data/vendor/jsclasses/jsclasses.dtx +176 -36
- data/vendor/jsclasses/jsclasses.ins +15 -5
- data/vendor/jsclasses/jsclasses.pdf +0 -0
- data/vendor/jsclasses/jslogo.dtx +4 -4
- data/vendor/jsclasses/jslogo.ins +9 -0
- data/vendor/jsclasses/jslogo.pdf +0 -0
- data/vendor/jsclasses/jslogo.sty +4 -16
- data/vendor/jsclasses/jspf.cls +73 -30
- data/vendor/jsclasses/jsreport.cls +74 -31
- data/vendor/jsclasses/jsverb.ins +9 -0
- data/vendor/jsclasses/jsverb.pdf +0 -0
- data/vendor/jsclasses/jsverb.sty +1 -13
- data/vendor/jsclasses/kiyou.cls +74 -31
- data/vendor/jsclasses/minijs.sty +68 -22
- data/vendor/jsclasses/okumacro.dtx +4 -5
- data/vendor/jsclasses/okumacro.ins +9 -0
- data/vendor/jsclasses/okumacro.pdf +0 -0
- data/vendor/jsclasses/okumacro.sty +4 -17
- data/vendor/jsclasses/okuverb.ins +9 -0
- data/vendor/jsclasses/okuverb.pdf +0 -0
- data/vendor/jsclasses/okuverb.sty +1 -13
- data/vendor/jsclasses/tests/relfont.tex +10 -0
- data/vendor/jsclasses/winjis.sty +23 -19
- metadata +65 -12
- data/.rubocop_todo.yml +0 -7
- data/lib/review/book/compilable.rb +0 -173
- data/lib/review/tocparser.rb +0 -271
- data/samples/syntax-book/review-ext.rb +0 -14
- data/test/test_tocparser.rb +0 -25
data/lib/epubmaker/producer.rb
CHANGED
@@ -192,7 +192,8 @@ module EPUBMaker
|
|
192
192
|
current = Dir.pwd
|
193
193
|
basedir ||= current
|
194
194
|
|
195
|
-
|
195
|
+
# use Dir to solve a path for Windows (see #1011)
|
196
|
+
new_tmpdir = Dir[File.join(tmpdir.nil? ? Dir.mktmpdir : tmpdir)][0]
|
196
197
|
if epubfile !~ %r{\A/}
|
197
198
|
epubfile = "#{current}/#{epubfile}"
|
198
199
|
end
|
data/lib/review/book.rb
CHANGED
data/lib/review/book/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2009-
|
2
|
+
# Copyright (c) 2009-2019 Minero Aoki, Kenshi Muto
|
3
3
|
# 2002-2008 Minero Aoki
|
4
4
|
#
|
5
5
|
# This program is free software.
|
@@ -9,27 +9,34 @@
|
|
9
9
|
#
|
10
10
|
require 'review/configure'
|
11
11
|
require 'review/catalog'
|
12
|
+
require 'review/book/bib'
|
12
13
|
|
13
14
|
module ReVIEW
|
14
15
|
module Book
|
15
16
|
class Base
|
16
17
|
attr_accessor :config
|
17
18
|
attr_writer :parts
|
18
|
-
|
19
|
+
attr_accessor :catalog
|
19
20
|
attr_reader :basedir
|
21
|
+
attr_accessor :bibpaper_index
|
20
22
|
|
21
|
-
def self.load(
|
22
|
-
new(
|
23
|
+
def self.load(basedir = '.', config: nil)
|
24
|
+
new(basedir, config: config)
|
23
25
|
end
|
24
26
|
|
25
|
-
def initialize(basedir = '.')
|
27
|
+
def initialize(basedir = '.', config: nil)
|
26
28
|
@basedir = basedir
|
27
29
|
@logger = ReVIEW.logger
|
28
30
|
@parts = nil
|
29
31
|
@chapter_index = nil
|
30
|
-
@config = ReVIEW::Configure.values
|
32
|
+
@config = config || ReVIEW::Configure.values
|
31
33
|
@catalog = nil
|
32
|
-
@
|
34
|
+
@bibpaper_index = nil
|
35
|
+
catalog_path = filename_join(@basedir, @config['catalogfile'])
|
36
|
+
if catalog_path && File.file?(catalog_path)
|
37
|
+
parse_catalog_file(catalog_path)
|
38
|
+
end
|
39
|
+
|
33
40
|
@warn_old_files = {} # XXX for checking CHAPS, PREDEF, POSTDEF
|
34
41
|
@basedir_seen = {}
|
35
42
|
update_rubyenv
|
@@ -45,6 +52,14 @@ module ReVIEW
|
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
55
|
+
def execute_indexer
|
56
|
+
return unless @catalog
|
57
|
+
|
58
|
+
parts.each do |part|
|
59
|
+
part.chapters.each(&:execute_indexer)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
48
63
|
def bib_file
|
49
64
|
config['bib_file']
|
50
65
|
end
|
@@ -80,7 +95,7 @@ module ReVIEW
|
|
80
95
|
def page_metric
|
81
96
|
if config['page_metric'].respond_to?(:downcase) && config['page_metric'].upcase =~ /\A[A-Z0-9_]+\Z/
|
82
97
|
ReVIEW::Book::PageMetric.const_get(config['page_metric'].upcase)
|
83
|
-
elsif config['page_metric'].is_a?(Array) && config['page_metric'].size == 5
|
98
|
+
elsif config['page_metric'].is_a?(Array) && (config['page_metric'].size == 5 || config['page_metric'].size == 4)
|
84
99
|
ReVIEW::Book::PageMetric.new(*config['page_metric'])
|
85
100
|
else
|
86
101
|
config['page_metric']
|
@@ -95,6 +110,30 @@ module ReVIEW
|
|
95
110
|
end
|
96
111
|
end
|
97
112
|
|
113
|
+
def create_chapter_index
|
114
|
+
chapter_index = ChapterIndex.new
|
115
|
+
each_chapter do |chap|
|
116
|
+
chapter_index.add_item(Index::Item.new(chap.id, chap.number, chap))
|
117
|
+
end
|
118
|
+
parts.each do |prt|
|
119
|
+
if prt.id.present?
|
120
|
+
chapter_index.add_item(Index::Item.new(prt.id, prt.number, prt))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
chapter_index
|
124
|
+
end
|
125
|
+
|
126
|
+
def generate_indexes
|
127
|
+
if bib_exist?
|
128
|
+
bib = ReVIEW::Book::Bib.new(file_content: bib_content, book: self)
|
129
|
+
bib.generate_indexes(use_bib: true)
|
130
|
+
@bibpaper_index = bib.bibpaper_index
|
131
|
+
end
|
132
|
+
self.each_chapter(&:generate_indexes)
|
133
|
+
self.parts.map(&:generate_indexes)
|
134
|
+
@chapter_index = create_chapter_index
|
135
|
+
end
|
136
|
+
|
98
137
|
def parts
|
99
138
|
@parts ||= read_parts
|
100
139
|
end
|
@@ -102,7 +141,7 @@ module ReVIEW
|
|
102
141
|
def parts_in_file
|
103
142
|
# TODO: should be `parts.find_all{|part| part.present? and part.file?}` ?
|
104
143
|
parts.find_all do |part|
|
105
|
-
part if part.present?
|
144
|
+
part if part.present? && part.file?
|
106
145
|
end
|
107
146
|
end
|
108
147
|
|
@@ -137,19 +176,12 @@ module ReVIEW
|
|
137
176
|
|
138
177
|
def chapter_index
|
139
178
|
return @chapter_index if @chapter_index
|
140
|
-
|
141
|
-
|
142
|
-
# TODO: contents += parts.find_all { |prt| prt.id.present? }
|
143
|
-
parts.each do |prt|
|
144
|
-
if prt.id.present?
|
145
|
-
contents << prt
|
146
|
-
end
|
147
|
-
end
|
148
|
-
@chapter_index = ChapterIndex.new(contents)
|
179
|
+
@chapter_index = create_chapter_index
|
180
|
+
@chapter_index
|
149
181
|
end
|
150
182
|
|
151
183
|
def chapter(id)
|
152
|
-
chapter_index[id]
|
184
|
+
chapter_index[id].content
|
153
185
|
end
|
154
186
|
|
155
187
|
def next_chapter(chapter)
|
@@ -175,9 +207,7 @@ module ReVIEW
|
|
175
207
|
end
|
176
208
|
|
177
209
|
def volume
|
178
|
-
|
179
|
-
vol.page_per_kbyte = page_metric.page_per_kbyte
|
180
|
-
vol
|
210
|
+
Volume.sum(parts.map(&:volume) + chapters.map(&:volume))
|
181
211
|
end
|
182
212
|
|
183
213
|
def load_config(filename)
|
@@ -185,24 +215,22 @@ module ReVIEW
|
|
185
215
|
@config.merge!(new_conf)
|
186
216
|
end
|
187
217
|
|
188
|
-
def
|
189
|
-
|
190
|
-
|
191
|
-
catalogfile_path = filename_join(@basedir, config['catalogfile'])
|
192
|
-
if File.file? catalogfile_path
|
193
|
-
@catalog = File.open(catalogfile_path, 'r:BOM|utf-8') { |f| Catalog.new(f) }
|
218
|
+
def parse_catalog_file(path)
|
219
|
+
unless File.file?(path)
|
220
|
+
raise FileNotFound, "catalog.yml is not found #{path}"
|
194
221
|
end
|
195
|
-
|
222
|
+
|
223
|
+
File.open(path, 'rt:BOM|utf-8') do |f|
|
224
|
+
@catalog = Catalog.new(f)
|
196
225
|
@catalog.validate!(@config, basedir)
|
197
226
|
end
|
198
|
-
@catalog
|
199
227
|
end
|
200
228
|
|
201
229
|
def read_chaps
|
202
230
|
if catalog
|
203
231
|
catalog.chaps
|
204
232
|
else
|
205
|
-
read_file(config['chapter_file'])
|
233
|
+
read_file(config['chapter_file']).split("\n")
|
206
234
|
end
|
207
235
|
end
|
208
236
|
|
@@ -210,7 +238,7 @@ module ReVIEW
|
|
210
238
|
if catalog
|
211
239
|
catalog.predef
|
212
240
|
else
|
213
|
-
read_file(config['predef_file'])
|
241
|
+
read_file(config['predef_file']).split("\n")
|
214
242
|
end
|
215
243
|
end
|
216
244
|
|
@@ -218,7 +246,7 @@ module ReVIEW
|
|
218
246
|
if catalog
|
219
247
|
catalog.appendix
|
220
248
|
else
|
221
|
-
read_file(config['postdef_file']) # for backward compatibility
|
249
|
+
read_file(config['postdef_file']).split("\n") # for backward compatibility
|
222
250
|
end
|
223
251
|
end
|
224
252
|
|
@@ -226,17 +254,15 @@ module ReVIEW
|
|
226
254
|
if catalog
|
227
255
|
catalog.postdef
|
228
256
|
else
|
229
|
-
|
257
|
+
[]
|
230
258
|
end
|
231
259
|
end
|
232
260
|
|
233
261
|
def read_part
|
234
|
-
return @read_part if @read_part
|
235
|
-
|
236
262
|
if catalog
|
237
|
-
|
263
|
+
catalog.parts
|
238
264
|
else
|
239
|
-
|
265
|
+
File.read(File.join(@basedir, config['part_file'])).split("\n")
|
240
266
|
end
|
241
267
|
end
|
242
268
|
|
@@ -256,41 +282,45 @@ module ReVIEW
|
|
256
282
|
File.exist?(File.join(contentdir, bib_file))
|
257
283
|
end
|
258
284
|
|
285
|
+
def bib_content
|
286
|
+
File.read(File.join(contentdir, bib_file))
|
287
|
+
end
|
288
|
+
|
259
289
|
def prefaces
|
260
290
|
if catalog
|
261
|
-
return mkpart_from_namelist(catalog.predef
|
291
|
+
return Part.mkpart_from_namelist(self, catalog.predef)
|
262
292
|
end
|
263
293
|
|
264
294
|
begin
|
265
295
|
predef_file = filename_join(@basedir, config['predef_file'])
|
266
296
|
if File.file?(predef_file)
|
267
|
-
mkpart_from_namelistfile(predef_file)
|
297
|
+
Part.mkpart_from_namelistfile(self, predef_file)
|
268
298
|
end
|
269
|
-
rescue FileNotFound =>
|
270
|
-
raise FileNotFound, "preface #{
|
299
|
+
rescue FileNotFound => e
|
300
|
+
raise FileNotFound, "preface #{e.message}"
|
271
301
|
end
|
272
302
|
end
|
273
303
|
|
274
304
|
def appendix
|
275
305
|
if catalog
|
276
|
-
names = catalog.appendix
|
277
|
-
chaps = names.each_with_index.map { |
|
278
|
-
return mkpart(chaps)
|
306
|
+
names = catalog.appendix
|
307
|
+
chaps = names.each_with_index.map { |name, number| Chapter.mkchap_ifexist(self, name, number + 1) }.compact
|
308
|
+
return Part.mkpart(chaps)
|
279
309
|
end
|
280
310
|
|
281
311
|
begin
|
282
312
|
postdef_file = filename_join(@basedir, config['postdef_file'])
|
283
313
|
if File.file?(postdef_file)
|
284
|
-
mkpart_from_namelistfile(postdef_file)
|
314
|
+
Part.mkpart_from_namelistfile(self, postdef_file)
|
285
315
|
end
|
286
|
-
rescue FileNotFound =>
|
287
|
-
raise FileNotFound, "postscript #{
|
316
|
+
rescue FileNotFound => e
|
317
|
+
raise FileNotFound, "postscript #{e.message}"
|
288
318
|
end
|
289
319
|
end
|
290
320
|
|
291
321
|
def postscripts
|
292
322
|
if catalog
|
293
|
-
mkpart_from_namelist(catalog.postdef
|
323
|
+
Part.mkpart_from_namelist(self, catalog.postdef)
|
294
324
|
end
|
295
325
|
end
|
296
326
|
|
@@ -300,13 +330,13 @@ module ReVIEW
|
|
300
330
|
list = parse_chapters
|
301
331
|
# NOTE: keep this = style to work this logic.
|
302
332
|
if pre = prefaces
|
303
|
-
list.unshift
|
333
|
+
list.unshift(pre)
|
304
334
|
end
|
305
335
|
if app = appendix
|
306
|
-
list.push
|
336
|
+
list.push(app)
|
307
337
|
end
|
308
338
|
if post = postscripts
|
309
|
-
list.push
|
339
|
+
list.push(post)
|
310
340
|
end
|
311
341
|
list
|
312
342
|
end
|
@@ -324,7 +354,7 @@ module ReVIEW
|
|
324
354
|
chap = Chapter.new(self, num += 1, chap, File.join(contentdir, chap))
|
325
355
|
chap
|
326
356
|
end
|
327
|
-
Part.new(self, part += 1, chaps, read_part
|
357
|
+
Part.new(self, part += 1, chaps, read_part[part - 1])
|
328
358
|
else
|
329
359
|
chap = Chapter.new(self, num += 1, entry, File.join(contentdir, entry))
|
330
360
|
if chap.number
|
@@ -337,53 +367,18 @@ module ReVIEW
|
|
337
367
|
end
|
338
368
|
end
|
339
369
|
|
340
|
-
|
341
|
-
|
342
|
-
map do |part_chunk|
|
370
|
+
# rubocop:disable Style/RedundantAssignment
|
371
|
+
chap = read_chaps.map(&:strip).join("\n").split(/\n{2,}/).map do |part_chunk|
|
343
372
|
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
|
373
|
+
if part_exist? && read_part.size > part
|
374
|
+
Part.new(self, part += 1, chaps, read_part[part - 1])
|
346
375
|
else
|
347
376
|
Part.new(self, nil, chaps)
|
348
377
|
end
|
349
378
|
end
|
350
|
-
|
351
|
-
end
|
379
|
+
# rubocop:enable Style/RedundantAssignment
|
352
380
|
|
353
|
-
|
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
|
381
|
+
chap
|
387
382
|
end
|
388
383
|
|
389
384
|
def read_file(filename)
|
@@ -394,9 +389,9 @@ module ReVIEW
|
|
394
389
|
end
|
395
390
|
end
|
396
391
|
res = ''
|
397
|
-
File.open(filename_join(@basedir, filename), '
|
392
|
+
File.open(filename_join(@basedir, filename), 'rt:BOM|utf-8') do |f|
|
398
393
|
f.each_line do |line|
|
399
|
-
next if
|
394
|
+
next if line.start_with?('#')
|
400
395
|
line.gsub!(/#.*\Z/, '')
|
401
396
|
res << line
|
402
397
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2020 Minero Aoki, Kenshi Muto
|
3
|
+
#
|
4
|
+
# This program is free software.
|
5
|
+
# You can distribute or modify this program under the terms of
|
6
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
7
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
8
|
+
#
|
9
|
+
require 'review/book/book_unit'
|
10
|
+
require 'review/lineinput'
|
11
|
+
require 'review/preprocessor'
|
12
|
+
|
13
|
+
module ReVIEW
|
14
|
+
module Book
|
15
|
+
class Bib < BookUnit
|
16
|
+
def number
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# Copyright (c) 2009-2017 Minero Aoki, Kenshi Muto
|
2
|
+
# 2002-2008 Minero Aoki
|
3
|
+
#
|
4
|
+
# This program is free software.
|
5
|
+
# You can distribute or modify this program under the terms of
|
6
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
7
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
8
|
+
#
|
9
|
+
require 'review/textutils'
|
10
|
+
require 'review/index_builder'
|
11
|
+
|
12
|
+
module ReVIEW
|
13
|
+
module Book
|
14
|
+
class BookUnit
|
15
|
+
include TextUtils
|
16
|
+
attr_reader :book
|
17
|
+
attr_reader :path
|
18
|
+
attr_reader :lines
|
19
|
+
attr_accessor :content
|
20
|
+
|
21
|
+
attr_reader :list_index, :table_index, :equation_index, :footnote_index,
|
22
|
+
:numberless_image_index, :image_index, :icon_index, :indepimage_index,
|
23
|
+
:headline_index, :column_index
|
24
|
+
|
25
|
+
def initialize(file_content: nil, book: nil)
|
26
|
+
if book
|
27
|
+
@book = book
|
28
|
+
end
|
29
|
+
if file_content
|
30
|
+
@content = file_content
|
31
|
+
end
|
32
|
+
if @content
|
33
|
+
@lines = @content.lines
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute_indexer(force: false)
|
38
|
+
if @index_builder && !force
|
39
|
+
return @index_builder
|
40
|
+
end
|
41
|
+
|
42
|
+
@index_builder = ReVIEW::IndexBuilder.new
|
43
|
+
compiler = ReVIEW::Compiler.new(@index_builder)
|
44
|
+
compiler.compile(self)
|
45
|
+
@index_builder
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_indexes(use_bib: false)
|
49
|
+
return unless content
|
50
|
+
|
51
|
+
@lines = content.lines
|
52
|
+
|
53
|
+
@indexes = execute_indexer
|
54
|
+
|
55
|
+
@list_index = @indexes.list_index
|
56
|
+
@table_index = @indexes.table_index
|
57
|
+
@equation_index = @indexes.equation_index
|
58
|
+
@footnote_index = @indexes.footnote_index
|
59
|
+
@headline_index = @indexes.headline_index
|
60
|
+
@column_index = @indexes.column_index
|
61
|
+
if use_bib
|
62
|
+
@book.bibpaper_index = @indexes.bibpaper_index
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def dirname
|
67
|
+
@path && File.dirname(@path)
|
68
|
+
end
|
69
|
+
|
70
|
+
def basename
|
71
|
+
@path && File.basename(@path)
|
72
|
+
end
|
73
|
+
|
74
|
+
def name
|
75
|
+
@name && File.basename(@name, '.*')
|
76
|
+
end
|
77
|
+
|
78
|
+
alias_method :id, :name
|
79
|
+
|
80
|
+
def title
|
81
|
+
return @title if @title
|
82
|
+
|
83
|
+
@title = ''
|
84
|
+
return @title unless content
|
85
|
+
content.each_line do |line|
|
86
|
+
if line =~ /\A=+/
|
87
|
+
@title = line.sub(/\A=+(\[.+?\])?(\{.+?\})?/, '').strip
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
@title
|
92
|
+
end
|
93
|
+
|
94
|
+
def size
|
95
|
+
content.size
|
96
|
+
end
|
97
|
+
|
98
|
+
def volume
|
99
|
+
@volume ||= Volume.count_file(path)
|
100
|
+
end
|
101
|
+
|
102
|
+
def list(id)
|
103
|
+
list_index[id]
|
104
|
+
end
|
105
|
+
|
106
|
+
def table(id)
|
107
|
+
table_index[id]
|
108
|
+
end
|
109
|
+
|
110
|
+
def equation(id)
|
111
|
+
equation_index[id]
|
112
|
+
end
|
113
|
+
|
114
|
+
def footnote(id)
|
115
|
+
footnote_index[id]
|
116
|
+
end
|
117
|
+
|
118
|
+
def image(id)
|
119
|
+
return image_index[id] if image_index.key?(id)
|
120
|
+
return icon_index[id] if icon_index.key?(id)
|
121
|
+
return numberless_image_index[id] if numberless_image_index.key?(id)
|
122
|
+
indepimage_index[id]
|
123
|
+
end
|
124
|
+
|
125
|
+
def bibpaper(id)
|
126
|
+
bibpaper_index[id]
|
127
|
+
end
|
128
|
+
|
129
|
+
def bibpaper_index
|
130
|
+
raise FileNotFound, "no such bib file: #{@book.bib_file}" unless @book.bib_exist?
|
131
|
+
@book.bibpaper_index
|
132
|
+
end
|
133
|
+
|
134
|
+
def headline(caption)
|
135
|
+
headline_index[caption]
|
136
|
+
end
|
137
|
+
|
138
|
+
def column(id)
|
139
|
+
column_index[id]
|
140
|
+
end
|
141
|
+
|
142
|
+
def next_chapter
|
143
|
+
book.next_chapter(self)
|
144
|
+
end
|
145
|
+
|
146
|
+
def prev_chapter
|
147
|
+
book.prev_chapter(self)
|
148
|
+
end
|
149
|
+
|
150
|
+
def image_bound?(item_id)
|
151
|
+
image(item_id).path
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|