review-peg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rubocop.yml +47 -0
- data/.rubocop_todo.yml +605 -0
- data/.travis.yml +18 -0
- data/COPYING +515 -0
- data/ChangeLog +2449 -0
- data/Dockerfile +22 -0
- data/Gemfile +6 -0
- data/README.rdoc +81 -0
- data/Rakefile +51 -0
- data/bin/review-catalog-converter-peg +129 -0
- data/bin/review-check-peg +169 -0
- data/bin/review-checkdep-peg +63 -0
- data/bin/review-compile-peg +202 -0
- data/bin/review-epubmaker-legacy-peg +1024 -0
- data/bin/review-epubmaker-peg +44 -0
- data/bin/review-index-peg +110 -0
- data/bin/review-init-peg +151 -0
- data/bin/review-pdfmaker-peg +18 -0
- data/bin/review-preproc-peg +131 -0
- data/bin/review-validate-peg +51 -0
- data/bin/review-vol-peg +100 -0
- data/debian/README.Debian +12 -0
- data/debian/README.source +5 -0
- data/debian/changelog +5 -0
- data/debian/compat +1 -0
- data/debian/control +22 -0
- data/debian/copyright +62 -0
- data/debian/docs +6 -0
- data/debian/manpage.1.ex +59 -0
- data/debian/patches/path.diff +91 -0
- data/debian/patches/series +1 -0
- data/debian/review.install +13 -0
- data/debian/review.links +4 -0
- data/debian/rules +13 -0
- data/debian/source/format +1 -0
- data/doc/NEWS.ja.md +350 -0
- data/doc/NEWS.md +354 -0
- data/doc/catalog.ja.md +53 -0
- data/doc/catalog.md +52 -0
- data/doc/format.ja.md +734 -0
- data/doc/format.md +746 -0
- data/doc/format_idg.ja.md +203 -0
- data/doc/quickstart.ja.md +222 -0
- data/doc/quickstart.md +252 -0
- data/doc/ruby-uuid/README +11 -0
- data/doc/ruby-uuid/README.ja +34 -0
- data/doc/sample.css +108 -0
- data/doc/sample.yml +238 -0
- data/lib/epubmaker.rb +24 -0
- data/lib/epubmaker/content.rb +93 -0
- data/lib/epubmaker/epubcommon.rb +424 -0
- data/lib/epubmaker/epubv2.rb +139 -0
- data/lib/epubmaker/epubv3.rb +222 -0
- data/lib/epubmaker/producer.rb +330 -0
- data/lib/lineinput.rb +107 -0
- data/lib/review.rb +3 -0
- data/lib/review/book.rb +43 -0
- data/lib/review/book/base.rb +401 -0
- data/lib/review/book/chapter.rb +100 -0
- data/lib/review/book/compilable.rb +184 -0
- data/lib/review/book/image_finder.rb +71 -0
- data/lib/review/book/index.rb +413 -0
- data/lib/review/book/page_metric.rb +47 -0
- data/lib/review/book/part.rb +54 -0
- data/lib/review/book/volume.rb +67 -0
- data/lib/review/builder.rb +452 -0
- data/lib/review/catalog.rb +52 -0
- data/lib/review/compiler.rb +5183 -0
- data/lib/review/compiler/literals_1_9.kpeg +22 -0
- data/lib/review/compiler/literals_1_9.rb +435 -0
- data/lib/review/configure.rb +64 -0
- data/lib/review/epubbuilder.rb +18 -0
- data/lib/review/epubmaker.rb +480 -0
- data/lib/review/ewbbuilder.rb +381 -0
- data/lib/review/exception.rb +21 -0
- data/lib/review/extentions.rb +4 -0
- data/lib/review/extentions/array.rb +25 -0
- data/lib/review/extentions/object.rb +9 -0
- data/lib/review/extentions/string.rb +33 -0
- data/lib/review/htmlbuilder.rb +1166 -0
- data/lib/review/htmllayout.rb +41 -0
- data/lib/review/htmltoc.rb +45 -0
- data/lib/review/htmlutils.rb +90 -0
- data/lib/review/i18n.rb +96 -0
- data/lib/review/i18n.yml +169 -0
- data/lib/review/idgxmlbuilder.rb +1233 -0
- data/lib/review/inaobuilder.rb +357 -0
- data/lib/review/latexbuilder.rb +941 -0
- data/lib/review/latexindex.rb +35 -0
- data/lib/review/latexutils.rb +95 -0
- data/lib/review/layout.tex.erb +340 -0
- data/lib/review/lineinput.rb +17 -0
- data/lib/review/location.rb +24 -0
- data/lib/review/makerhelper.rb +67 -0
- data/lib/review/markdownbuilder.rb +339 -0
- data/lib/review/node.rb +288 -0
- data/lib/review/pdfmaker.rb +332 -0
- data/lib/review/preprocessor.rb +530 -0
- data/lib/review/review.kpeg +745 -0
- data/lib/review/sec_counter.rb +69 -0
- data/lib/review/template.rb +21 -0
- data/lib/review/textbuilder.rb +17 -0
- data/lib/review/textutils.rb +16 -0
- data/lib/review/tocparser.rb +348 -0
- data/lib/review/tocprinter.rb +205 -0
- data/lib/review/topbuilder.rb +796 -0
- data/lib/review/unfold.rb +138 -0
- data/lib/review/version.rb +3 -0
- data/lib/uuid.rb +312 -0
- data/review.gemspec +32 -0
- data/templates/html/layout-html5.html.erb +17 -0
- data/templates/html/layout-xhtml1.html.erb +20 -0
- 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/xml/container.xml.erb +6 -0
- data/test/CHAPS +2 -0
- data/test/assets/test.xml.erb +3 -0
- data/test/assets/test_template.tex +255 -0
- data/test/assets/test_template_backmatter.tex +32 -0
- data/test/bib.re +13 -0
- data/test/book_test_helper.rb +35 -0
- data/test/sample-book/README.md +7 -0
- data/test/sample-book/src/Rakefile +58 -0
- data/test/sample-book/src/_cover.html +3 -0
- data/test/sample-book/src/catalog.yml +10 -0
- data/test/sample-book/src/ch01.re +71 -0
- data/test/sample-book/src/ch02.re +3 -0
- data/test/sample-book/src/config.yml +186 -0
- data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
- data/test/sample-book/src/images/cover.jpg +0 -0
- data/test/sample-book/src/preface.re +15 -0
- data/test/sample-book/src/sty/jumoline.sty +310 -0
- data/test/sample-book/src/sty/reviewmacro.sty +39 -0
- data/test/sample-book/src/style.css +251 -0
- data/test/sample-book/src/vendor/jumoline/README +29 -0
- data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
- data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
- data/test/test.re +43 -0
- data/test/test_book.rb +556 -0
- data/test/test_book_chapter.rb +280 -0
- data/test/test_book_part.rb +54 -0
- data/test/test_builder.rb +80 -0
- data/test/test_catalog.rb +119 -0
- data/test/test_catalog_converter_cmd.rb +73 -0
- data/test/test_compiler.rb +92 -0
- data/test/test_configure.rb +50 -0
- data/test/test_epub3maker.rb +529 -0
- data/test/test_epubmaker.rb +569 -0
- data/test/test_epubmaker_cmd.rb +40 -0
- data/test/test_helper.rb +92 -0
- data/test/test_htmlbuilder.rb +1114 -0
- data/test/test_htmltoc.rb +32 -0
- data/test/test_htmlutils.rb +50 -0
- data/test/test_i18n.rb +180 -0
- data/test/test_idgxmlbuilder.rb +608 -0
- data/test/test_image_finder.rb +82 -0
- data/test/test_inaobuilder.rb +245 -0
- data/test/test_index.rb +174 -0
- data/test/test_latexbuilder.rb +732 -0
- data/test/test_lineinput.rb +182 -0
- data/test/test_makerhelper.rb +66 -0
- data/test/test_markdownbuilder.rb +125 -0
- data/test/test_pdfmaker.rb +171 -0
- data/test/test_pdfmaker_cmd.rb +40 -0
- data/test/test_preprocessor.rb +23 -0
- data/test/test_review_ext.rb +31 -0
- data/test/test_template.rb +26 -0
- data/test/test_textutils.rb +32 -0
- data/test/test_topbuilder.rb +291 -0
- data/test/test_uuid.rb +157 -0
- metadata +357 -0
data/lib/review/node.rb
ADDED
@@ -0,0 +1,288 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module ReVIEW
|
4
|
+
class Node
|
5
|
+
attr_accessor :content
|
6
|
+
|
7
|
+
def to_raw
|
8
|
+
to_s_by(:to_raw)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_doc
|
12
|
+
to_s_by(:to_doc)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s_by(meth)
|
16
|
+
if content.kind_of? String
|
17
|
+
@content
|
18
|
+
elsif content.nil?
|
19
|
+
nil
|
20
|
+
elsif !content.kind_of? Array
|
21
|
+
@content.__send__(meth)
|
22
|
+
else
|
23
|
+
##@content.map(&meth).join("")
|
24
|
+
@content.map{|o| o.__send__(meth)}.join("")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_json(*args)
|
29
|
+
if content.kind_of? String
|
30
|
+
val = '"'+@content.gsub(/\"/,'\\"').gsub(/\n/,'\\n')+'"'
|
31
|
+
elsif content.nil?
|
32
|
+
val = "null"
|
33
|
+
elsif !content.kind_of? Array
|
34
|
+
val = @content.to_json
|
35
|
+
else
|
36
|
+
val = "["+@content.map(&:to_json).join(",")+"]"
|
37
|
+
end
|
38
|
+
'{"ruleName":"' + self.class.to_s.sub(/ReVIEW::/,"").sub(/Node$/,"") + '",' +
|
39
|
+
"\"offset\":#{position.pos},\"line\":#{position.line},\"column\":#{position.col}," +
|
40
|
+
'"childNodes":' + val +
|
41
|
+
'}'
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
self.to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class HeadlineNode < Node
|
51
|
+
|
52
|
+
def to_doc
|
53
|
+
content_str = super
|
54
|
+
cmd = @cmd ? @cmd.to_doc : nil
|
55
|
+
label = @label
|
56
|
+
@compiler.compile_headline(@level, cmd, label, content_str)
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_json
|
60
|
+
'{"ruleName":"' + self.class.to_s.sub(/ReVIEW::/,"").sub(/Node$/,"") + '",' +
|
61
|
+
%Q|"cmd":"#{@cmd.to_json}",|+
|
62
|
+
%Q|"label":"#{@label.to_json}",|+
|
63
|
+
"\"offset\":#{position.pos},\"line\":#{position.line},\"column\":#{position.col}," +
|
64
|
+
'"childNodes":' + @content.to_json + '}'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class ParagraphNode < Node
|
69
|
+
|
70
|
+
def to_doc
|
71
|
+
#content = @content.map(&:to_doc)
|
72
|
+
content = super.split(/\n/)
|
73
|
+
@compiler.compile_paragraph(content)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class BlockElementNode < Node
|
78
|
+
|
79
|
+
def to_doc
|
80
|
+
# content_str = super
|
81
|
+
args = @args.map(&:to_doc)
|
82
|
+
if @content
|
83
|
+
content_lines = @content.map(&:to_doc)
|
84
|
+
else
|
85
|
+
content_lines = nil
|
86
|
+
end
|
87
|
+
@compiler.compile_command(@name, @args, content_lines, self)
|
88
|
+
end
|
89
|
+
|
90
|
+
def parse_args(*patterns)
|
91
|
+
patterns.map.with_index do |pattern, i|
|
92
|
+
if @args[i]
|
93
|
+
@args[i].__send__("to_#{pattern}")
|
94
|
+
else
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class CodeBlockElementNode < Node
|
102
|
+
|
103
|
+
def to_doc
|
104
|
+
# content_str = super
|
105
|
+
args = @args.map(&:to_doc)
|
106
|
+
if @content
|
107
|
+
content_lines = raw_lines
|
108
|
+
else
|
109
|
+
content_lines = nil
|
110
|
+
end
|
111
|
+
@compiler.compile_command(@name, @args, content_lines, self)
|
112
|
+
end
|
113
|
+
|
114
|
+
def parse_args(*patterns)
|
115
|
+
patterns.map.with_index do |pattern, i|
|
116
|
+
if @args[i]
|
117
|
+
@args[i].__send__("to_#{pattern}")
|
118
|
+
else
|
119
|
+
nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def raw_lines
|
125
|
+
self.content.to_doc.split(/\n/)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
class InlineElementNode < Node
|
131
|
+
def to_raw
|
132
|
+
content_str = super
|
133
|
+
"@<#{@symbol}>{#{content_str}}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def to_doc
|
137
|
+
#content_str = super
|
138
|
+
@compiler.compile_inline(@symbol, @content)
|
139
|
+
end
|
140
|
+
|
141
|
+
def to_json
|
142
|
+
'{"ruleName":"' + self.class.to_s.sub(/ReVIEW::/,"").sub(/Node$/,"") + '",' +
|
143
|
+
%Q|"symbol":"#{@symbol}",| +
|
144
|
+
"\"offset\":#{position.pos},\"line\":#{position.line},\"column\":#{position.col}," +
|
145
|
+
'"childNodes":[' + @content.map(&:to_json).join(",") + ']}'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class ComplexInlineElementNode < Node
|
150
|
+
def to_raw
|
151
|
+
content_str = super
|
152
|
+
"@<#{@symbol}>{#{content_str}}"
|
153
|
+
end
|
154
|
+
|
155
|
+
def to_doc
|
156
|
+
#content_str = super
|
157
|
+
@compiler.compile_inline(@symbol, @content)
|
158
|
+
end
|
159
|
+
|
160
|
+
def to_json
|
161
|
+
'{"ruleName":"' + self.class.to_s.sub(/ReVIEW::/,"").sub(/Node$/,"") + '",' +
|
162
|
+
%Q|"symbol":"#{@symbol}",| +
|
163
|
+
"\"offset\":#{position.pos},\"line\":#{position.line},\"column\":#{position.col}," +
|
164
|
+
'"childNodes":[' + @content.map(&:to_json).join(",") + ']}'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class InlineElementContentNode < Node
|
169
|
+
end
|
170
|
+
|
171
|
+
class ComplexInlineElementContentNode < Node
|
172
|
+
end
|
173
|
+
|
174
|
+
class TextNode < Node
|
175
|
+
|
176
|
+
def to_raw
|
177
|
+
content_str = super
|
178
|
+
content_str.to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
def to_doc
|
182
|
+
content_str = super
|
183
|
+
@compiler.compile_text(content_str)
|
184
|
+
end
|
185
|
+
|
186
|
+
def to_json(*args)
|
187
|
+
val = '"'+@content.gsub(/\"/,'\\"').gsub(/\n/,'\\n')+'"'
|
188
|
+
'{"ruleName":"' + self.class.to_s.sub(/ReVIEW::/,"").sub(/Node$/,"") + '",' +
|
189
|
+
"\"offset\":#{position.pos},\"line\":#{position.line},\"column\":#{position.col}," +
|
190
|
+
'"text":' + val + '}'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
class NewLineNode < Node
|
195
|
+
|
196
|
+
def to_doc
|
197
|
+
""
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class RawNode < Node
|
202
|
+
|
203
|
+
def to_doc
|
204
|
+
@compiler.compile_raw(@builder, @content.join(""))
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
class BracketArgNode < Node
|
209
|
+
end
|
210
|
+
|
211
|
+
class BraceArgNode < Node
|
212
|
+
end
|
213
|
+
|
214
|
+
class SinglelineCommentNode < Node
|
215
|
+
def to_doc
|
216
|
+
""
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
class SinglelineContentNode < Node
|
221
|
+
end
|
222
|
+
|
223
|
+
class UlistNode < Node
|
224
|
+
def to_doc
|
225
|
+
@compiler.compile_ulist(@content)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
class UlistElementNode < Node
|
230
|
+
def level=(level)
|
231
|
+
@level = level
|
232
|
+
end
|
233
|
+
|
234
|
+
def to_doc
|
235
|
+
@content.map(&:to_doc).join("")
|
236
|
+
end
|
237
|
+
|
238
|
+
def concat(elem)
|
239
|
+
@content << elem
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class OlistNode < Node
|
244
|
+
def to_doc
|
245
|
+
@compiler.compile_olist(@content)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
class OlistElementNode < Node
|
250
|
+
def num=(num)
|
251
|
+
@num = num
|
252
|
+
end
|
253
|
+
|
254
|
+
def to_doc
|
255
|
+
@content.map(&:to_doc).join("")
|
256
|
+
end
|
257
|
+
|
258
|
+
def concat(elem)
|
259
|
+
@content << elem
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
class DlistNode < Node
|
264
|
+
def to_doc
|
265
|
+
@compiler.compile_dlist(@content)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
class DlistElementNode < Node
|
270
|
+
def to_doc
|
271
|
+
@content.map(&:to_doc).join("")
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
class DocumentNode < Node
|
276
|
+
end
|
277
|
+
|
278
|
+
class ColumnNode < Node
|
279
|
+
|
280
|
+
def to_doc
|
281
|
+
level = @level
|
282
|
+
label = @label
|
283
|
+
caption = @caption ? @caption.to_doc : nil
|
284
|
+
@compiler.compile_column(level, label, caption, @content)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
@@ -0,0 +1,332 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2015 Kenshi Muto and Masayoshi Takahashi
|
4
|
+
#
|
5
|
+
# This program is free software.
|
6
|
+
# You can distribute or modify this program under the terms of
|
7
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
8
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
9
|
+
#
|
10
|
+
require 'optparse'
|
11
|
+
require 'yaml'
|
12
|
+
require 'fileutils'
|
13
|
+
require 'erb'
|
14
|
+
|
15
|
+
require 'review'
|
16
|
+
require 'review/i18n'
|
17
|
+
|
18
|
+
|
19
|
+
module ReVIEW
|
20
|
+
class PDFMaker
|
21
|
+
|
22
|
+
include FileUtils
|
23
|
+
include ReVIEW::LaTeXUtils
|
24
|
+
|
25
|
+
attr_accessor :config, :basedir
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@basedir = Dir.pwd
|
29
|
+
end
|
30
|
+
|
31
|
+
def system_or_raise(*args)
|
32
|
+
Kernel.system(*args) or raise("failed to run command: #{args.join(' ')}")
|
33
|
+
end
|
34
|
+
|
35
|
+
def error(msg)
|
36
|
+
$stderr.puts "#{File.basename($0, '.*')}: error: #{msg}"
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def warn(msg)
|
41
|
+
$stderr.puts "#{File.basename($0, '.*')}: warning: #{msg}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def pdf_filepath
|
45
|
+
File.join(@basedir, @config["bookname"]+".pdf")
|
46
|
+
end
|
47
|
+
|
48
|
+
def remove_old_file
|
49
|
+
FileUtils.rm_f(pdf_filepath)
|
50
|
+
end
|
51
|
+
|
52
|
+
def build_path
|
53
|
+
"./#{@config["bookname"]}-pdf"
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_compile_status(ignore_errors)
|
57
|
+
return unless @compile_errors
|
58
|
+
|
59
|
+
if ignore_errors
|
60
|
+
$stderr.puts "compile error, but try to generate PDF file"
|
61
|
+
else
|
62
|
+
error "compile error, No PDF file output."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.execute(*args)
|
67
|
+
self.new.execute(*args)
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_opts(args)
|
71
|
+
cmd_config = Hash.new
|
72
|
+
opts = OptionParser.new
|
73
|
+
|
74
|
+
opts.banner = "Usage: review-pdfmaker configfile"
|
75
|
+
opts.version = ReVIEW::VERSION
|
76
|
+
opts.on('--help', 'Prints this message and quit.') do
|
77
|
+
puts opts.help
|
78
|
+
exit 0
|
79
|
+
end
|
80
|
+
opts.on('--[no-]debug', 'Keep temporary files.') do |debug|
|
81
|
+
cmd_config["debug"] = debug
|
82
|
+
end
|
83
|
+
opts.on('--ignore-errors', 'Ignore review-compile errors.') do
|
84
|
+
cmd_config["ignore-errors"] = true
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.parse!(args)
|
88
|
+
if args.size != 1
|
89
|
+
puts opts.help
|
90
|
+
exit 0
|
91
|
+
end
|
92
|
+
|
93
|
+
return cmd_config, args[0]
|
94
|
+
end
|
95
|
+
|
96
|
+
def execute(*args)
|
97
|
+
@config = ReVIEW::Configure.values
|
98
|
+
cmd_config, yamlfile = parse_opts(args)
|
99
|
+
|
100
|
+
@config.merge!(YAML.load_file(yamlfile))
|
101
|
+
# YAML configs will be overridden by command line options.
|
102
|
+
@config.merge!(cmd_config)
|
103
|
+
I18n.setup(@config["language"])
|
104
|
+
generate_pdf(yamlfile)
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_pdf(yamlfile)
|
108
|
+
remove_old_file
|
109
|
+
@path = build_path()
|
110
|
+
Dir.mkdir(@path)
|
111
|
+
|
112
|
+
@chaps_fnames = Hash.new{|h, key| h[key] = ""}
|
113
|
+
@compile_errors = nil
|
114
|
+
|
115
|
+
book = ReVIEW::Book.load(@basedir)
|
116
|
+
book.config = @config
|
117
|
+
book.parts.each do |part|
|
118
|
+
if part.name.present?
|
119
|
+
if part.file?
|
120
|
+
output_chaps(part.name, yamlfile)
|
121
|
+
@chaps_fnames["CHAPS"] << %Q|\\input{#{part.name}.tex}\n|
|
122
|
+
else
|
123
|
+
@chaps_fnames["CHAPS"] << %Q|\\part{#{part.name}}\n|
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
part.chapters.each do |chap|
|
128
|
+
filename = File.basename(chap.path, ".*")
|
129
|
+
output_chaps(filename, yamlfile)
|
130
|
+
@chaps_fnames["PREDEF"] << "\\input{#{filename}.tex}\n" if chap.on_PREDEF?
|
131
|
+
@chaps_fnames["CHAPS"] << "\\input{#{filename}.tex}\n" if chap.on_CHAPS?
|
132
|
+
@chaps_fnames["APPENDIX"] << "\\input{#{filename}.tex}\n" if chap.on_APPENDIX?
|
133
|
+
@chaps_fnames["POSTDEF"] << "\\input{#{filename}.tex}\n" if chap.on_POSTDEF?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
check_compile_status(@config["ignore-errors"])
|
138
|
+
|
139
|
+
@config["pre_str"] = @chaps_fnames["PREDEF"]
|
140
|
+
@config["chap_str"] = @chaps_fnames["CHAPS"]
|
141
|
+
@config["appendix_str"] = @chaps_fnames["APPENDIX"]
|
142
|
+
@config["post_str"] = @chaps_fnames["POSTDEF"]
|
143
|
+
|
144
|
+
@config["usepackage"] = ""
|
145
|
+
if @config["texstyle"]
|
146
|
+
@config["usepackage"] = "\\usepackage{#{@config['texstyle']}}"
|
147
|
+
end
|
148
|
+
|
149
|
+
copy_images("./images", File.join(@path, "images"))
|
150
|
+
copyStyToDir(File.join(Dir.pwd, "sty"), @path)
|
151
|
+
copyStyToDir(File.join(Dir.pwd, "sty"), @path, "fd")
|
152
|
+
copyStyToDir(File.join(Dir.pwd, "sty"), @path, "cls")
|
153
|
+
copyStyToDir(Dir.pwd, @path, "tex")
|
154
|
+
|
155
|
+
Dir.chdir(@path) do
|
156
|
+
template = get_template
|
157
|
+
File.open("./book.tex", "wb"){|f| f.write(template)}
|
158
|
+
|
159
|
+
call_hook("hook_beforetexcompile")
|
160
|
+
|
161
|
+
## do compile
|
162
|
+
kanji = 'utf8'
|
163
|
+
texcommand = "platex"
|
164
|
+
texoptions = "-kanji=#{kanji}"
|
165
|
+
dvicommand = "dvipdfmx"
|
166
|
+
dvioptions = "-d 5"
|
167
|
+
|
168
|
+
if ENV["REVIEW_SAFE_MODE"].to_i & 4 > 0
|
169
|
+
warn "command configuration is prohibited in safe mode. ignored."
|
170
|
+
else
|
171
|
+
texcommand = @config["texcommand"] if @config["texcommand"]
|
172
|
+
dvicommand = @config["dvicommand"] if @config["dvicommand"]
|
173
|
+
dvioptions = @config["dvioptions"] if @config["dvioptions"]
|
174
|
+
texoptions = @config["texoptions"] if @config["texoptions"]
|
175
|
+
end
|
176
|
+
3.times do
|
177
|
+
system_or_raise("#{texcommand} #{texoptions} book.tex")
|
178
|
+
end
|
179
|
+
call_hook("hook_aftertexcompile")
|
180
|
+
|
181
|
+
if File.exist?("book.dvi")
|
182
|
+
system_or_raise("#{dvicommand} #{dvioptions} book.dvi")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
call_hook("hook_afterdvipdf")
|
186
|
+
|
187
|
+
FileUtils.cp(File.join(@path, "book.pdf"), pdf_filepath)
|
188
|
+
|
189
|
+
unless @config["debug"]
|
190
|
+
remove_entry_secure @path
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def output_chaps(filename, yamlfile)
|
195
|
+
$stderr.puts "compiling #{filename}.tex"
|
196
|
+
cmd = "#{ReVIEW::MakerHelper.bindir}/review-compile-peg --yaml=#{yamlfile} --target=latex --level=#{@config["secnolevel"]} --toclevel=#{@config["toclevel"]} #{@config["params"]} #{filename}.re > #{@path}/#{filename}.tex"
|
197
|
+
if system cmd
|
198
|
+
# OK
|
199
|
+
else
|
200
|
+
@compile_errors = true
|
201
|
+
warn cmd
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# PDFMaker#copy_images should copy image files _AND_ execute extractbb (or ebb).
|
206
|
+
#
|
207
|
+
def copy_images(from, to)
|
208
|
+
if File.exist?(from)
|
209
|
+
Dir.mkdir(to)
|
210
|
+
ReVIEW::MakerHelper.copy_images_to_dir(from, to)
|
211
|
+
Dir.chdir(to) do
|
212
|
+
images = Dir.glob("**/*").find_all{|f|
|
213
|
+
File.file?(f) and f =~ /\.(jpg|jpeg|png|pdf)\z/
|
214
|
+
}
|
215
|
+
break if images.empty?
|
216
|
+
system("extractbb", *images)
|
217
|
+
unless system("extractbb", "-m", *images)
|
218
|
+
system_or_raise("ebb", *images)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def make_custom_page(file)
|
225
|
+
file_sty = file.to_s.sub(/\.[^.]+$/, ".tex")
|
226
|
+
if File.exist?(file_sty)
|
227
|
+
File.read(file_sty)
|
228
|
+
else
|
229
|
+
nil
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def join_with_separator(value, sep)
|
234
|
+
if value.kind_of? Array
|
235
|
+
value.join(sep)
|
236
|
+
else
|
237
|
+
value
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def make_colophon_role(role)
|
242
|
+
if @config[role].present?
|
243
|
+
return "#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(@config[role], ReVIEW::I18n.t("names_splitter")))} \\\\\n"
|
244
|
+
else
|
245
|
+
""
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def make_colophon
|
250
|
+
colophon = ""
|
251
|
+
@config["colophon_order"].each do |role|
|
252
|
+
colophon += make_colophon_role(role)
|
253
|
+
end
|
254
|
+
colophon
|
255
|
+
end
|
256
|
+
|
257
|
+
def make_authors
|
258
|
+
authors = ""
|
259
|
+
if @config["aut"].present?
|
260
|
+
author_names = join_with_separator(@config["aut"], ReVIEW::I18n.t("names_splitter"))
|
261
|
+
authors = ReVIEW::I18n.t("author_with_label", author_names)
|
262
|
+
end
|
263
|
+
if @config["csl"].present?
|
264
|
+
csl_names = join_with_separator(@config["csl"], ReVIEW::I18n.t("names_splitter"))
|
265
|
+
authors += " \\\\\n"+ ReVIEW::I18n.t("supervisor_with_label", csl_names)
|
266
|
+
end
|
267
|
+
if @config["trl"].present?
|
268
|
+
trl_names = join_with_separator(@config["trl"], ReVIEW::I18n.t("names_splitter"))
|
269
|
+
authors += " \\\\\n"+ ReVIEW::I18n.t("translator_with_label", trl_names)
|
270
|
+
end
|
271
|
+
authors
|
272
|
+
end
|
273
|
+
|
274
|
+
def get_template
|
275
|
+
dclass = @config["texdocumentclass"] || []
|
276
|
+
documentclass = dclass[0] || "jsbook"
|
277
|
+
documentclassoption = dclass[1] || "oneside"
|
278
|
+
|
279
|
+
okuduke = make_colophon
|
280
|
+
authors = make_authors
|
281
|
+
|
282
|
+
custom_titlepage = make_custom_page(@config["cover"]) || make_custom_page(@config["coverfile"])
|
283
|
+
custom_originaltitlepage = make_custom_page(@config["originaltitlefile"])
|
284
|
+
custom_creditpage = make_custom_page(@config["creditfile"])
|
285
|
+
|
286
|
+
custom_profilepage = make_custom_page(@config["profile"])
|
287
|
+
custom_advfilepage = make_custom_page(@config["advfile"])
|
288
|
+
if @config["colophon"] && @config["colophon"].kind_of?(String)
|
289
|
+
custom_colophonpage = make_custom_page(@config["colophon"])
|
290
|
+
end
|
291
|
+
custom_backcoverpage = make_custom_page(@config["backcover"])
|
292
|
+
|
293
|
+
template = File.expand_path('layout.tex.erb', File.dirname(__FILE__))
|
294
|
+
layout_file = File.join(@basedir, "layouts", "layout.tex.erb")
|
295
|
+
if File.exist?(layout_file)
|
296
|
+
template = layout_file
|
297
|
+
end
|
298
|
+
|
299
|
+
erb = ERB.new(File.open(template).read)
|
300
|
+
values = @config # must be 'values' for legacy files
|
301
|
+
erb.result(binding)
|
302
|
+
end
|
303
|
+
|
304
|
+
def copyStyToDir(dirname, copybase, extname = "sty")
|
305
|
+
unless File.directory?(dirname)
|
306
|
+
warn "No such directory - #{dirname}"
|
307
|
+
return
|
308
|
+
end
|
309
|
+
|
310
|
+
Dir.open(dirname) do |dir|
|
311
|
+
dir.each do |fname|
|
312
|
+
if File.extname(fname).downcase == "."+extname
|
313
|
+
FileUtils.mkdir_p(copybase)
|
314
|
+
FileUtils.cp File.join(dirname, fname), copybase
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def call_hook(hookname)
|
321
|
+
if @config["pdfmaker"].instance_of?(Hash) && @config["pdfmaker"][hookname]
|
322
|
+
hook = File.absolute_path(@config["pdfmaker"][hookname], @basedir)
|
323
|
+
if ENV["REVIEW_SAFE_MODE"].to_i & 1 > 0
|
324
|
+
warn "hook configuration is prohibited in safe mode. ignored."
|
325
|
+
else
|
326
|
+
system_or_raise("#{hook} #{Dir.pwd} #{@basedir}")
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|