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/makerhelper.rb
CHANGED
@@ -8,7 +8,6 @@
|
|
8
8
|
require 'pathname'
|
9
9
|
require 'fileutils'
|
10
10
|
require 'yaml'
|
11
|
-
require 'shellwords'
|
12
11
|
|
13
12
|
begin
|
14
13
|
require 'cgi/escape'
|
@@ -18,12 +17,6 @@ end
|
|
18
17
|
|
19
18
|
module ReVIEW
|
20
19
|
module MakerHelper
|
21
|
-
# Return review/bin directory
|
22
|
-
def bindir
|
23
|
-
Pathname.new("#{Pathname.new(__FILE__).realpath.dirname}/../../bin").realpath
|
24
|
-
end
|
25
|
-
module_function :bindir
|
26
|
-
|
27
20
|
def h(str)
|
28
21
|
CGI.escapeHTML(str)
|
29
22
|
end
|
@@ -51,6 +44,7 @@ module ReVIEW
|
|
51
44
|
Dir.open(from_dir) do |dir|
|
52
45
|
dir.each do |fname|
|
53
46
|
next if fname =~ /^\./
|
47
|
+
|
54
48
|
if FileTest.directory?("#{from_dir}/#{fname}")
|
55
49
|
image_files += copy_images_to_dir("#{from_dir}/#{fname}", "#{to_dir}/#{fname}", options)
|
56
50
|
else
|
@@ -59,6 +53,7 @@ module ReVIEW
|
|
59
53
|
is_converted = false
|
60
54
|
(options[:convert] || {}).each do |orig_type, conv_type|
|
61
55
|
next unless /\.#{orig_type}$/ =~ fname
|
56
|
+
|
62
57
|
is_converted = system("convert #{from_dir}/#{fname} #{to_dir}/#{fname}.#{conv_type}")
|
63
58
|
image_files << "#{from_dir}/#{fname}.#{conv_type}"
|
64
59
|
end
|
@@ -76,203 +71,5 @@ module ReVIEW
|
|
76
71
|
image_files
|
77
72
|
end
|
78
73
|
module_function :copy_images_to_dir
|
79
|
-
|
80
|
-
def cleanup_mathimg(path = '_review_math')
|
81
|
-
math_dir = "./#{@config['imagedir']}/#{path}"
|
82
|
-
if @config['imgmath'] && Dir.exist?(math_dir)
|
83
|
-
FileUtils.rm_rf(math_dir)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def default_imgmath_preamble
|
88
|
-
<<-EOB
|
89
|
-
\\documentclass[uplatex,a3paper,landscape]{jsarticle}
|
90
|
-
\\usepackage[deluxe,uplatex]{otf}
|
91
|
-
\\usepackage[T1]{fontenc}
|
92
|
-
\\usepackage{textcomp}
|
93
|
-
\\usepackage{lmodern}
|
94
|
-
\\usepackage[dvipdfmx]{graphicx}
|
95
|
-
\\usepackage[dvipdfmx,table]{xcolor}
|
96
|
-
\\usepackage[utf8]{inputenc}
|
97
|
-
\\usepackage{ascmac}
|
98
|
-
\\usepackage{float}
|
99
|
-
\\usepackage{alltt}
|
100
|
-
\\usepackage{amsmath}
|
101
|
-
\\usepackage{amssymb}
|
102
|
-
\\usepackage{amsfonts}
|
103
|
-
\\usepackage{anyfontsize}
|
104
|
-
\\usepackage{bm}
|
105
|
-
\\pagestyle{empty}
|
106
|
-
% \\setpaperwidth{1000mm}
|
107
|
-
EOB
|
108
|
-
end
|
109
|
-
|
110
|
-
def make_math_images(math_dir)
|
111
|
-
fontsize = @config['imgmath_options']['fontsize'].to_f
|
112
|
-
lineheight = @config['imgmath_options']['lineheight'].to_f
|
113
|
-
|
114
|
-
texsrc = default_imgmath_preamble
|
115
|
-
if @config['imgmath_options']['preamble_file'] && File.readable?(@config['imgmath_options']['preamble_file'])
|
116
|
-
texsrc = File.read(@config['imgmath_options']['preamble_file'])
|
117
|
-
end
|
118
|
-
|
119
|
-
texsrc << <<-EOB
|
120
|
-
\\begin{document}
|
121
|
-
\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont
|
122
|
-
\\input{__IMGMATH_BODY__}
|
123
|
-
\\end{document}
|
124
|
-
EOB
|
125
|
-
|
126
|
-
hashes = File.readlines(File.join(math_dir, '__IMGMATH_BODY__.map')).sort.uniq
|
127
|
-
File.write(File.join(math_dir, '__IMGMATH_BODY__.map'), hashes.join)
|
128
|
-
|
129
|
-
File.open(File.join(math_dir, '__IMGMATH_BODY__.tex'), 'w') do |f|
|
130
|
-
File.open(File.join(math_dir, '__IMGMATH_BODY__.map')) do |map|
|
131
|
-
map.each_line do |l|
|
132
|
-
l.chomp!
|
133
|
-
f.puts "% #{l}"
|
134
|
-
f.puts File.read(File.join(math_dir, "__IMGMATH_BODY__#{l}.tex"))
|
135
|
-
File.unlink(File.join(math_dir, "__IMGMATH_BODY__#{l}.tex"))
|
136
|
-
f.puts '\\clearpage'
|
137
|
-
f.puts
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
math_dir = File.realpath(math_dir)
|
143
|
-
Dir.mktmpdir do |tmpdir|
|
144
|
-
FileUtils.cp([File.join(math_dir, '__IMGMATH_BODY__.tex'),
|
145
|
-
File.join(math_dir, '__IMGMATH_BODY__.map')],
|
146
|
-
tmpdir)
|
147
|
-
tex_path = File.join(tmpdir, '__IMGMATH__.tex')
|
148
|
-
File.write(tex_path, texsrc)
|
149
|
-
|
150
|
-
begin
|
151
|
-
case @config['imgmath_options']['converter']
|
152
|
-
when 'pdfcrop'
|
153
|
-
make_math_images_pdfcrop(tmpdir, tex_path, math_dir)
|
154
|
-
when 'dvipng'
|
155
|
-
make_math_images_dvipng(tmpdir, tex_path, math_dir)
|
156
|
-
else
|
157
|
-
error "unknown math converter error. imgmath_options/converter parameter should be 'pdfcrop' or 'dvipng'."
|
158
|
-
end
|
159
|
-
rescue CompileError
|
160
|
-
FileUtils.cp([tex_path,
|
161
|
-
File.join(File.dirname(tex_path), '__IMGMATH__.log')],
|
162
|
-
math_dir)
|
163
|
-
error "LaTeX math compile error. See #{math_dir}/__IMGMATH__.log for details."
|
164
|
-
end
|
165
|
-
end
|
166
|
-
FileUtils.rm_f([File.join(math_dir, '__IMGMATH_BODY__.tex'),
|
167
|
-
File.join(math_dir, '__IMGMATH_BODY__.map')])
|
168
|
-
end
|
169
|
-
module_function :make_math_images
|
170
|
-
|
171
|
-
def make_math_images_pdfcrop(dir, tex_path, math_dir)
|
172
|
-
# rubocop:disable Metrics/BlockLength
|
173
|
-
Dir.chdir(dir) do
|
174
|
-
dvi_path = '__IMGMATH__.dvi'
|
175
|
-
pdf_path = '__IMGMATH__.pdf'
|
176
|
-
out, status = Open3.capture2e(*[@config['texcommand'], @config['texoptions'].shellsplit, tex_path].flatten.compact)
|
177
|
-
if !status.success? || (!File.exist?(dvi_path) && !File.exist?(pdf_path))
|
178
|
-
raise CompileError
|
179
|
-
end
|
180
|
-
if File.exist?(dvi_path)
|
181
|
-
out, status = Open3.capture2e(*[@config['dvicommand'], @config['dvioptions'].shellsplit, dvi_path].flatten.compact)
|
182
|
-
if !status.success? || !File.exist?(pdf_path)
|
183
|
-
warn "error in #{@config['dvicommand']}. Error log:\n#{out}"
|
184
|
-
raise CompileError
|
185
|
-
end
|
186
|
-
end
|
187
|
-
args = @config['imgmath_options']['pdfcrop_cmd'].shellsplit
|
188
|
-
args.map! do |m|
|
189
|
-
m.sub('%i', pdf_path).
|
190
|
-
sub('%o', '__IMGMATH__pdfcrop.pdf')
|
191
|
-
end
|
192
|
-
out, status = Open3.capture2e(*args)
|
193
|
-
unless status.success?
|
194
|
-
warn "error in pdfcrop. Error log:\n#{out}"
|
195
|
-
raise CompileError
|
196
|
-
end
|
197
|
-
pdf_path = '__IMGMATH__pdfcrop.pdf'
|
198
|
-
pdf_path2 = pdf_path
|
199
|
-
|
200
|
-
File.open('__IMGMATH_BODY__.map') do |f|
|
201
|
-
page = 0
|
202
|
-
f.each_line do |key|
|
203
|
-
page += 1
|
204
|
-
key.chomp!
|
205
|
-
if File.exist?(File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}"))
|
206
|
-
# made already
|
207
|
-
next
|
208
|
-
end
|
209
|
-
|
210
|
-
if @config['imgmath_options']['extract_singlepage']
|
211
|
-
# if extract_singlepage = true, split each page
|
212
|
-
args = @config['imgmath_options']['pdfextract_cmd'].shellsplit
|
213
|
-
|
214
|
-
args.map! do |m|
|
215
|
-
m.sub('%i', pdf_path).
|
216
|
-
sub('%o', "__IMGMATH__pdfcrop_p#{page}.pdf").
|
217
|
-
sub('%O', "__IMGMATH__pdfcrop_p#{page}").
|
218
|
-
sub('%p', page.to_s)
|
219
|
-
end
|
220
|
-
out, status = Open3.capture2e(*args)
|
221
|
-
unless status.success?
|
222
|
-
warn "error in pdf extracting. Error log:\n#{out}"
|
223
|
-
raise CompileError
|
224
|
-
end
|
225
|
-
|
226
|
-
pdf_path2 = "__IMGMATH__pdfcrop_p#{page}.pdf"
|
227
|
-
end
|
228
|
-
|
229
|
-
args = @config['imgmath_options']['pdfcrop_pixelize_cmd'].shellsplit
|
230
|
-
args.map! do |m|
|
231
|
-
m.sub('%i', pdf_path2).
|
232
|
-
sub('%t', @config['imgmath_options']['format']).
|
233
|
-
sub('%o', File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}")).
|
234
|
-
sub('%O', File.join(math_dir, "_gen_#{key}")).
|
235
|
-
sub('%p', page.to_s)
|
236
|
-
end
|
237
|
-
out, status = Open3.capture2e(*args)
|
238
|
-
unless status.success?
|
239
|
-
warn "error in pdf pixelizing. Error log:\n#{out}"
|
240
|
-
raise CompileError
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
# rubocop:enable Metrics/BlockLength
|
246
|
-
end
|
247
|
-
|
248
|
-
def make_math_images_dvipng(dir, tex_path, math_dir)
|
249
|
-
Dir.chdir(dir) do
|
250
|
-
dvi_path = '__IMGMATH__.dvi'
|
251
|
-
out, status = Open3.capture2e(*[@config['texcommand'], @config['texoptions'].shellsplit, tex_path].flatten.compact)
|
252
|
-
if !status.success? || !File.exist?(dvi_path)
|
253
|
-
raise CompileError
|
254
|
-
end
|
255
|
-
|
256
|
-
File.open('__IMGMATH_BODY__.map') do |f|
|
257
|
-
page = 0
|
258
|
-
f.each_line do |key|
|
259
|
-
page += 1
|
260
|
-
key.chomp!
|
261
|
-
args = @config['imgmath_options']['dvipng_cmd'].shellsplit
|
262
|
-
args.map! do |m|
|
263
|
-
m.sub('%i', dvi_path).
|
264
|
-
sub('%o', File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}")).
|
265
|
-
sub('%O', File.join(math_dir, "_gen_#{key}")).
|
266
|
-
sub('%p', page.to_s)
|
267
|
-
end
|
268
|
-
out, status = Open3.capture2e(*args)
|
269
|
-
unless status.success?
|
270
|
-
warn "error in dvipng. Error log:\n#{out}"
|
271
|
-
raise CompileError
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
74
|
end
|
278
75
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013-
|
1
|
+
# Copyright (c) 2013-2020 KADO Masanori, Masayoshi Takahashi, Kenshi Muto
|
2
2
|
#
|
3
3
|
# This program is free software.
|
4
4
|
# You can distribute or modify this program under the terms of
|
@@ -224,6 +224,14 @@ module ReVIEW
|
|
224
224
|
"<u>#{str}</u>"
|
225
225
|
end
|
226
226
|
|
227
|
+
def inline_ins(str)
|
228
|
+
"<ins>#{str}</ins>"
|
229
|
+
end
|
230
|
+
|
231
|
+
def inline_del(str)
|
232
|
+
"~~#{str}~~"
|
233
|
+
end
|
234
|
+
|
227
235
|
def image_image(id, caption, _metric)
|
228
236
|
blank
|
229
237
|
puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
|
@@ -244,6 +252,28 @@ module ReVIEW
|
|
244
252
|
"<!-- DTP:#{str} -->"
|
245
253
|
end
|
246
254
|
|
255
|
+
def inline_hd_chap(chap, id)
|
256
|
+
n = chap.headline_index.number(id)
|
257
|
+
if n.present? && chap.number && over_secnolevel?(n)
|
258
|
+
str = I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
|
259
|
+
else
|
260
|
+
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
|
261
|
+
end
|
262
|
+
if @book.config['chapterlink']
|
263
|
+
if @chapter == chap
|
264
|
+
anchor = 'h' + n.tr('.', '-')
|
265
|
+
%Q(<a href="##{anchor}">#{str}</a>)
|
266
|
+
else
|
267
|
+
warn 'MARKDOWNBuilder does not support links to other chapters'
|
268
|
+
str
|
269
|
+
end
|
270
|
+
else
|
271
|
+
str
|
272
|
+
end
|
273
|
+
rescue KeyError
|
274
|
+
error "unknown headline: #{id}"
|
275
|
+
end
|
276
|
+
|
247
277
|
def indepimage(_lines, id, caption = '', _metric = nil)
|
248
278
|
blank
|
249
279
|
puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
|
@@ -358,6 +388,7 @@ module ReVIEW
|
|
358
388
|
|
359
389
|
def comment(lines, comment = nil)
|
360
390
|
return unless @book.config['draft']
|
391
|
+
|
361
392
|
lines ||= []
|
362
393
|
unless comment.blank?
|
363
394
|
lines.unshift(comment)
|
data/lib/review/pdfmaker.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2021 Kenshi Muto and Masayoshi Takahashi
|
2
2
|
#
|
3
3
|
# This program is free software.
|
4
4
|
# You can distribute or modify this program under the terms of
|
@@ -22,11 +22,14 @@ require 'review/yamlloader'
|
|
22
22
|
require 'review/version'
|
23
23
|
require 'review/makerhelper'
|
24
24
|
require 'review/template'
|
25
|
+
require 'review/latexbox'
|
26
|
+
require 'review/call_hook'
|
25
27
|
|
26
28
|
module ReVIEW
|
27
29
|
class PDFMaker
|
28
30
|
include FileUtils
|
29
31
|
include ReVIEW::LaTeXUtils
|
32
|
+
include ReVIEW::CallHook
|
30
33
|
|
31
34
|
attr_accessor :config, :basedir
|
32
35
|
|
@@ -151,6 +154,7 @@ module ReVIEW
|
|
151
154
|
generate_pdf
|
152
155
|
rescue ApplicationError => e
|
153
156
|
raise if @config['debug']
|
157
|
+
|
154
158
|
error(e.message)
|
155
159
|
end
|
156
160
|
end
|
@@ -198,7 +202,7 @@ module ReVIEW
|
|
198
202
|
Dir.chdir(@path) do
|
199
203
|
File.open("./#{@mastertex}.tex", 'wb') { |f| f.write template }
|
200
204
|
|
201
|
-
call_hook('hook_beforetexcompile')
|
205
|
+
call_hook('hook_beforetexcompile', Dir.pwd, @basedir, base_dir: @basedir)
|
202
206
|
|
203
207
|
## do compile
|
204
208
|
if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
|
@@ -241,32 +245,32 @@ module ReVIEW
|
|
241
245
|
system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
|
242
246
|
end
|
243
247
|
|
244
|
-
call_hook('hook_beforemakeindex')
|
248
|
+
call_hook('hook_beforemakeindex', Dir.pwd, @basedir, base_dir: @basedir)
|
245
249
|
if @config['pdfmaker']['makeindex'] && File.size?("#{@mastertex}.idx")
|
246
250
|
system_or_raise(*[makeindex_command, makeindex_options, @mastertex].flatten.compact)
|
251
|
+
call_hook('hook_aftermakeindex', Dir.pwd, @basedir, base_dir: @basedir)
|
247
252
|
system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
|
248
253
|
end
|
249
|
-
call_hook('hook_aftermakeindex')
|
250
254
|
|
251
255
|
system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
|
252
|
-
call_hook('hook_aftertexcompile')
|
256
|
+
call_hook('hook_aftertexcompile', Dir.pwd, @basedir, base_dir: @basedir)
|
253
257
|
|
254
258
|
if File.exist?("#{@mastertex}.dvi") && dvicommand.present?
|
255
259
|
system_or_raise(*[dvicommand, dvioptions, "#{@mastertex}.dvi"].flatten.compact)
|
256
|
-
call_hook('hook_afterdvipdf')
|
260
|
+
call_hook('hook_afterdvipdf', Dir.pwd, @basedir, base_dir: @basedir)
|
257
261
|
end
|
258
262
|
end
|
259
263
|
end
|
260
264
|
|
261
265
|
def generate_pdf
|
262
266
|
remove_old_file
|
263
|
-
erb_config
|
264
267
|
@path = build_path
|
265
268
|
begin
|
266
269
|
@compile_errors = nil
|
267
270
|
|
268
271
|
book = ReVIEW::Book::Base.new(@basedir, config: @config)
|
269
272
|
@converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new)
|
273
|
+
erb_config
|
270
274
|
|
271
275
|
@input_files = make_input_files(book)
|
272
276
|
|
@@ -287,6 +291,7 @@ module ReVIEW
|
|
287
291
|
build_pdf
|
288
292
|
|
289
293
|
FileUtils.cp(File.join(@path, "#{@mastertex}.pdf"), pdf_filepath)
|
294
|
+
@logger.success("built #{File.basename(pdf_filepath)}")
|
290
295
|
ensure
|
291
296
|
remove_entry_secure(@path) unless @config['debug']
|
292
297
|
end
|
@@ -307,6 +312,7 @@ module ReVIEW
|
|
307
312
|
#
|
308
313
|
def copy_images(from, to)
|
309
314
|
return unless File.exist?(from)
|
315
|
+
|
310
316
|
Dir.mkdir(to)
|
311
317
|
ReVIEW::MakerHelper.copy_images_to_dir(from, to)
|
312
318
|
end
|
@@ -316,6 +322,7 @@ module ReVIEW
|
|
316
322
|
if File.exist?(file_sty)
|
317
323
|
return File.read(file_sty)
|
318
324
|
end
|
325
|
+
|
319
326
|
nil
|
320
327
|
end
|
321
328
|
|
@@ -445,36 +452,40 @@ module ReVIEW
|
|
445
452
|
@locale_latex['postchaptername'] = chapter_tuple[1].to_s
|
446
453
|
@locale_latex['preappendixname'] = appendix_tuple[0].to_s
|
447
454
|
@locale_latex['postappendixname'] = appendix_tuple[1].to_s
|
448
|
-
end
|
449
455
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
456
|
+
if @config['pdfmaker']['boxsetting']
|
457
|
+
begin
|
458
|
+
@boxsetting = ReVIEW::LaTeXBox.new.tcbox(@config)
|
459
|
+
rescue ReVIEW::ConfigError => e
|
460
|
+
error e
|
461
|
+
end
|
462
|
+
end
|
455
463
|
end
|
456
464
|
|
457
465
|
def latex_config
|
458
|
-
result =
|
466
|
+
result = ReVIEW::Template.generate(path: './latex/config.erb', mode: '-', binding: binding)
|
459
467
|
local_config_file = File.join(@basedir, 'layouts', 'config-local.tex.erb')
|
460
468
|
if File.exist?(local_config_file)
|
461
469
|
result << "%% BEGIN: config-local.tex.erb\n"
|
462
|
-
result <<
|
470
|
+
result << ReVIEW::Template.generate(path: 'layouts/config-local.tex.erb', mode: '-', binding: binding, template_dir: @basedir)
|
463
471
|
result << "%% END: config-local.tex.erb\n"
|
464
472
|
end
|
465
473
|
result
|
466
474
|
end
|
467
475
|
|
468
476
|
def template_content
|
469
|
-
|
477
|
+
template_dir = ReVIEW::Template::TEMPLATE_DIR
|
470
478
|
if @config.check_version('2', exception: false)
|
471
|
-
|
479
|
+
template_path = './latex-compat2/layout.tex.erb'
|
480
|
+
else
|
481
|
+
template_path = './latex/layout.tex.erb'
|
472
482
|
end
|
473
483
|
layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
|
474
484
|
if File.exist?(layout_file)
|
475
|
-
|
485
|
+
template_dir = @basedir
|
486
|
+
template_path = 'layouts/layout.tex.erb'
|
476
487
|
end
|
477
|
-
|
488
|
+
ReVIEW::Template.generate(path: template_path, mode: '-', binding: binding, template_dir: template_dir)
|
478
489
|
end
|
479
490
|
|
480
491
|
def copy_sty(dirname, copybase, extname = 'sty')
|
@@ -486,6 +497,7 @@ module ReVIEW
|
|
486
497
|
Dir.open(dirname) do |dir|
|
487
498
|
dir.sort.each do |fname|
|
488
499
|
next unless File.extname(fname).downcase == '.' + extname
|
500
|
+
|
489
501
|
FileUtils.mkdir_p(copybase) unless Dir.exist?(copybase)
|
490
502
|
if extname == 'erb'
|
491
503
|
File.open(File.join(copybase, fname.sub(/\.erb\Z/, '')), 'w') do |f|
|
@@ -497,15 +509,5 @@ module ReVIEW
|
|
497
509
|
end
|
498
510
|
end
|
499
511
|
end
|
500
|
-
|
501
|
-
def call_hook(hookname)
|
502
|
-
return if !@config['pdfmaker'].is_a?(Hash) || @config['pdfmaker'][hookname].nil?
|
503
|
-
hook = File.absolute_path(@config['pdfmaker'][hookname], @basedir)
|
504
|
-
if ENV['REVIEW_SAFE_MODE'].to_i & 1 > 0
|
505
|
-
warn 'hook configuration is prohibited in safe mode. ignored.'
|
506
|
-
else
|
507
|
-
system_or_raise(hook, Dir.pwd, @basedir)
|
508
|
-
end
|
509
|
-
end
|
510
512
|
end
|
511
513
|
end
|