review 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +90 -66
- data/.travis.yml +1 -1
- data/Gemfile +0 -1
- data/NEWS.ja.md +82 -0
- data/NEWS.md +83 -0
- data/README.md +5 -3
- data/Rakefile +8 -8
- data/bin/review +1 -5
- data/bin/review-catalog-converter +22 -27
- data/bin/review-check +36 -43
- data/bin/review-checkdep +10 -15
- data/bin/review-compile +37 -55
- data/bin/review-epubmaker +4 -5
- data/bin/review-index +21 -29
- data/bin/review-init +26 -37
- data/bin/review-pdfmaker +0 -2
- data/bin/review-preproc +25 -45
- data/bin/review-validate +19 -18
- data/bin/review-vol +15 -27
- data/doc/config.yml.sample +5 -2
- data/doc/format.ja.md +20 -1
- data/doc/format.md +21 -5
- data/doc/images/review-generate.png +0 -0
- data/lib/epubmaker.rb +1 -3
- data/lib/epubmaker/content.rb +24 -27
- data/lib/epubmaker/epubcommon.rb +135 -148
- data/lib/epubmaker/epubv2.rb +39 -46
- data/lib/epubmaker/epubv3.rb +93 -103
- data/lib/epubmaker/producer.rb +138 -151
- data/lib/epubmaker/zip_exporter.rb +21 -26
- data/lib/review/book.rb +3 -6
- data/lib/review/book/base.rb +78 -103
- data/lib/review/book/chapter.rb +36 -40
- data/lib/review/book/compilable.rb +28 -31
- data/lib/review/book/image_finder.rb +6 -13
- data/lib/review/book/index.rb +100 -121
- data/lib/review/book/page_metric.rb +2 -7
- data/lib/review/book/part.rb +18 -20
- data/lib/review/book/volume.rb +9 -13
- data/lib/review/builder.rb +81 -116
- data/lib/review/catalog.rb +15 -19
- data/lib/review/compiler.rb +64 -83
- data/lib/review/configure.rb +87 -97
- data/lib/review/converter.rb +2 -7
- data/lib/review/epubbuilder.rb +1 -3
- data/lib/review/epubmaker.rb +213 -205
- data/lib/review/exception.rb +2 -4
- data/lib/review/extentions.rb +0 -1
- data/lib/review/extentions/hash.rb +2 -2
- data/lib/review/extentions/string.rb +5 -30
- data/lib/review/htmlbuilder.rb +320 -375
- data/lib/review/htmltoc.rb +4 -7
- data/lib/review/htmlutils.rb +29 -32
- data/lib/review/i18n.rb +33 -44
- data/lib/review/i18n.yml +3 -3
- data/lib/review/idgxmlbuilder.rb +309 -345
- data/lib/review/latexbuilder.rb +175 -212
- data/lib/review/latexindex.rb +2 -8
- data/lib/review/latexutils.rb +33 -43
- data/lib/review/lineinput.rb +1 -1
- data/lib/review/logger.rb +21 -0
- data/lib/review/makerhelper.rb +1 -4
- data/lib/review/markdownbuilder.rb +44 -53
- data/lib/review/md2inaobuilder.rb +6 -12
- data/lib/review/pdfmaker.rb +143 -173
- data/lib/review/preprocessor.rb +64 -101
- data/lib/review/rstbuilder.rb +126 -158
- data/lib/review/sec_counter.rb +18 -34
- data/lib/review/template.rb +4 -5
- data/lib/review/textbuilder.rb +2 -3
- data/lib/review/textutils.rb +7 -13
- data/lib/review/tocparser.rb +31 -56
- data/lib/review/tocprinter.rb +26 -52
- data/lib/review/topbuilder.rb +219 -247
- data/lib/review/unfold.rb +15 -24
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +75 -99
- data/lib/review/webtocprinter.rb +15 -20
- data/lib/review/yamlloader.rb +13 -15
- data/review.gemspec +20 -22
- data/templates/latex/layout.tex.erb +2 -2
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/web/html/layout-html5.html.erb +2 -2
- data/test/assets/black.eps +280 -0
- data/test/assets/fit.png +0 -0
- data/test/assets/large.gif +0 -0
- data/test/assets/large.jpg +0 -0
- data/test/assets/large.png +0 -0
- data/test/assets/large.svg +65 -0
- data/test/assets/test_template.tex +1 -1
- data/test/book_test_helper.rb +2 -2
- data/test/run_test.rb +4 -4
- data/test/sample-book/src/Rakefile +21 -22
- data/test/syntax-book/Gemfile +4 -0
- data/test/syntax-book/Rakefile +72 -0
- data/test/syntax-book/appA.re +22 -0
- data/test/syntax-book/bib.re +6 -0
- data/test/syntax-book/catalog.yml +15 -0
- data/test/syntax-book/ch01.re +136 -0
- data/test/syntax-book/ch02.re +351 -0
- data/test/syntax-book/ch03.re +82 -0
- data/test/syntax-book/config.yml +35 -0
- data/test/syntax-book/images/ball.png +0 -0
- data/test/syntax-book/images/cover.jpg +0 -0
- data/test/syntax-book/images/fractal.png +0 -0
- data/test/syntax-book/images/img3-1.png +0 -0
- data/test/syntax-book/images/inlineicon.jpg +0 -0
- data/test/syntax-book/images/logic.png +0 -0
- data/test/syntax-book/images/logic2.png +0 -0
- data/test/syntax-book/images/puzzle.jpg +0 -0
- data/test/syntax-book/images/table.jpg +0 -0
- data/test/syntax-book/part2.re +6 -0
- data/test/syntax-book/pre01.re +26 -0
- data/test/syntax-book/review-ext.rb +14 -0
- data/test/syntax-book/sty/jumoline.sty +310 -0
- data/test/syntax-book/sty/reviewmacro.sty +39 -0
- data/test/syntax-book/style.css +494 -0
- data/test/syntax-book/syntax.dic +2 -0
- data/test/test_book.rb +106 -111
- data/test/test_book_chapter.rb +21 -22
- data/test/test_book_part.rb +3 -5
- data/test/test_builder.rb +11 -22
- data/test/test_catalog.rb +17 -18
- data/test/test_catalog_converter_cmd.rb +5 -5
- data/test/test_compiler.rb +18 -16
- data/test/test_configure.rb +35 -38
- data/test/test_converter.rb +3 -4
- data/test/test_epub3maker.rb +136 -117
- data/test/test_epubmaker.rb +107 -114
- data/test/test_epubmaker_cmd.rb +2 -4
- data/test/test_extentions_hash.rb +32 -33
- data/test/test_helper.rb +9 -11
- data/test/test_htmlbuilder.rb +454 -420
- data/test/test_htmltoc.rb +8 -12
- data/test/test_htmlutils.rb +0 -2
- data/test/test_i18n.rb +159 -150
- data/test/test_idgxmlbuilder.rb +190 -197
- data/test/test_image_finder.rb +21 -22
- data/test/test_index.rb +24 -29
- data/test/test_latexbuilder.rb +274 -264
- data/test/test_lineinput.rb +7 -10
- data/test/test_location.rb +7 -7
- data/test/test_makerhelper.rb +13 -25
- data/test/test_markdownbuilder.rb +23 -26
- data/test/test_md2inaobuilder.rb +8 -11
- data/test/test_pdfmaker.rb +114 -123
- data/test/test_pdfmaker_cmd.rb +1 -3
- data/test/test_review_ext.rb +3 -5
- data/test/test_rstbuilder.rb +92 -97
- data/test/test_template.rb +3 -7
- data/test/test_textutils.rb +27 -27
- data/test/test_tocparser.rb +2 -2
- data/test/test_topbuilder.rb +98 -103
- data/test/test_webtocprinter.rb +5 -6
- data/test/test_yamlloader.rb +42 -42
- data/test/test_zip_exporter.rb +12 -18
- metadata +86 -9
- data/lib/review/ewbbuilder.rb +0 -382
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
# This program is free software.
|
3
2
|
# You can distribute or modify this program under the terms of
|
4
3
|
# the GNU LGPL, Lesser General Public License version 2.1.
|
@@ -6,26 +5,23 @@
|
|
6
5
|
require 'review/markdownbuilder'
|
7
6
|
|
8
7
|
module ReVIEW
|
9
|
-
|
10
8
|
class MD2INAOBuilder < MARKDOWNBuilder
|
11
9
|
def paragraph(lines)
|
12
|
-
puts
|
10
|
+
puts ' ' + lines.join
|
13
11
|
puts "\n"
|
14
12
|
end
|
15
13
|
|
16
14
|
def list_header(id, caption, lang)
|
17
|
-
lang ||=
|
15
|
+
lang ||= ''
|
18
16
|
puts "```#{lang}"
|
19
|
-
print %Q
|
17
|
+
print %Q(●リスト#{@chapter.list(id).number}::#{compile_inline(caption)}\n\n)
|
20
18
|
end
|
21
19
|
|
22
20
|
def cmd(lines)
|
23
21
|
# WEB+DB では使っていないらしいけど
|
24
|
-
puts
|
25
|
-
lines.each
|
26
|
-
|
27
|
-
end
|
28
|
-
puts ""
|
22
|
+
puts '!!! cmd'
|
23
|
+
lines.each { |line| puts detab(line) }
|
24
|
+
puts ''
|
29
25
|
end
|
30
26
|
|
31
27
|
def dl_begin
|
@@ -51,7 +47,5 @@ module ReVIEW
|
|
51
47
|
%Q[<span class='groupruby'>#{escape_html(base)}(#{escape_html(ruby)})</span>]
|
52
48
|
end
|
53
49
|
end
|
54
|
-
|
55
50
|
end
|
56
|
-
|
57
51
|
end # module ReVIEW
|
data/lib/review/pdfmaker.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
# Copyright (c) 2010-2017 Kenshi Muto and Masayoshi Takahashi
|
4
2
|
#
|
5
3
|
# This program is free software.
|
@@ -23,10 +21,8 @@ require 'review/version'
|
|
23
21
|
require 'review/makerhelper'
|
24
22
|
require 'review/template'
|
25
23
|
|
26
|
-
|
27
24
|
module ReVIEW
|
28
25
|
class PDFMaker
|
29
|
-
|
30
26
|
include FileUtils
|
31
27
|
include ReVIEW::LaTeXUtils
|
32
28
|
|
@@ -35,7 +31,8 @@ module ReVIEW
|
|
35
31
|
def initialize
|
36
32
|
@basedir = nil
|
37
33
|
@basehookdir = nil
|
38
|
-
@
|
34
|
+
@logger = ReVIEW.logger
|
35
|
+
@input_files = Hash.new { |h, key| h[key] = '' }
|
39
36
|
end
|
40
37
|
|
41
38
|
def system_or_raise(*args)
|
@@ -43,16 +40,16 @@ module ReVIEW
|
|
43
40
|
end
|
44
41
|
|
45
42
|
def error(msg)
|
46
|
-
|
43
|
+
@logger.error "#{File.basename($PROGRAM_NAME, '.*')}: #{msg}"
|
47
44
|
exit 1
|
48
45
|
end
|
49
46
|
|
50
47
|
def warn(msg)
|
51
|
-
|
48
|
+
@logger.warn "#{File.basename($PROGRAM_NAME, '.*')}: #{msg}"
|
52
49
|
end
|
53
50
|
|
54
51
|
def pdf_filepath
|
55
|
-
File.join(@basedir, @config[
|
52
|
+
File.join(@basedir, @config['bookname'] + '.pdf')
|
56
53
|
end
|
57
54
|
|
58
55
|
def remove_old_file
|
@@ -60,15 +57,13 @@ module ReVIEW
|
|
60
57
|
end
|
61
58
|
|
62
59
|
def build_path
|
63
|
-
if @config[
|
64
|
-
path = "#{@config[
|
65
|
-
if File.exist?(path)
|
66
|
-
FileUtils.rm_rf(path, :secure => true)
|
67
|
-
end
|
60
|
+
if @config['debug']
|
61
|
+
path = "#{@config['bookname']}-pdf"
|
62
|
+
FileUtils.rm_rf(path, secure: true) if File.exist?(path)
|
68
63
|
Dir.mkdir(path)
|
69
|
-
|
64
|
+
path
|
70
65
|
else
|
71
|
-
|
66
|
+
Dir.mktmpdir("#{@config['bookname']}-pdf-")
|
72
67
|
end
|
73
68
|
end
|
74
69
|
|
@@ -76,9 +71,9 @@ module ReVIEW
|
|
76
71
|
return unless @compile_errors
|
77
72
|
|
78
73
|
if ignore_errors
|
79
|
-
$stderr.puts
|
74
|
+
$stderr.puts 'compile error, but try to generate PDF file'
|
80
75
|
else
|
81
|
-
error
|
76
|
+
error 'compile error, No PDF file output.'
|
82
77
|
end
|
83
78
|
end
|
84
79
|
|
@@ -90,18 +85,14 @@ module ReVIEW
|
|
90
85
|
cmd_config = {}
|
91
86
|
opts = OptionParser.new
|
92
87
|
|
93
|
-
opts.banner =
|
88
|
+
opts.banner = 'Usage: review-pdfmaker configfile'
|
94
89
|
opts.version = ReVIEW::VERSION
|
95
90
|
opts.on('--help', 'Prints this message and quit.') do
|
96
91
|
puts opts.help
|
97
92
|
exit 0
|
98
93
|
end
|
99
|
-
opts.on('--[no-]debug', 'Keep temporary files.')
|
100
|
-
|
101
|
-
end
|
102
|
-
opts.on('--ignore-errors', 'Ignore review-compile errors.') do
|
103
|
-
cmd_config["ignore-errors"] = true
|
104
|
-
end
|
94
|
+
opts.on('--[no-]debug', 'Keep temporary files.') { |debug| cmd_config['debug'] = debug }
|
95
|
+
opts.on('--ignore-errors', 'Ignore review-compile errors.') { cmd_config['ignore-errors'] = true }
|
105
96
|
|
106
97
|
opts.parse!(args)
|
107
98
|
if args.size != 1
|
@@ -109,18 +100,18 @@ module ReVIEW
|
|
109
100
|
exit 0
|
110
101
|
end
|
111
102
|
|
112
|
-
|
103
|
+
[cmd_config, args[0]]
|
113
104
|
end
|
114
105
|
|
115
106
|
def execute(*args)
|
116
107
|
@config = ReVIEW::Configure.values
|
117
|
-
@config.maker =
|
108
|
+
@config.maker = 'pdfmaker'
|
118
109
|
cmd_config, yamlfile = parse_opts(args)
|
119
110
|
loader = ReVIEW::YAMLLoader.new
|
120
111
|
@config.deep_merge!(loader.load_file(yamlfile))
|
121
112
|
# YAML configs will be overridden by command line options.
|
122
113
|
@config.merge!(cmd_config)
|
123
|
-
I18n.setup(@config[
|
114
|
+
I18n.setup(@config['language'])
|
124
115
|
@basedir = File.dirname(yamlfile)
|
125
116
|
@basehookdir = File.absolute_path(File.dirname(yamlfile))
|
126
117
|
|
@@ -133,24 +124,24 @@ module ReVIEW
|
|
133
124
|
end
|
134
125
|
|
135
126
|
def make_input_files(book, yamlfile)
|
136
|
-
input_files = Hash.new{|h, key| h[key] =
|
127
|
+
input_files = Hash.new { |h, key| h[key] = '' }
|
137
128
|
book.parts.each do |part|
|
138
129
|
if part.name.present?
|
139
130
|
if part.file?
|
140
131
|
output_chaps(part.name, yamlfile)
|
141
|
-
input_files[
|
132
|
+
input_files['CHAPS'] << %Q(\\input{#{part.name}.tex}\n)
|
142
133
|
else
|
143
|
-
input_files[
|
134
|
+
input_files['CHAPS'] << %Q(\\part{#{part.name}}\n)
|
144
135
|
end
|
145
136
|
end
|
146
137
|
|
147
138
|
part.chapters.each do |chap|
|
148
|
-
filename = File.basename(chap.path,
|
139
|
+
filename = File.basename(chap.path, '.*')
|
149
140
|
output_chaps(filename, yamlfile)
|
150
|
-
input_files[
|
151
|
-
input_files[
|
152
|
-
input_files[
|
153
|
-
input_files[
|
141
|
+
input_files['PREDEF'] << "\\input{#{filename}.tex}\n" if chap.on_predef?
|
142
|
+
input_files['CHAPS'] << "\\input{#{filename}.tex}\n" if chap.on_chaps?
|
143
|
+
input_files['APPENDIX'] << "\\input{#{filename}.tex}\n" if chap.on_appendix?
|
144
|
+
input_files['POSTDEF'] << "\\input{#{filename}.tex}\n" if chap.on_postdef?
|
154
145
|
end
|
155
146
|
end
|
156
147
|
|
@@ -158,32 +149,32 @@ module ReVIEW
|
|
158
149
|
end
|
159
150
|
|
160
151
|
def build_pdf
|
161
|
-
template =
|
152
|
+
template = template_content
|
162
153
|
Dir.chdir(@path) do
|
163
|
-
File.open(
|
154
|
+
File.open('./book.tex', 'wb') { |f| f.write(template) }
|
164
155
|
|
165
|
-
call_hook(
|
156
|
+
call_hook('hook_beforetexcompile')
|
166
157
|
|
167
158
|
## do compile
|
168
|
-
if ENV[
|
169
|
-
warn
|
170
|
-
texcommand = ReVIEW::Configure.values[
|
171
|
-
dvicommand = ReVIEW::Configure.values[
|
172
|
-
dvioptions = ReVIEW::Configure.values[
|
173
|
-
texoptions = ReVIEW::Configure.values[
|
174
|
-
makeindex_command = ReVIEW::Configure.values[
|
175
|
-
makeindex_options = ReVIEW::Configure.values[
|
176
|
-
makeindex_sty = ReVIEW::Configure.values[
|
177
|
-
makeindex_dic = ReVIEW::Configure.values[
|
159
|
+
if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
|
160
|
+
warn 'command configuration is prohibited in safe mode. ignored.'
|
161
|
+
texcommand = ReVIEW::Configure.values['texcommand']
|
162
|
+
dvicommand = ReVIEW::Configure.values['dvicommand']
|
163
|
+
dvioptions = ReVIEW::Configure.values['dvioptions']
|
164
|
+
texoptions = ReVIEW::Configure.values['texoptions']
|
165
|
+
makeindex_command = ReVIEW::Configure.values['pdfmaker']['makeindex_command']
|
166
|
+
makeindex_options = ReVIEW::Configure.values['pdfmaker']['makeindex_options']
|
167
|
+
makeindex_sty = ReVIEW::Configure.values['pdfmaker']['makeindex_sty']
|
168
|
+
makeindex_dic = ReVIEW::Configure.values['pdfmaker']['makeindex_dic']
|
178
169
|
else
|
179
|
-
texcommand = @config[
|
180
|
-
dvicommand = @config[
|
181
|
-
dvioptions = @config[
|
182
|
-
texoptions = @config[
|
183
|
-
makeindex_command = @config[
|
184
|
-
makeindex_options = @config[
|
185
|
-
makeindex_sty = @config[
|
186
|
-
makeindex_dic = @config[
|
170
|
+
texcommand = @config['texcommand'] if @config['texcommand']
|
171
|
+
dvicommand = @config['dvicommand'] if @config['dvicommand']
|
172
|
+
dvioptions = @config['dvioptions'] if @config['dvioptions']
|
173
|
+
texoptions = @config['texoptions'] if @config['texoptions']
|
174
|
+
makeindex_command = @config['pdfmaker']['makeindex_command']
|
175
|
+
makeindex_options = @config['pdfmaker']['makeindex_options']
|
176
|
+
makeindex_sty = @config['pdfmaker']['makeindex_sty']
|
177
|
+
makeindex_dic = @config['pdfmaker']['makeindex_dic']
|
187
178
|
end
|
188
179
|
|
189
180
|
if makeindex_sty.present?
|
@@ -199,23 +190,23 @@ module ReVIEW
|
|
199
190
|
system_or_raise("#{texcommand} #{texoptions} book.tex")
|
200
191
|
end
|
201
192
|
|
202
|
-
call_hook(
|
203
|
-
system_or_raise("#{makeindex_command} #{makeindex_options} book") if @config[
|
204
|
-
call_hook(
|
193
|
+
call_hook('hook_beforemakeindex')
|
194
|
+
system_or_raise("#{makeindex_command} #{makeindex_options} book") if @config['pdfmaker']['makeindex'] && File.exist?('book.idx')
|
195
|
+
call_hook('hook_aftermakeindex')
|
205
196
|
|
206
197
|
system_or_raise("#{texcommand} #{texoptions} book.tex")
|
207
|
-
call_hook(
|
198
|
+
call_hook('hook_aftertexcompile')
|
208
199
|
|
209
|
-
if File.exist?(
|
200
|
+
if File.exist?('book.dvi')
|
210
201
|
system_or_raise("#{dvicommand} #{dvioptions} book.dvi")
|
211
|
-
call_hook(
|
202
|
+
call_hook('hook_afterdvipdf')
|
212
203
|
end
|
213
204
|
end
|
214
205
|
end
|
215
206
|
|
216
207
|
def generate_pdf(yamlfile)
|
217
208
|
remove_old_file
|
218
|
-
@path = build_path
|
209
|
+
@path = build_path
|
219
210
|
begin
|
220
211
|
@compile_errors = nil
|
221
212
|
|
@@ -225,33 +216,29 @@ module ReVIEW
|
|
225
216
|
|
226
217
|
@input_files = make_input_files(book, yamlfile)
|
227
218
|
|
228
|
-
check_compile_status(@config[
|
219
|
+
check_compile_status(@config['ignore-errors'])
|
229
220
|
|
230
|
-
@config[
|
231
|
-
if @config[
|
232
|
-
@config["usepackage"] = "\\usepackage{#{@config['texstyle']}}"
|
233
|
-
end
|
221
|
+
@config['usepackage'] = ''
|
222
|
+
@config['usepackage'] = "\\usepackage{#{@config['texstyle']}}" if @config['texstyle']
|
234
223
|
|
235
|
-
copy_images(@config[
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
224
|
+
copy_images(@config['imagedir'], File.join(@path, @config['imagedir']))
|
225
|
+
copy_sty(File.join(Dir.pwd, 'sty'), @path)
|
226
|
+
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'fd')
|
227
|
+
copy_sty(File.join(Dir.pwd, 'sty'), @path, 'cls')
|
228
|
+
copy_sty(Dir.pwd, @path, 'tex')
|
240
229
|
|
241
230
|
build_pdf
|
242
231
|
|
243
|
-
FileUtils.cp(File.join(@path,
|
232
|
+
FileUtils.cp(File.join(@path, 'book.pdf'), pdf_filepath)
|
244
233
|
ensure
|
245
|
-
unless @config[
|
246
|
-
remove_entry_secure @path
|
247
|
-
end
|
234
|
+
remove_entry_secure @path unless @config['debug']
|
248
235
|
end
|
249
236
|
end
|
250
237
|
|
251
|
-
def output_chaps(filename,
|
238
|
+
def output_chaps(filename, _yamlfile)
|
252
239
|
$stderr.puts "compiling #{filename}.tex"
|
253
240
|
begin
|
254
|
-
@converter.convert(filename+
|
241
|
+
@converter.convert(filename + '.re', File.join(@path, filename + '.tex'))
|
255
242
|
rescue => e
|
256
243
|
@compile_errors = true
|
257
244
|
warn "compile error in #{filename}.tex (#{e.class})"
|
@@ -262,33 +249,25 @@ module ReVIEW
|
|
262
249
|
# PDFMaker#copy_images should copy image files _AND_ execute extractbb (or ebb).
|
263
250
|
#
|
264
251
|
def copy_images(from, to)
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
system("extractbb", *images)
|
274
|
-
unless system("extractbb", "-m", *images)
|
275
|
-
system_or_raise("ebb", *images)
|
276
|
-
end
|
277
|
-
end
|
252
|
+
return unless File.exist?(from)
|
253
|
+
Dir.mkdir(to)
|
254
|
+
ReVIEW::MakerHelper.copy_images_to_dir(from, to)
|
255
|
+
Dir.chdir(to) do
|
256
|
+
images = Dir.glob('**/*').find_all { |f| File.file?(f) and f =~ /\.(jpg|jpeg|png|pdf|ai|eps|tif)\z/ }
|
257
|
+
break if images.empty?
|
258
|
+
system('extractbb', *images)
|
259
|
+
system_or_raise('ebb', *images) unless system('extractbb', '-m', *images)
|
278
260
|
end
|
279
261
|
end
|
280
262
|
|
281
263
|
def make_custom_page(file)
|
282
|
-
file_sty = file.to_s.sub(/\.[^.]
|
283
|
-
if File.exist?(file_sty)
|
284
|
-
|
285
|
-
else
|
286
|
-
nil
|
287
|
-
end
|
264
|
+
file_sty = file.to_s.sub(/\.[^.]+\Z/, '.tex')
|
265
|
+
return File.read(file_sty) if File.exist?(file_sty)
|
266
|
+
nil
|
288
267
|
end
|
289
268
|
|
290
269
|
def join_with_separator(value, sep)
|
291
|
-
if value.
|
270
|
+
if value.is_a?(Array)
|
292
271
|
value.join(sep)
|
293
272
|
else
|
294
273
|
value
|
@@ -297,61 +276,56 @@ module ReVIEW
|
|
297
276
|
|
298
277
|
def make_colophon_role(role)
|
299
278
|
if @config[role].present?
|
300
|
-
initialize_metachars(@config[
|
301
|
-
|
279
|
+
initialize_metachars(@config['texcommand'])
|
280
|
+
"#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(@config.names_of(role), ReVIEW::I18n.t('names_splitter')))} \\\\\n"
|
302
281
|
else
|
303
|
-
|
282
|
+
''
|
304
283
|
end
|
305
284
|
end
|
306
285
|
|
307
286
|
def make_colophon
|
308
|
-
colophon =
|
309
|
-
@config[
|
310
|
-
colophon += make_colophon_role(role)
|
311
|
-
end
|
287
|
+
colophon = ''
|
288
|
+
@config['colophon_order'].each { |role| colophon += make_colophon_role(role) }
|
312
289
|
colophon
|
313
290
|
end
|
314
291
|
|
315
292
|
def make_authors
|
316
|
-
authors =
|
317
|
-
if @config[
|
318
|
-
author_names = join_with_separator(@config.names_of(
|
319
|
-
authors = ReVIEW::I18n.t(
|
293
|
+
authors = ''
|
294
|
+
if @config['aut'].present?
|
295
|
+
author_names = join_with_separator(@config.names_of('aut').map { |s| escape_latex(s) }, ReVIEW::I18n.t('names_splitter'))
|
296
|
+
authors = ReVIEW::I18n.t('author_with_label', author_names)
|
320
297
|
end
|
321
|
-
if @config[
|
322
|
-
csl_names = join_with_separator(@config.names_of(
|
323
|
-
authors += " \\\\\n"+ ReVIEW::I18n.t(
|
298
|
+
if @config['csl'].present?
|
299
|
+
csl_names = join_with_separator(@config.names_of('csl').map { |s| escape_latex(s) }, ReVIEW::I18n.t('names_splitter'))
|
300
|
+
authors += " \\\\\n" + ReVIEW::I18n.t('supervisor_with_label', csl_names)
|
324
301
|
end
|
325
|
-
if @config[
|
326
|
-
trl_names = join_with_separator(@config.names_of(
|
327
|
-
authors += " \\\\\n"+ ReVIEW::I18n.t(
|
302
|
+
if @config['trl'].present?
|
303
|
+
trl_names = join_with_separator(@config.names_of('trl').map { |s| escape_latex(s) }, ReVIEW::I18n.t('names_splitter'))
|
304
|
+
authors += " \\\\\n" + ReVIEW::I18n.t('translator_with_label', trl_names)
|
328
305
|
end
|
329
306
|
authors
|
330
307
|
end
|
331
308
|
|
332
309
|
def make_history_list
|
333
310
|
buf = []
|
334
|
-
if @config[
|
335
|
-
@config[
|
311
|
+
if @config['history']
|
312
|
+
@config['history'].each_with_index do |items, edit|
|
336
313
|
items.each_with_index do |item, rev|
|
337
|
-
editstr =
|
338
|
-
revstr = ReVIEW::I18n.t(
|
314
|
+
editstr = edit == 0 ? ReVIEW::I18n.t('first_edition') : ReVIEW::I18n.t('nth_edition', (edit + 1).to_s)
|
315
|
+
revstr = ReVIEW::I18n.t('nth_impression', (rev + 1).to_s)
|
339
316
|
if item =~ /\A\d+\-\d+\-\d+\Z/
|
340
|
-
buf << ReVIEW::I18n.t(
|
317
|
+
buf << ReVIEW::I18n.t('published_by1', [date_to_s(item), editstr + revstr])
|
341
318
|
elsif item =~ /\A(\d+\-\d+\-\d+)[\s ](.+)/
|
342
319
|
# custom date with string
|
343
|
-
item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/)
|
344
|
-
buf << ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])
|
345
|
-
end
|
320
|
+
item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) { |m| buf << ReVIEW::I18n.t('published_by3', [date_to_s(m[1]), m[2]]) }
|
346
321
|
else
|
347
322
|
# free format
|
348
323
|
buf << item
|
349
324
|
end
|
350
325
|
end
|
351
326
|
end
|
352
|
-
elsif @config[
|
353
|
-
buf << ReVIEW::I18n.t(
|
354
|
-
date_to_s(@config["date"]))
|
327
|
+
elsif @config['date']
|
328
|
+
buf << ReVIEW::I18n.t('published_by2', date_to_s(@config['date']))
|
355
329
|
end
|
356
330
|
buf
|
357
331
|
end
|
@@ -359,63 +333,61 @@ module ReVIEW
|
|
359
333
|
def date_to_s(date)
|
360
334
|
require 'date'
|
361
335
|
d = Date.parse(date)
|
362
|
-
d.strftime(ReVIEW::I18n.t(
|
336
|
+
d.strftime(ReVIEW::I18n.t('date_format'))
|
363
337
|
end
|
364
338
|
|
365
|
-
def
|
366
|
-
dclass = @config[
|
367
|
-
@documentclass = dclass[0] ||
|
368
|
-
@documentclassoption = dclass[1] ||
|
339
|
+
def template_content
|
340
|
+
dclass = @config['texdocumentclass'] || []
|
341
|
+
@documentclass = dclass[0] || 'jsbook'
|
342
|
+
@documentclassoption = dclass[1] || 'uplatex,oneside'
|
369
343
|
|
370
344
|
@okuduke = make_colophon
|
371
345
|
@authors = make_authors
|
372
346
|
|
373
|
-
@custom_titlepage = make_custom_page(@config[
|
374
|
-
@custom_originaltitlepage = make_custom_page(@config[
|
375
|
-
@custom_creditpage = make_custom_page(@config[
|
347
|
+
@custom_titlepage = make_custom_page(@config['cover']) || make_custom_page(@config['coverfile'])
|
348
|
+
@custom_originaltitlepage = make_custom_page(@config['originaltitlefile'])
|
349
|
+
@custom_creditpage = make_custom_page(@config['creditfile'])
|
376
350
|
|
377
|
-
@custom_profilepage = make_custom_page(@config[
|
378
|
-
@custom_advfilepage = make_custom_page(@config[
|
379
|
-
if @config[
|
380
|
-
|
381
|
-
end
|
382
|
-
@custom_backcoverpage = make_custom_page(@config["backcover"])
|
351
|
+
@custom_profilepage = make_custom_page(@config['profile'])
|
352
|
+
@custom_advfilepage = make_custom_page(@config['advfile'])
|
353
|
+
@custom_colophonpage = make_custom_page(@config['colophon']) if @config['colophon'] && @config['colophon'].is_a?(String)
|
354
|
+
@custom_backcoverpage = make_custom_page(@config['backcover'])
|
383
355
|
|
384
|
-
if @config[
|
385
|
-
warn
|
386
|
-
else
|
387
|
-
@config["pubhistory"] = make_history_list.join("\n")
|
388
|
-
end
|
389
|
-
if @documentclass == "ubook" || @documentclass == "utbook"
|
390
|
-
@coverimageoption = "width=\\textheight,height=\\textwidth,keepaspectratio,angle=90"
|
356
|
+
if @config['pubhistory']
|
357
|
+
warn 'pubhistory is oboleted. use history.'
|
391
358
|
else
|
392
|
-
@
|
359
|
+
@config['pubhistory'] = make_history_list.join("\n")
|
393
360
|
end
|
394
361
|
|
362
|
+
@coverimageoption =
|
363
|
+
if @documentclass == 'ubook' || @documentclass == 'utbook'
|
364
|
+
'width=\\textheight,height=\\textwidth,keepaspectratio,angle=90'
|
365
|
+
else
|
366
|
+
'width=\\textwidth,height=\\textheight,keepaspectratio'
|
367
|
+
end
|
368
|
+
|
395
369
|
@locale_latex = {}
|
396
|
-
part_tuple = I18n.get(
|
397
|
-
chapter_tuple = I18n.get(
|
398
|
-
appendix_tuple = I18n.get(
|
399
|
-
@locale_latex[
|
400
|
-
@locale_latex[
|
401
|
-
@locale_latex[
|
402
|
-
@locale_latex[
|
403
|
-
@locale_latex[
|
404
|
-
@locale_latex[
|
370
|
+
part_tuple = I18n.get('part').split(/\%[A-Za-z]{1,3}/, 2)
|
371
|
+
chapter_tuple = I18n.get('chapter').split(/\%[A-Za-z]{1,3}/, 2)
|
372
|
+
appendix_tuple = I18n.get('appendix').split(/\%[A-Za-z]{1,3}/, 2)
|
373
|
+
@locale_latex['prepartname'] = part_tuple[0]
|
374
|
+
@locale_latex['postpartname'] = part_tuple[1]
|
375
|
+
@locale_latex['prechaptername'] = chapter_tuple[0]
|
376
|
+
@locale_latex['postchaptername'] = chapter_tuple[1]
|
377
|
+
@locale_latex['preappendixname'] = appendix_tuple[0]
|
378
|
+
@locale_latex['postappendixname'] = appendix_tuple[1]
|
405
379
|
|
406
380
|
template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
|
407
|
-
layout_file = File.join(@basedir,
|
408
|
-
if File.exist?(layout_file)
|
409
|
-
template = layout_file
|
410
|
-
end
|
381
|
+
layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
|
382
|
+
template = layout_file if File.exist?(layout_file)
|
411
383
|
|
412
|
-
@texcompiler = File.basename(@config[
|
384
|
+
@texcompiler = File.basename(@config['texcommand'], '.*')
|
413
385
|
|
414
386
|
erb = ReVIEW::Template.load(template, '-')
|
415
387
|
erb.result(binding)
|
416
388
|
end
|
417
389
|
|
418
|
-
def
|
390
|
+
def copy_sty(dirname, copybase, extname = 'sty')
|
419
391
|
unless File.directory?(dirname)
|
420
392
|
warn "No such directory - #{dirname}"
|
421
393
|
return
|
@@ -423,7 +395,7 @@ module ReVIEW
|
|
423
395
|
|
424
396
|
Dir.open(dirname) do |dir|
|
425
397
|
dir.each do |fname|
|
426
|
-
if File.extname(fname).downcase ==
|
398
|
+
if File.extname(fname).downcase == '.' + extname
|
427
399
|
FileUtils.mkdir_p(copybase)
|
428
400
|
FileUtils.cp File.join(dirname, fname), copybase
|
429
401
|
end
|
@@ -432,15 +404,13 @@ module ReVIEW
|
|
432
404
|
end
|
433
405
|
|
434
406
|
def call_hook(hookname)
|
435
|
-
if
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
end
|
407
|
+
return if !@config['pdfmaker'].is_a?(Hash) || @config['pdfmaker'][hookname].nil?
|
408
|
+
hook = File.absolute_path(@config['pdfmaker'][hookname], @basehookdir)
|
409
|
+
if ENV['REVIEW_SAFE_MODE'].to_i & 1 > 0
|
410
|
+
warn 'hook configuration is prohibited in safe mode. ignored.'
|
411
|
+
else
|
412
|
+
system_or_raise("#{hook} #{Dir.pwd} #{@basehookdir}")
|
442
413
|
end
|
443
414
|
end
|
444
415
|
end
|
445
416
|
end
|
446
|
-
|