review 2.0.0.beta1 → 2.0.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 +66 -1
- data/.rubocop_todo.yml +617 -0
- data/.travis.yml +16 -1
- data/ChangeLog +48 -0
- data/Dockerfile +22 -0
- data/Gemfile +0 -1
- data/README.md +97 -0
- data/Rakefile +10 -11
- data/appveyor.yml +9 -0
- data/bin/review +46 -0
- data/bin/review-check +8 -21
- data/bin/review-compile +26 -43
- data/bin/review-index +9 -22
- data/bin/review-init +21 -25
- data/bin/review-preproc +9 -13
- data/bin/review-validate +1 -1
- data/bin/review-vol +3 -17
- data/bin/review-webmaker +15 -0
- data/doc/NEWS.ja.md +534 -0
- data/doc/NEWS.md +538 -0
- data/doc/catalog.ja.md +10 -18
- data/doc/catalog.md +5 -9
- data/doc/config.yml.sample +319 -0
- data/doc/customize_epub.ja.md +42 -0
- data/doc/format.ja.md +320 -288
- data/doc/format.md +277 -170
- data/doc/format_idg.ja.md +82 -175
- data/doc/pdfmaker.ja.md +61 -0
- data/doc/pdfmaker.md +65 -0
- data/doc/quickstart.ja.md +88 -98
- data/doc/quickstart.md +72 -110
- data/doc/sample.css +41 -0
- data/doc/writing_vertical.ja.md +55 -0
- data/doc/writing_vertical.md +5 -0
- data/lib/epubmaker/content.rb +3 -3
- data/lib/epubmaker/epubcommon.rb +173 -145
- data/lib/epubmaker/epubv2.rb +24 -77
- data/lib/epubmaker/epubv3.rb +72 -73
- data/lib/epubmaker/producer.rb +54 -30
- data/lib/lineinput.rb +48 -0
- data/lib/review/book.rb +0 -1
- data/lib/review/book/base.rb +47 -27
- data/lib/review/book/chapter.rb +48 -19
- data/lib/review/book/compilable.rb +10 -14
- data/lib/review/book/index.rb +10 -19
- data/lib/review/book/page_metric.rb +0 -10
- data/lib/review/book/part.rb +17 -3
- data/lib/review/builder.rb +84 -68
- data/lib/review/catalog.rb +5 -1
- data/lib/review/compiler.rb +327 -4657
- data/lib/review/configure.rb +84 -10
- data/lib/review/converter.rb +28 -0
- data/lib/review/epubbuilder.rb +1 -1
- data/lib/review/epubmaker.rb +142 -158
- data/lib/review/ewbbuilder.rb +5 -5
- data/lib/review/exception.rb +1 -1
- data/lib/review/extentions.rb +1 -1
- data/lib/review/extentions/hash.rb +15 -0
- data/lib/review/extentions/string.rb +2 -1
- data/lib/review/htmlbuilder.rb +364 -348
- data/lib/review/htmltoc.rb +44 -0
- data/lib/review/htmlutils.rb +12 -6
- data/lib/review/i18n.rb +78 -6
- data/lib/review/i18n.yml +7 -4
- data/lib/review/idgxmlbuilder.rb +226 -267
- data/lib/review/latexbuilder.rb +281 -274
- data/lib/review/latexutils.rb +56 -49
- data/lib/review/makerhelper.rb +8 -4
- data/lib/review/markdownbuilder.rb +80 -124
- data/lib/review/pdfmaker.rb +197 -138
- data/lib/review/preprocessor.rb +16 -67
- data/lib/review/template.rb +24 -0
- data/lib/review/textbuilder.rb +1 -1
- data/lib/review/textutils.rb +18 -24
- data/lib/review/tocparser.rb +51 -106
- data/lib/review/tocprinter.rb +61 -117
- data/lib/review/topbuilder.rb +119 -126
- data/lib/review/unfold.rb +2 -2
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +302 -0
- data/lib/review/webtocprinter.rb +48 -0
- data/lib/review/yamlloader.rb +47 -0
- data/review.gemspec +3 -3
- data/templates/html/layout-html5.html.erb +17 -0
- data/templates/html/layout-xhtml1.html.erb +20 -0
- data/{lib/review → templates/latex}/layout.tex.erb +107 -115
- data/templates/ncx/epubv2.ncx.erb +11 -0
- data/templates/opf/epubv2.opf.erb +21 -0
- data/templates/opf/epubv3.opf.erb +18 -0
- data/templates/web/html/layout-html5.html.erb +56 -0
- data/templates/web/html/layout-xhtml1.html.erb +20 -0
- data/templates/xml/container.xml.erb +6 -0
- data/test/assets/test.xml.erb +3 -0
- data/test/assets/test_template.tex +28 -71
- data/test/assets/test_template_backmatter.tex +1 -9
- data/test/sample-book/src/Rakefile +12 -3
- data/{doc/sample.yml → test/sample-book/src/config-epub2.yml} +92 -147
- data/test/sample-book/src/config.yml +40 -154
- data/test/sample-book/src/style-web.css +45 -0
- data/test/sample-book/src/style.css +23 -1
- data/test/test.re +1 -1
- data/test/test_book.rb +15 -17
- data/test/test_book_chapter.rb +2 -80
- data/test/test_book_part.rb +1 -1
- data/test/test_builder.rb +28 -6
- data/test/test_catalog.rb +17 -0
- data/test/test_compiler.rb +14 -59
- data/test/test_configure.rb +94 -0
- data/test/test_converter.rb +21 -0
- data/test/test_epub3maker.rb +155 -3
- data/test/test_epubmaker.rb +245 -30
- data/test/test_epubmaker_cmd.rb +2 -2
- data/test/test_extentions_hash.rb +60 -0
- data/test/test_helper.rb +4 -47
- data/test/test_htmlbuilder.rb +282 -175
- data/test/test_htmltoc.rb +33 -0
- data/test/test_i18n.rb +134 -70
- data/test/test_idgxmlbuilder.rb +58 -39
- data/test/test_latexbuilder.rb +132 -14
- data/test/test_lineinput.rb +5 -26
- data/test/test_makerhelper.rb +6 -4
- data/test/test_markdownbuilder.rb +23 -5
- data/test/test_pdfmaker.rb +86 -20
- data/test/test_pdfmaker_cmd.rb +1 -3
- data/test/test_review_ext.rb +1 -1
- data/test/test_template.rb +27 -0
- data/test/test_textutils.rb +36 -0
- data/test/test_tocparser.rb +25 -0
- data/test/test_topbuilder.rb +34 -2
- data/test/test_yamlloader.rb +188 -0
- metadata +71 -29
- data/README.rdoc +0 -81
- data/bin/review-epubmaker-legacy +0 -1024
- data/doc/ruby-uuid/README +0 -11
- data/doc/ruby-uuid/README.ja +0 -34
- data/lib/review/compiler/literals_1_8.kpeg +0 -19
- data/lib/review/compiler/literals_1_8.rb +0 -432
- data/lib/review/compiler/literals_1_9.kpeg +0 -22
- data/lib/review/compiler/literals_1_9.rb +0 -435
- data/lib/review/extentions/array.rb +0 -25
- data/lib/review/htmllayout.rb +0 -41
- data/lib/review/inaobuilder.rb +0 -357
- data/lib/review/location.rb +0 -24
- data/lib/review/node.rb +0 -267
- data/lib/review/review.kpeg +0 -724
- data/lib/uuid.rb +0 -312
- data/rubocop-todo.yml +0 -456
- data/test/test_inaobuilder.rb +0 -247
- data/test/test_uuid.rb +0 -157
data/lib/review/pdfmaker.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2010-
|
3
|
+
# Copyright (c) 2010-2016 Kenshi Muto and Masayoshi Takahashi
|
4
4
|
#
|
5
5
|
# This program is free software.
|
6
6
|
# You can distribute or modify this program under the terms of
|
@@ -11,9 +11,17 @@ require 'optparse'
|
|
11
11
|
require 'yaml'
|
12
12
|
require 'fileutils'
|
13
13
|
require 'erb'
|
14
|
+
require 'tmpdir'
|
14
15
|
|
15
|
-
require 'review'
|
16
16
|
require 'review/i18n'
|
17
|
+
require 'review/book'
|
18
|
+
require 'review/configure'
|
19
|
+
require 'review/converter'
|
20
|
+
require 'review/latexbuilder'
|
21
|
+
require 'review/yamlloader'
|
22
|
+
require 'review/version'
|
23
|
+
require 'review/makerhelper'
|
24
|
+
require 'review/template'
|
17
25
|
|
18
26
|
|
19
27
|
module ReVIEW
|
@@ -22,8 +30,11 @@ module ReVIEW
|
|
22
30
|
include FileUtils
|
23
31
|
include ReVIEW::LaTeXUtils
|
24
32
|
|
33
|
+
attr_accessor :config, :basedir
|
34
|
+
|
25
35
|
def initialize
|
26
|
-
@basedir =
|
36
|
+
@basedir = nil
|
37
|
+
@input_files = Hash.new{|h, key| h[key] = ""}
|
27
38
|
end
|
28
39
|
|
29
40
|
def system_or_raise(*args)
|
@@ -39,13 +50,25 @@ module ReVIEW
|
|
39
50
|
$stderr.puts "#{File.basename($0, '.*')}: warning: #{msg}"
|
40
51
|
end
|
41
52
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
53
|
+
def pdf_filepath
|
54
|
+
File.join(@basedir, @config["bookname"]+".pdf")
|
55
|
+
end
|
56
|
+
|
57
|
+
def remove_old_file
|
58
|
+
FileUtils.rm_f(pdf_filepath)
|
45
59
|
end
|
46
60
|
|
47
|
-
def build_path
|
48
|
-
|
61
|
+
def build_path
|
62
|
+
if @config["debug"]
|
63
|
+
path = "#{@config["bookname"]}-pdf"
|
64
|
+
if File.exist?(path)
|
65
|
+
FileUtils.rm_rf(path, :secure => true)
|
66
|
+
end
|
67
|
+
Dir.mkdir(path)
|
68
|
+
return path
|
69
|
+
else
|
70
|
+
return Dir.mktmpdir("#{@config["bookname"]}-pdf-")
|
71
|
+
end
|
49
72
|
end
|
50
73
|
|
51
74
|
def check_compile_status(ignore_errors)
|
@@ -89,120 +112,114 @@ module ReVIEW
|
|
89
112
|
end
|
90
113
|
|
91
114
|
def execute(*args)
|
92
|
-
config = ReVIEW::Configure.values
|
115
|
+
@config = ReVIEW::Configure.values
|
116
|
+
@config.maker = "pdfmaker"
|
93
117
|
cmd_config, yamlfile = parse_opts(args)
|
94
|
-
|
95
|
-
config.
|
118
|
+
loader = ReVIEW::YAMLLoader.new
|
119
|
+
@config.deep_merge!(loader.load_file(yamlfile))
|
96
120
|
# YAML configs will be overridden by command line options.
|
97
|
-
config.merge!(cmd_config)
|
98
|
-
I18n.setup(config["language"])
|
99
|
-
|
121
|
+
@config.merge!(cmd_config)
|
122
|
+
I18n.setup(@config["language"])
|
123
|
+
@basedir = File.dirname(yamlfile)
|
124
|
+
|
125
|
+
begin
|
126
|
+
@config.check_version(ReVIEW::VERSION)
|
127
|
+
rescue ReVIEW::ConfigError => e
|
128
|
+
warn e.message
|
129
|
+
end
|
130
|
+
generate_pdf(yamlfile)
|
100
131
|
end
|
101
132
|
|
102
|
-
def generate_pdf(
|
103
|
-
|
104
|
-
@path = build_path(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
@chaps_fnames["CHAPS"] << %Q|\\part{#{part.name}}\n|
|
133
|
+
def generate_pdf(yamlfile)
|
134
|
+
remove_old_file
|
135
|
+
@path = build_path()
|
136
|
+
begin
|
137
|
+
@compile_errors = nil
|
138
|
+
|
139
|
+
book = ReVIEW::Book.load(@basedir)
|
140
|
+
book.config = @config
|
141
|
+
@converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new)
|
142
|
+
book.parts.each do |part|
|
143
|
+
if part.name.present?
|
144
|
+
if part.file?
|
145
|
+
output_chaps(part.name, yamlfile)
|
146
|
+
@input_files["CHAPS"] << %Q|\\input{#{part.name}.tex}\n|
|
147
|
+
else
|
148
|
+
@input_files["CHAPS"] << %Q|\\part{#{part.name}}\n|
|
149
|
+
end
|
120
150
|
end
|
121
|
-
end
|
122
151
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
152
|
+
part.chapters.each do |chap|
|
153
|
+
filename = File.basename(chap.path, ".*")
|
154
|
+
output_chaps(filename, yamlfile)
|
155
|
+
@input_files["PREDEF"] << "\\input{#{filename}.tex}\n" if chap.on_PREDEF?
|
156
|
+
@input_files["CHAPS"] << "\\input{#{filename}.tex}\n" if chap.on_CHAPS?
|
157
|
+
@input_files["APPENDIX"] << "\\input{#{filename}.tex}\n" if chap.on_APPENDIX?
|
158
|
+
@input_files["POSTDEF"] << "\\input{#{filename}.tex}\n" if chap.on_POSTDEF?
|
159
|
+
end
|
130
160
|
end
|
131
|
-
end
|
132
|
-
|
133
|
-
check_compile_status(config["ignore-errors"])
|
134
161
|
|
135
|
-
|
136
|
-
config["chap_str"] = @chaps_fnames["CHAPS"]
|
137
|
-
config["appendix_str"] = @chaps_fnames["APPENDIX"]
|
138
|
-
config["post_str"] = @chaps_fnames["POSTDEF"]
|
162
|
+
check_compile_status(@config["ignore-errors"])
|
139
163
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
164
|
+
@config["usepackage"] = ""
|
165
|
+
if @config["texstyle"]
|
166
|
+
@config["usepackage"] = "\\usepackage{#{@config['texstyle']}}"
|
167
|
+
end
|
144
168
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
169
|
+
copy_images("./images", File.join(@path, "images"))
|
170
|
+
copyStyToDir(File.join(Dir.pwd, "sty"), @path)
|
171
|
+
copyStyToDir(File.join(Dir.pwd, "sty"), @path, "fd")
|
172
|
+
copyStyToDir(File.join(Dir.pwd, "sty"), @path, "cls")
|
173
|
+
copyStyToDir(Dir.pwd, @path, "tex")
|
150
174
|
|
151
|
-
|
152
|
-
|
153
|
-
|
175
|
+
template = get_template
|
176
|
+
Dir.chdir(@path) do
|
177
|
+
File.open("./book.tex", "wb"){|f| f.write(template)}
|
154
178
|
|
155
|
-
|
179
|
+
call_hook("hook_beforetexcompile")
|
156
180
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
181
|
+
## do compile
|
182
|
+
if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
|
183
|
+
warn "command configuration is prohibited in safe mode. ignored."
|
184
|
+
else
|
185
|
+
texcommand = @config["texcommand"] if @config["texcommand"]
|
186
|
+
dvicommand = @config["dvicommand"] if @config["dvicommand"]
|
187
|
+
dvioptions = @config["dvioptions"] if @config["dvioptions"]
|
188
|
+
texoptions = @config["texoptions"] if @config["texoptions"]
|
189
|
+
end
|
190
|
+
3.times do
|
191
|
+
system_or_raise("#{texcommand} #{texoptions} book.tex")
|
192
|
+
end
|
193
|
+
call_hook("hook_aftertexcompile")
|
164
194
|
|
165
|
-
|
166
|
-
|
167
|
-
else
|
168
|
-
texcommand = config["texcommand"] if config["texcommand"]
|
169
|
-
dvicommand = config["dvicommand"] if config["dvicommand"]
|
170
|
-
dvioptions = config["dvioptions"] if config["dvioptions"]
|
171
|
-
if enc
|
172
|
-
kanji = enc.split(/\=/).last.gsub(/-/, '').downcase
|
173
|
-
texoptions = "-kanji=#{kanji}"
|
195
|
+
if File.exist?("book.dvi")
|
196
|
+
system_or_raise("#{dvicommand} #{dvioptions} book.dvi")
|
174
197
|
end
|
175
|
-
texoptions = config["texoptions"] if config["texoptions"]
|
176
198
|
end
|
177
|
-
|
178
|
-
system_or_raise("#{texcommand} #{texoptions} book.tex")
|
179
|
-
end
|
180
|
-
call_hook("hook_aftertexcompile", config)
|
199
|
+
call_hook("hook_afterdvipdf")
|
181
200
|
|
182
|
-
|
183
|
-
system_or_raise("#{dvicommand} #{dvioptions} book.dvi")
|
184
|
-
end
|
185
|
-
}
|
186
|
-
call_hook("hook_afterdvipdf", config)
|
187
|
-
|
188
|
-
FileUtils.cp("#{@path}/book.pdf", "#{@basedir}/#{bookname}.pdf")
|
201
|
+
FileUtils.cp(File.join(@path, "book.pdf"), pdf_filepath)
|
189
202
|
|
190
|
-
|
191
|
-
|
203
|
+
ensure
|
204
|
+
unless @config["debug"]
|
205
|
+
remove_entry_secure @path
|
206
|
+
end
|
192
207
|
end
|
193
208
|
end
|
194
209
|
|
195
|
-
def output_chaps(filename,
|
210
|
+
def output_chaps(filename, yamlfile)
|
196
211
|
$stderr.puts "compiling #{filename}.tex"
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
else
|
212
|
+
begin
|
213
|
+
@converter.convert(filename+".re", File.join(@path, filename+".tex"))
|
214
|
+
rescue => e
|
201
215
|
@compile_errors = true
|
202
|
-
warn
|
216
|
+
warn "compile error in #{filename}.tex (#{e.class})"
|
217
|
+
warn e.message
|
203
218
|
end
|
204
219
|
end
|
205
220
|
|
221
|
+
# PDFMaker#copy_images should copy image files _AND_ execute extractbb (or ebb).
|
222
|
+
#
|
206
223
|
def copy_images(from, to)
|
207
224
|
if File.exist?(from)
|
208
225
|
Dir.mkdir(to)
|
@@ -237,89 +254,131 @@ module ReVIEW
|
|
237
254
|
end
|
238
255
|
end
|
239
256
|
|
240
|
-
def make_colophon_role(role
|
241
|
-
if config[role].present?
|
242
|
-
|
257
|
+
def make_colophon_role(role)
|
258
|
+
if @config[role].present?
|
259
|
+
initialize_metachars(@config["texcommand"])
|
260
|
+
return "#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(@config.names_of(role), ReVIEW::I18n.t("names_splitter")))} \\\\\n"
|
243
261
|
else
|
244
262
|
""
|
245
263
|
end
|
246
264
|
end
|
247
265
|
|
248
|
-
def make_colophon
|
266
|
+
def make_colophon
|
249
267
|
colophon = ""
|
250
|
-
config["colophon_order"].each do |role|
|
251
|
-
colophon += make_colophon_role(role
|
268
|
+
@config["colophon_order"].each do |role|
|
269
|
+
colophon += make_colophon_role(role)
|
252
270
|
end
|
253
271
|
colophon
|
254
272
|
end
|
255
273
|
|
256
|
-
def make_authors
|
274
|
+
def make_authors
|
257
275
|
authors = ""
|
258
|
-
if config["aut"].present?
|
259
|
-
author_names = join_with_separator(config
|
276
|
+
if @config["aut"].present?
|
277
|
+
author_names = join_with_separator(@config.names_of("aut"), ReVIEW::I18n.t("names_splitter"))
|
260
278
|
authors = ReVIEW::I18n.t("author_with_label", author_names)
|
261
279
|
end
|
262
|
-
if config["csl"].present?
|
263
|
-
csl_names = join_with_separator(config
|
280
|
+
if @config["csl"].present?
|
281
|
+
csl_names = join_with_separator(@config.names_of("csl"), ReVIEW::I18n.t("names_splitter"))
|
264
282
|
authors += " \\\\\n"+ ReVIEW::I18n.t("supervisor_with_label", csl_names)
|
265
283
|
end
|
266
|
-
if config["trl"].present?
|
267
|
-
trl_names = join_with_separator(config
|
284
|
+
if @config["trl"].present?
|
285
|
+
trl_names = join_with_separator(@config.names_of("trl"), ReVIEW::I18n.t("names_splitter"))
|
268
286
|
authors += " \\\\\n"+ ReVIEW::I18n.t("translator_with_label", trl_names)
|
269
287
|
end
|
270
288
|
authors
|
271
289
|
end
|
272
290
|
|
273
|
-
def
|
274
|
-
|
275
|
-
|
276
|
-
|
291
|
+
def make_history_list
|
292
|
+
buf = []
|
293
|
+
if @config["history"]
|
294
|
+
@config["history"].each_with_index do |items, edit|
|
295
|
+
items.each_with_index do |item, rev|
|
296
|
+
editstr = (edit == 0) ? ReVIEW::I18n.t("first_edition") : ReVIEW::I18n.t("nth_edition","#{edit+1}")
|
297
|
+
revstr = ReVIEW::I18n.t("nth_impression", "#{rev+1}")
|
298
|
+
if item =~ /\A\d+\-\d+\-\d+\Z/
|
299
|
+
buf << ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])
|
300
|
+
else
|
301
|
+
# custom date with string
|
302
|
+
item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
|
303
|
+
buf << ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
elsif @config["date"]
|
309
|
+
buf << ReVIEW::I18n.t("published_by2",
|
310
|
+
date_to_s(@config["date"]))
|
311
|
+
end
|
312
|
+
buf
|
313
|
+
end
|
314
|
+
|
315
|
+
def date_to_s(date)
|
316
|
+
require 'date'
|
317
|
+
d = Date.parse(date)
|
318
|
+
d.strftime(ReVIEW::I18n.t("date_format"))
|
319
|
+
end
|
277
320
|
|
278
|
-
|
279
|
-
|
321
|
+
def get_template
|
322
|
+
dclass = @config["texdocumentclass"] || []
|
323
|
+
@documentclass = dclass[0] || "jsbook"
|
324
|
+
@documentclassoption = dclass[1] || "uplatex,oneside"
|
280
325
|
|
281
|
-
|
282
|
-
|
283
|
-
custom_creditpage = make_custom_page(config["creditfile"])
|
326
|
+
@okuduke = make_colophon
|
327
|
+
@authors = make_authors
|
284
328
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
329
|
+
@custom_titlepage = make_custom_page(@config["cover"]) || make_custom_page(@config["coverfile"])
|
330
|
+
@custom_originaltitlepage = make_custom_page(@config["originaltitlefile"])
|
331
|
+
@custom_creditpage = make_custom_page(@config["creditfile"])
|
332
|
+
|
333
|
+
@custom_profilepage = make_custom_page(@config["profile"])
|
334
|
+
@custom_advfilepage = make_custom_page(@config["advfile"])
|
335
|
+
if @config["colophon"] && @config["colophon"].kind_of?(String)
|
336
|
+
@custom_colophonpage = make_custom_page(@config["colophon"])
|
289
337
|
end
|
290
|
-
custom_backcoverpage = make_custom_page(config["backcover"])
|
338
|
+
@custom_backcoverpage = make_custom_page(@config["backcover"])
|
291
339
|
|
292
|
-
|
340
|
+
if @config["pubhistory"]
|
341
|
+
warn "pubhistory is oboleted. use history."
|
342
|
+
else
|
343
|
+
@config["pubhistory"] = make_history_list.join("\n")
|
344
|
+
end
|
345
|
+
if @documentclass == "ubook" || @documentclass == "utbook"
|
346
|
+
@coverimageoption = "width=\\textheight,height=\\textwidth,keepaspectratio,angle=90"
|
347
|
+
else
|
348
|
+
@coverimageoption = "width=\\textwidth,height=\\textheight,keepaspectratio"
|
349
|
+
end
|
350
|
+
|
351
|
+
template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
|
293
352
|
layout_file = File.join(@basedir, "layouts", "layout.tex.erb")
|
294
353
|
if File.exist?(layout_file)
|
295
354
|
template = layout_file
|
296
355
|
end
|
297
356
|
|
298
|
-
|
299
|
-
|
357
|
+
@texcompiler = File.basename(@config["texcommand"], ".*")
|
358
|
+
|
359
|
+
erb = ReVIEW::Template.load(template, '-')
|
300
360
|
erb.result(binding)
|
301
361
|
end
|
302
362
|
|
303
363
|
def copyStyToDir(dirname, copybase, extname = "sty")
|
304
364
|
unless File.directory?(dirname)
|
305
|
-
|
365
|
+
warn "No such directory - #{dirname}"
|
306
366
|
return
|
307
367
|
end
|
308
368
|
|
309
|
-
Dir.open(dirname)
|
310
|
-
dir.each
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
FileUtils.cp "#{dirname}/#{fname}", copybase
|
369
|
+
Dir.open(dirname) do |dir|
|
370
|
+
dir.each do |fname|
|
371
|
+
if File.extname(fname).downcase == "."+extname
|
372
|
+
FileUtils.mkdir_p(copybase)
|
373
|
+
FileUtils.cp File.join(dirname, fname), copybase
|
315
374
|
end
|
316
|
-
|
317
|
-
|
375
|
+
end
|
376
|
+
end
|
318
377
|
end
|
319
378
|
|
320
|
-
def call_hook(hookname
|
321
|
-
if config["pdfmaker"].instance_of?(Hash) && config["pdfmaker"][hookname]
|
322
|
-
hook = File.absolute_path(config["pdfmaker"][hookname], @basedir)
|
379
|
+
def call_hook(hookname)
|
380
|
+
if @config["pdfmaker"].instance_of?(Hash) && @config["pdfmaker"][hookname]
|
381
|
+
hook = File.absolute_path(@config["pdfmaker"][hookname], @basedir)
|
323
382
|
if ENV["REVIEW_SAFE_MODE"].to_i & 1 > 0
|
324
383
|
warn "hook configuration is prohibited in safe mode. ignored."
|
325
384
|
else
|
data/lib/review/preprocessor.rb
CHANGED
@@ -24,24 +24,10 @@ module ReVIEW
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def warn(msg)
|
27
|
-
if @config["outencoding"] =~ /^EUC$/
|
28
|
-
msg = NKF.nkf("-W -e", msg)
|
29
|
-
elsif @config["outencoding"] =~ /^SJIS$/
|
30
|
-
msg = NKF.nkf("-W -s", msg)
|
31
|
-
elsif @config["outencoding"] =~ /^JIS$/
|
32
|
-
msg = NKF.nkf("-W -j", msg)
|
33
|
-
end
|
34
27
|
$stderr.puts "#{location()}: warning: #{msg}"
|
35
28
|
end
|
36
29
|
|
37
30
|
def error(msg)
|
38
|
-
if @config["outencoding"] =~ /^EUC$/
|
39
|
-
msg = NKF.nkf("-W -e", msg)
|
40
|
-
elsif @config["outencoding"] =~ /^SJIS$/
|
41
|
-
msg = NKF.nkf("-W -s", msg)
|
42
|
-
elsif @config["outencoding"] =~ /^JIS$/
|
43
|
-
msg = NKF.nkf("-W -j", msg)
|
44
|
-
end
|
45
31
|
@errutils_err = true
|
46
32
|
raise ApplicationError, "#{location()}: #{msg}"
|
47
33
|
end
|
@@ -148,7 +134,7 @@ module ReVIEW
|
|
148
134
|
path = expand(direc.arg)
|
149
135
|
ent = @repository.fetch_file(path)
|
150
136
|
ent = evaluate(path, ent) if direc['eval']
|
151
|
-
replace_block
|
137
|
+
replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
|
152
138
|
|
153
139
|
when /\A\#@map(?:range)?/
|
154
140
|
direc = parse_directive(line, 2, 'unindent')
|
@@ -156,7 +142,7 @@ module ReVIEW
|
|
156
142
|
ent = @repository.fetch_range(path, direc.args[1]) or
|
157
143
|
error "unknown range: #{path}: #{direc.args[1]}"
|
158
144
|
ent = (direc['unindent'] ? unindent(ent, direc['unindent']) : ent)
|
159
|
-
replace_block
|
145
|
+
replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
|
160
146
|
|
161
147
|
when /\A\#@end/
|
162
148
|
error 'unbaranced #@end'
|
@@ -167,7 +153,7 @@ module ReVIEW
|
|
167
153
|
warn "unkown directive: #{line.strip}" unless known_directive?(op)
|
168
154
|
@f.print line
|
169
155
|
|
170
|
-
when /\A\s*\z/
|
156
|
+
when /\A\s*\z/ # empty line
|
171
157
|
@f.puts
|
172
158
|
else
|
173
159
|
@f.print line
|
@@ -175,42 +161,17 @@ module ReVIEW
|
|
175
161
|
end
|
176
162
|
end
|
177
163
|
|
178
|
-
private
|
179
|
-
|
180
164
|
KNOWN_DIRECTIVES = %w( require provide warn ok )
|
181
165
|
|
182
166
|
def known_directive?(op)
|
183
167
|
KNOWN_DIRECTIVES.index(op)
|
184
168
|
end
|
185
169
|
|
186
|
-
def convert_outencoding(*s)
|
187
|
-
ine = ""
|
188
|
-
if @config["inencoding"] =~ /^EUC$/i
|
189
|
-
ine = "-E,"
|
190
|
-
elsif @config["inencoding"] =~ /^SJIS$/i
|
191
|
-
ine = "-S,"
|
192
|
-
elsif @config["inencoding"] =~ /^JIS$/i
|
193
|
-
ine = "-J,"
|
194
|
-
elsif @config["inencoding"] =~ /^UTF\-8$/i
|
195
|
-
ine = "-W,"
|
196
|
-
end
|
197
|
-
|
198
|
-
if @config["outencoding"] =~ /^EUC$/i
|
199
|
-
NKF.nkf("#{ine} -m0x -e", *s)
|
200
|
-
elsif @config["outencoding"] =~ /^SJIS$/i
|
201
|
-
NKF.nkf("#{ine} -m0x -s", *s)
|
202
|
-
elsif @config["outencoding"] =~ /^JIS$/i
|
203
|
-
NKF.nkf("#{ine} -m0x -j", *s)
|
204
|
-
else
|
205
|
-
NKF.nkf("#{ine} -m0x -w", *s)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
170
|
def replace_block(f, directive_line, newlines, with_lineno)
|
210
171
|
@f.print directive_line
|
211
172
|
newlines.each do |line|
|
212
173
|
print_number line.number if with_lineno
|
213
|
-
@f.print
|
174
|
+
@f.print line.string
|
214
175
|
end
|
215
176
|
skip_list f
|
216
177
|
end
|
@@ -243,8 +204,8 @@ module ReVIEW
|
|
243
204
|
class Directive
|
244
205
|
def initialize(op, args, opts)
|
245
206
|
@op = op
|
246
|
-
|
247
|
-
|
207
|
+
@args = args
|
208
|
+
@opts = opts
|
248
209
|
end
|
249
210
|
|
250
211
|
attr_reader :op
|
@@ -297,12 +258,12 @@ module ReVIEW
|
|
297
258
|
|
298
259
|
def optarg_value(spec)
|
299
260
|
case spec
|
300
|
-
when 'true'
|
301
|
-
when 'false' then false
|
302
|
-
when 'nil'
|
303
|
-
when nil
|
304
|
-
when /^\d+$/ then $&.to_i
|
305
|
-
else
|
261
|
+
when 'true' then true # [name=true]
|
262
|
+
when 'false' then false # [name=false]
|
263
|
+
when 'nil' then nil # [name=nil]
|
264
|
+
when nil then true # [name]
|
265
|
+
when /^\d+$/ then $&.to_i # [name=8]
|
266
|
+
else # [name=val]
|
306
267
|
spec
|
307
268
|
end
|
308
269
|
end
|
@@ -335,18 +296,6 @@ module ReVIEW
|
|
335
296
|
n == INF_INDENT ? 0 : n
|
336
297
|
end
|
337
298
|
|
338
|
-
def check_ruby_syntax(rbfile)
|
339
|
-
status = spawn {
|
340
|
-
exec("ruby -c #{rbfile} 2>&1 > /dev/null")
|
341
|
-
}
|
342
|
-
error "syntax check failed: #{rbfile}" unless status.exitstatus == 0
|
343
|
-
end
|
344
|
-
|
345
|
-
def spawn
|
346
|
-
pid, status = *Process.waitpid2(fork { yield })
|
347
|
-
status
|
348
|
-
end
|
349
|
-
|
350
299
|
def evaluate(path, chunk)
|
351
300
|
outputs = get_output("ruby #{path}", false).split(/\n/).map {|s| s.strip }
|
352
301
|
chunk.map {|line|
|
@@ -443,7 +392,7 @@ module ReVIEW
|
|
443
392
|
end
|
444
393
|
|
445
394
|
def git?(fname)
|
446
|
-
fname
|
395
|
+
fname.start_with?('git|')
|
447
396
|
end
|
448
397
|
|
449
398
|
def parse_git_blob(g_obj)
|
@@ -454,7 +403,7 @@ module ReVIEW
|
|
454
403
|
end
|
455
404
|
|
456
405
|
def parse_file(fname)
|
457
|
-
File.open(fname) {|f|
|
406
|
+
File.open(fname, 'r:BOM|utf-8') {|f|
|
458
407
|
init_ErrorUtils f
|
459
408
|
return _parse_file(f)
|
460
409
|
}
|
@@ -465,7 +414,7 @@ module ReVIEW
|
|
465
414
|
repo = {'file' => whole}
|
466
415
|
curr = {'WHOLE' => whole}
|
467
416
|
lineno = 1
|
468
|
-
yacchack = false
|
417
|
+
yacchack = false # remove ';'-only lines.
|
469
418
|
opened = [['(not opened)', '(not opened)']] * 3
|
470
419
|
|
471
420
|
f.each do |line|
|
@@ -510,7 +459,7 @@ module ReVIEW
|
|
510
459
|
when /(?:\A\#@|\#@@)yacchack/
|
511
460
|
yacchack = true
|
512
461
|
|
513
|
-
when /\A\#@-/
|
462
|
+
when /\A\#@-/ # does not increment line number.
|
514
463
|
line = canonical($')
|
515
464
|
curr.each_value do |list|
|
516
465
|
list.push Line.new(nil, line)
|