review 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +42 -0
- data/README.rdoc +31 -0
- data/bin/review-catalog-converter +129 -0
- data/bin/review-check +4 -2
- data/bin/review-compile +7 -7
- data/bin/review-index +4 -3
- data/bin/review-init +3 -1
- data/bin/review-pdfmaker +2 -258
- data/bin/review-vol +2 -2
- data/doc/catalog.rdoc +18 -3
- data/doc/format.rdoc +2 -3
- data/doc/quickstart.rdoc +1 -1
- data/lib/epubmaker/epubv2.rb +16 -8
- data/lib/epubmaker/epubv3.rb +44 -12
- data/lib/epubmaker/producer.rb +4 -2
- data/lib/review/book.rb +0 -1
- data/lib/review/book/base.rb +72 -35
- data/lib/review/book/chapter.rb +8 -12
- data/lib/review/book/compilable.rb +8 -8
- data/lib/review/book/image_finder.rb +7 -0
- data/lib/review/book/index.rb +23 -5
- data/lib/review/book/volume.rb +2 -1
- data/lib/review/builder.rb +10 -5
- data/lib/review/catalog.rb +5 -0
- data/lib/review/compiler.rb +1 -1
- data/lib/review/configure.rb +12 -0
- data/lib/review/epubmaker.rb +13 -7
- data/lib/review/htmlbuilder.rb +26 -12
- data/lib/review/i18n.rb +2 -2
- data/lib/review/i18n.yml +21 -0
- data/lib/review/idgxmlbuilder.rb +11 -9
- data/lib/review/latexbuilder.rb +3 -2
- data/lib/review/{review.tex.erb → layout.tex.erb} +9 -1
- data/lib/review/markdownbuilder.rb +126 -4
- data/lib/review/pdfmaker.rb +291 -0
- data/lib/review/tocparser.rb +6 -5
- data/lib/review/tocprinter.rb +5 -2
- data/lib/review/version.rb +1 -1
- data/review.gemspec +1 -1
- data/rubocop-todo.yml +13 -0
- data/test/test_book.rb +95 -133
- data/test/test_book_chapter.rb +16 -21
- data/test/test_builder.rb +12 -7
- data/test/test_catalog.rb +15 -3
- data/test/test_catalog_converter_cmd.rb +73 -0
- data/test/test_epubmaker.rb +5 -5
- data/test/test_helper.rb +32 -21
- data/test/test_htmlbuilder.rb +219 -192
- data/test/test_i18n.rb +46 -19
- data/test/test_idgxmlbuilder.rb +177 -182
- data/test/test_inaobuilder.rb +1 -2
- data/test/test_index.rb +20 -0
- data/test/test_latexbuilder.rb +175 -183
- data/test/test_markdownbuilder.rb +41 -5
- data/test/test_pdfmaker.rb +130 -0
- data/test/test_topbuilder.rb +92 -96
- metadata +10 -6
- data/lib/review/book/parameters.rb +0 -98
- data/test/test_book_parameter.rb +0 -42
data/lib/review/i18n.yml
CHANGED
@@ -17,6 +17,17 @@ ja:
|
|
17
17
|
ruby_prefix: "("
|
18
18
|
ruby_postfix: ")"
|
19
19
|
aut: "著 者"
|
20
|
+
csl: "監 修"
|
21
|
+
dsr: "デザイン"
|
22
|
+
ill: "イラスト"
|
23
|
+
cov: "表 紙"
|
24
|
+
edt: "編 集"
|
25
|
+
pht: "撮 影"
|
26
|
+
trl: "翻 訳"
|
27
|
+
## XXX Backward Compatibility: `prt` should be "印刷所"
|
28
|
+
prt: "発行所"
|
29
|
+
pbl: "発行所"
|
30
|
+
contact: "連絡先"
|
20
31
|
author_postfix: " 著"
|
21
32
|
supervisor_postfix: " 監修"
|
22
33
|
translator_postfix: " 訳"
|
@@ -39,6 +50,16 @@ en:
|
|
39
50
|
caption_prefix_idgxml: " "
|
40
51
|
ruby_prefix: "("
|
41
52
|
ruby_postfix: ")"
|
53
|
+
aut: "Author"
|
54
|
+
csl: "Consultant"
|
55
|
+
dsr: "Design"
|
56
|
+
ill: "Illustrator"
|
57
|
+
edt: "Editor"
|
58
|
+
pht: "Photographer"
|
59
|
+
trl: "Translator"
|
60
|
+
prt: "Printer"
|
61
|
+
pbl: "Publisher"
|
62
|
+
contact: "Contact"
|
42
63
|
names_splitter: ", "
|
43
64
|
|
44
65
|
zh_TW:
|
data/lib/review/idgxmlbuilder.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
3
|
# Copyright (c) 2002-2007 Minero Aoki
|
4
|
-
# 2008-
|
4
|
+
# 2008-2014 Minero Aoki, Kenshi Muto
|
5
5
|
#
|
6
6
|
# This program is free software.
|
7
7
|
# You can distribute or modify this program under the terms of
|
@@ -160,7 +160,7 @@ module ReVIEW
|
|
160
160
|
placeholder = if @chapter.is_a? ReVIEW::Book::Part
|
161
161
|
level = 0
|
162
162
|
'part'
|
163
|
-
elsif @chapter.
|
163
|
+
elsif @chapter.on_APPENDIX?
|
164
164
|
'appendix'
|
165
165
|
else
|
166
166
|
'chapter'
|
@@ -181,7 +181,7 @@ module ReVIEW
|
|
181
181
|
@section += 1
|
182
182
|
print %Q(<sect id="sect:#{@chapter.number}.#{@section}">) unless @secttags.nil?
|
183
183
|
if @book.config["secnolevel"] >= 2
|
184
|
-
if @chapter.number.blank? or @chapter.
|
184
|
+
if @chapter.number.blank? or @chapter.on_APPENDIX?
|
185
185
|
prefix = ""
|
186
186
|
else
|
187
187
|
prefix = "#{@chapter.number}.#{@section}#{I18n.t("chapter_postfix")}"
|
@@ -201,7 +201,7 @@ module ReVIEW
|
|
201
201
|
@subsection += 1
|
202
202
|
print %Q(<sect2 id="sect:#{@chapter.number}.#{@section}.#{@subsection}">) unless @secttags.nil?
|
203
203
|
if @book.config["secnolevel"] >= 3
|
204
|
-
if @chapter.number.blank? or @chapter.
|
204
|
+
if @chapter.number.blank? or @chapter.on_APPENDIX?
|
205
205
|
prefix = ""
|
206
206
|
else
|
207
207
|
prefix = "#{@chapter.number}.#{@section}.#{@subsection}#{I18n.t("chapter_postfix")}"
|
@@ -219,7 +219,7 @@ module ReVIEW
|
|
219
219
|
@subsubsection += 1
|
220
220
|
print %Q(<sect3 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}">) unless @secttags.nil?
|
221
221
|
if @book.config["secnolevel"] >= 4
|
222
|
-
if @chapter.number.blank? or @chapter.
|
222
|
+
if @chapter.number.blank? or @chapter.on_APPENDIX?
|
223
223
|
prefix = ""
|
224
224
|
else
|
225
225
|
prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}#{I18n.t("chapter_postfix")}"
|
@@ -235,7 +235,7 @@ module ReVIEW
|
|
235
235
|
@subsubsubsection += 1
|
236
236
|
print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) unless @secttags.nil?
|
237
237
|
if @book.config["secnolevel"] >= 5
|
238
|
-
if @chapter.number.blank? or @chapter.
|
238
|
+
if @chapter.number.blank? or @chapter.on_APPENDIX?
|
239
239
|
prefix = ""
|
240
240
|
else
|
241
241
|
prefix = "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}#{I18n.t("chapter_postfix")}"
|
@@ -518,6 +518,7 @@ module ReVIEW
|
|
518
518
|
print %Q[</pre>]
|
519
519
|
image_header id, caption
|
520
520
|
puts "</img>"
|
521
|
+
warn "no such image: #{id}"
|
521
522
|
end
|
522
523
|
|
523
524
|
def image_header(id, caption)
|
@@ -1069,7 +1070,7 @@ module ReVIEW
|
|
1069
1070
|
rescue
|
1070
1071
|
warn %Q[no such image: #{id}]
|
1071
1072
|
end
|
1072
|
-
puts %Q[<caption>#{compile_inline(caption)}</caption>] if
|
1073
|
+
puts %Q[<caption>#{compile_inline(caption)}</caption>] if caption.present?
|
1073
1074
|
puts "</img>"
|
1074
1075
|
end
|
1075
1076
|
|
@@ -1156,10 +1157,11 @@ module ReVIEW
|
|
1156
1157
|
end
|
1157
1158
|
|
1158
1159
|
def inline_title(id)
|
1160
|
+
title = super
|
1159
1161
|
if @book.config["chapterlink"]
|
1160
|
-
%Q(<link href="#{id}">#{
|
1162
|
+
%Q(<link href="#{id}">#{title}</link>)
|
1161
1163
|
else
|
1162
|
-
|
1164
|
+
title
|
1163
1165
|
end
|
1164
1166
|
rescue KeyError
|
1165
1167
|
error "unknown chapter: #{id}"
|
data/lib/review/latexbuilder.rb
CHANGED
@@ -603,10 +603,11 @@ module ReVIEW
|
|
603
603
|
end
|
604
604
|
|
605
605
|
def inline_title(id)
|
606
|
+
title = super
|
606
607
|
if @book.config["chapterlink"]
|
607
|
-
"\\hyperref[chap:#{id}]{#{
|
608
|
+
"\\hyperref[chap:#{id}]{#{title}}"
|
608
609
|
else
|
609
|
-
|
610
|
+
title
|
610
611
|
end
|
611
612
|
rescue KeyError
|
612
613
|
error "unknown chapter: #{id}"
|
@@ -157,7 +157,6 @@
|
|
157
157
|
}
|
158
158
|
|
159
159
|
\newcommand{\reviewcolophon}[0]{%
|
160
|
-
\backmatter
|
161
160
|
\clearpage}
|
162
161
|
\newcommand{\reviewappendix}[0]{%
|
163
162
|
\appendix}
|
@@ -227,7 +226,16 @@
|
|
227
226
|
<%= values["chap_str"] %>
|
228
227
|
\renewcommand{\chaptermark}[1]{\markboth{\appendixname\thechapter~#1}{}}
|
229
228
|
\reviewappendix
|
229
|
+
<%= values["appendix_str"] %>
|
230
|
+
|
231
|
+
%% backmatter begins
|
232
|
+
<% if values["post_str"] or values["colophon"] %>
|
233
|
+
\backmatter
|
234
|
+
<% end %>
|
235
|
+
|
236
|
+
<% if values["post_str"] %>
|
230
237
|
<%= values["post_str"] %>
|
238
|
+
<% end %>
|
231
239
|
|
232
240
|
<% if values["colophon"] %>
|
233
241
|
%% okuduke
|
@@ -15,6 +15,12 @@ module ReVIEW
|
|
15
15
|
'.md'
|
16
16
|
end
|
17
17
|
|
18
|
+
def builder_init_file
|
19
|
+
@ul_indent = 0
|
20
|
+
@chapter.book.image_types = %w( .png .jpg .jpeg .gif .svg )
|
21
|
+
end
|
22
|
+
private :builder_init_file
|
23
|
+
|
18
24
|
def puts(str)
|
19
25
|
@blank_seen = false
|
20
26
|
super
|
@@ -26,8 +32,10 @@ module ReVIEW
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def headline(level, label, caption)
|
35
|
+
blank
|
29
36
|
prefix = "#" * level
|
30
37
|
puts "#{prefix} #{caption}"
|
38
|
+
blank
|
31
39
|
end
|
32
40
|
|
33
41
|
def quote(lines)
|
@@ -42,15 +50,24 @@ module ReVIEW
|
|
42
50
|
end
|
43
51
|
|
44
52
|
def ul_begin
|
45
|
-
blank
|
53
|
+
blank if @ul_indent == 0
|
54
|
+
@ul_indent += 1
|
46
55
|
end
|
47
56
|
|
48
57
|
def ul_item(lines)
|
49
|
-
puts "- #{lines.join}"
|
58
|
+
puts " " * (@ul_indent - 1) + "* " + "#{lines.join}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def ul_item_begin(lines)
|
62
|
+
puts " " * (@ul_indent - 1) + "* " + "#{lines.join}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def ul_item_end
|
50
66
|
end
|
51
67
|
|
52
68
|
def ul_end
|
53
|
-
|
69
|
+
@ul_indent -= 1
|
70
|
+
blank if @ul_indent == 0
|
54
71
|
end
|
55
72
|
|
56
73
|
def ol_begin
|
@@ -67,6 +84,9 @@ module ReVIEW
|
|
67
84
|
|
68
85
|
def emlist(lines, caption = nil)
|
69
86
|
blank
|
87
|
+
if caption
|
88
|
+
puts caption
|
89
|
+
end
|
70
90
|
puts "```"
|
71
91
|
lines.each do |line|
|
72
92
|
puts detab(line)
|
@@ -104,9 +124,14 @@ module ReVIEW
|
|
104
124
|
"`#{str}`"
|
105
125
|
end
|
106
126
|
|
127
|
+
def inline_tt(str)
|
128
|
+
"`#{str}`"
|
129
|
+
end
|
130
|
+
|
131
|
+
|
107
132
|
def image_image(id, caption, metric)
|
108
133
|
blank
|
109
|
-
puts "![#{caption}](
|
134
|
+
puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(/\A\.\//, "")})"
|
110
135
|
blank
|
111
136
|
end
|
112
137
|
|
@@ -121,6 +146,12 @@ module ReVIEW
|
|
121
146
|
nofunc_text("[UnknownImage:#{id}]")
|
122
147
|
end
|
123
148
|
|
149
|
+
def indepimage(id, caption="", metric=nil)
|
150
|
+
blank
|
151
|
+
puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(/\A\.\//, "")})"
|
152
|
+
blank
|
153
|
+
end
|
154
|
+
|
124
155
|
def pagebreak
|
125
156
|
puts "{pagebreak}"
|
126
157
|
end
|
@@ -129,6 +160,97 @@ module ReVIEW
|
|
129
160
|
"jpg"
|
130
161
|
end
|
131
162
|
|
163
|
+
def cmd(lines)
|
164
|
+
puts "```"
|
165
|
+
lines.each do |line|
|
166
|
+
puts detab(line)
|
167
|
+
end
|
168
|
+
puts "```"
|
169
|
+
end
|
170
|
+
|
171
|
+
def table(lines, id = nil, caption = nil)
|
172
|
+
rows = []
|
173
|
+
sepidx = nil
|
174
|
+
lines.each_with_index do |line, idx|
|
175
|
+
if /\A[\=\-]{12}/ =~ line
|
176
|
+
# just ignore
|
177
|
+
#error "too many table separator" if sepidx
|
178
|
+
sepidx ||= idx
|
179
|
+
next
|
180
|
+
end
|
181
|
+
rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
|
182
|
+
end
|
183
|
+
rows = adjust_n_cols(rows)
|
184
|
+
|
185
|
+
begin
|
186
|
+
table_header id, caption unless caption.nil?
|
187
|
+
rescue KeyError
|
188
|
+
error "no such table: #{id}"
|
189
|
+
end
|
190
|
+
table_begin rows.first.size
|
191
|
+
return if rows.empty?
|
192
|
+
if sepidx
|
193
|
+
sepidx.times do
|
194
|
+
tr rows.shift.map {|s| th(s) }
|
195
|
+
end
|
196
|
+
table_border rows.first.size
|
197
|
+
rows.each do |cols|
|
198
|
+
tr cols.map {|s| td(s) }
|
199
|
+
end
|
200
|
+
else
|
201
|
+
rows.each do |cols|
|
202
|
+
h, *cs = *cols
|
203
|
+
tr [th(h)] + cs.map {|s| td(s) }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
table_end
|
207
|
+
end
|
208
|
+
|
209
|
+
def table_header(id, caption)
|
210
|
+
if get_chap.nil?
|
211
|
+
puts %Q[#{I18n.t("table")}#{I18n.t("format_number_header_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
|
212
|
+
else
|
213
|
+
puts %Q[#{I18n.t("table")}#{I18n.t("format_number_header", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
|
214
|
+
end
|
215
|
+
blank
|
216
|
+
end
|
217
|
+
|
218
|
+
def table_begin(ncols)
|
219
|
+
end
|
220
|
+
|
221
|
+
def tr(rows)
|
222
|
+
puts "|#{rows.join("|")}|"
|
223
|
+
end
|
224
|
+
|
225
|
+
def table_border(ncols)
|
226
|
+
puts (0..ncols).map{"|"}.join(":--")
|
227
|
+
end
|
228
|
+
|
229
|
+
def th(str)
|
230
|
+
"#{str}"
|
231
|
+
end
|
232
|
+
|
233
|
+
def td(str)
|
234
|
+
"#{str}"
|
235
|
+
end
|
236
|
+
|
237
|
+
def table_end
|
238
|
+
blank
|
239
|
+
end
|
240
|
+
|
241
|
+
def footnote(id, str)
|
242
|
+
puts "[^#{id}]: #{compile_inline(str)}"
|
243
|
+
blank
|
244
|
+
end
|
245
|
+
|
246
|
+
def inline_fn(id)
|
247
|
+
"[^#{id}]"
|
248
|
+
end
|
249
|
+
|
250
|
+
def inline_br(str)
|
251
|
+
"\n"
|
252
|
+
end
|
253
|
+
|
132
254
|
def nofunc_text(str)
|
133
255
|
str
|
134
256
|
end
|
@@ -0,0 +1,291 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2014 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
|
+
def error(msg)
|
26
|
+
$stderr.puts "#{File.basename($0, '.*')}: error: #{msg}"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def warn(msg)
|
31
|
+
$stderr.puts "#{File.basename($0, '.*')}: warning: #{msg}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_book(config)
|
35
|
+
pdf_file = config["bookname"]+".pdf"
|
36
|
+
if File.exist? pdf_file
|
37
|
+
error "file already exists:#{pdf_file}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_path(config)
|
42
|
+
"./#{config["bookname"]}-pdf"
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_compile_status(ignore_errors)
|
46
|
+
return unless @compile_errors
|
47
|
+
|
48
|
+
if ignore_errors
|
49
|
+
$stderr.puts "compile error, but try to generate PDF file"
|
50
|
+
else
|
51
|
+
error "compile error, No PDF file output."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.execute(*args)
|
56
|
+
self.new.execute(*args)
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_opts(args)
|
60
|
+
cmd_config = Hash.new
|
61
|
+
opts = OptionParser.new
|
62
|
+
|
63
|
+
opts.banner = "Usage: review-pdfmaker configfile"
|
64
|
+
opts.version = ReVIEW::VERSION
|
65
|
+
opts.on('--help', 'Prints this message and quit.') do
|
66
|
+
puts opts.help
|
67
|
+
exit 0
|
68
|
+
end
|
69
|
+
opts.on('--[no-]debug', 'Keep temporary files.') do |debug|
|
70
|
+
cmd_config["debug"] = debug
|
71
|
+
end
|
72
|
+
opts.on('--ignore-errors', 'Ignore review-compile errors.') do
|
73
|
+
cmd_config["ignore-errors"] = true
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.parse!(args)
|
77
|
+
if args.size != 1
|
78
|
+
puts opts.help
|
79
|
+
exit 0
|
80
|
+
end
|
81
|
+
|
82
|
+
return cmd_config, args[0]
|
83
|
+
end
|
84
|
+
|
85
|
+
def execute(*args)
|
86
|
+
config = ReVIEW::Configure.values
|
87
|
+
cmd_config, yamlfile = parse_opts(args)
|
88
|
+
|
89
|
+
config.merge!(YAML.load_file(yamlfile))
|
90
|
+
# YAML configs will be overridden by command line options.
|
91
|
+
config.merge!(cmd_config)
|
92
|
+
generate_pdf(config)
|
93
|
+
end
|
94
|
+
|
95
|
+
def generate_pdf(config)
|
96
|
+
check_book(config)
|
97
|
+
@basedir = Dir.pwd
|
98
|
+
@path = build_path(config)
|
99
|
+
bookname = config["bookname"]
|
100
|
+
Dir.mkdir(@path)
|
101
|
+
|
102
|
+
@chaps_fnames = Hash.new{|h, key| h[key] = ""}
|
103
|
+
@compile_errors = nil
|
104
|
+
|
105
|
+
ReVIEW::Book.load(@basedir).parts.each do |part|
|
106
|
+
if part.name.present?
|
107
|
+
if part.file?
|
108
|
+
output_parts(part.name, config)
|
109
|
+
@chaps_fnames["CHAPS"] << %Q|\\input{#{part.name}.tex}\n|
|
110
|
+
else
|
111
|
+
@chaps_fnames["CHAPS"] << %Q|\\part{#{part.name}}\n|
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
part.chapters.each do |chap|
|
116
|
+
filename = "#{File.basename(chap.path, ".*")}.tex"
|
117
|
+
output_chaps(filename, config)
|
118
|
+
@chaps_fnames["PREDEF"] << "\\input{#{filename}}\n" if chap.on_PREDEF?
|
119
|
+
@chaps_fnames["CHAPS"] << "\\input{#{filename}}\n" if chap.on_CHAPS?
|
120
|
+
@chaps_fnames["APPENDIX"] << "\\input{#{filename}}\n" if chap.on_APPENDIX?
|
121
|
+
@chaps_fnames["POSTDEF"] << "\\input{#{filename}}\n" if chap.on_POSTDEF?
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
check_compile_status(config["ignore-errors"])
|
126
|
+
|
127
|
+
config["pre_str"] = @chaps_fnames["PREDEF"]
|
128
|
+
config["chap_str"] = @chaps_fnames["CHAPS"]
|
129
|
+
config["appendix_str"] = @chaps_fnames["APPENDIX"]
|
130
|
+
config["post_str"] = @chaps_fnames["POSTDEF"]
|
131
|
+
|
132
|
+
config["usepackage"] = ""
|
133
|
+
if config["texstyle"]
|
134
|
+
config["usepackage"] = "\\usepackage{#{config['texstyle']}}"
|
135
|
+
end
|
136
|
+
|
137
|
+
copy_images("./images", "#{@path}/images")
|
138
|
+
copyStyToDir(Dir.pwd + "/sty", @path)
|
139
|
+
copyStyToDir(Dir.pwd, @path, "tex")
|
140
|
+
|
141
|
+
Dir.chdir(@path) {
|
142
|
+
template = get_template(config)
|
143
|
+
File.open("./book.tex", "wb"){|f| f.write(template)}
|
144
|
+
|
145
|
+
## do compile
|
146
|
+
enc = config["params"].to_s.split(/\s+/).find{|i| i =~ /\A--outencoding=/ }
|
147
|
+
kanji = 'utf8'
|
148
|
+
if enc
|
149
|
+
kanji = enc.split(/\=/).last.gsub(/-/, '').downcase
|
150
|
+
end
|
151
|
+
texcommand = config["texcommand"] || "platex"
|
152
|
+
3.times do
|
153
|
+
system("#{texcommand} -kanji=#{kanji} book.tex")
|
154
|
+
end
|
155
|
+
if File.exist?("book.dvi")
|
156
|
+
system("dvipdfmx -d 5 book.dvi")
|
157
|
+
end
|
158
|
+
}
|
159
|
+
FileUtils.cp("#{@path}/book.pdf", "#{@basedir}/#{bookname}.pdf")
|
160
|
+
|
161
|
+
unless config["debug"]
|
162
|
+
remove_entry_secure @path
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def output_chaps(filename, config)
|
167
|
+
$stderr.puts "compiling #{filename}"
|
168
|
+
cmd = "#{ReVIEW::MakerHelper.bindir}/review-compile --target=latex --level=#{config["secnolevel"]} --toclevel=#{config["toclevel"]} #{config["params"]} #{filename} > #{@path}/#{filename}"
|
169
|
+
if system cmd
|
170
|
+
# OK
|
171
|
+
else
|
172
|
+
@compile_errors = true
|
173
|
+
warn cmd
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def output_parts(filename, config)
|
178
|
+
$stderr.puts "compiling #{filename}.tex"
|
179
|
+
cmd = "review-compile --target=latex --level=#{config["secnolevel"]} --toclevel=#{config["toclevel"]} #{config["params"]} #{filename}.re | sed -e s/\\chapter{/\\part{/ > #{@path}/#{filename}.tex"
|
180
|
+
if system cmd
|
181
|
+
# OK
|
182
|
+
else
|
183
|
+
@compile_errors = true
|
184
|
+
warn cmd
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
def copy_images(from, to)
|
190
|
+
if File.exist?(from)
|
191
|
+
Dir.mkdir(to)
|
192
|
+
ReVIEW::MakerHelper.copy_images_to_dir(from, to)
|
193
|
+
Dir.chdir(to) do
|
194
|
+
images = Dir.glob("**/*").find_all{|f|
|
195
|
+
File.file?(f) and f =~ /\.(jpg|jpeg|png|pdf)\z/
|
196
|
+
}
|
197
|
+
system("extractbb", *images)
|
198
|
+
unless system("extractbb", "-m", *images)
|
199
|
+
system("ebb", *images)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def make_custom_titlepage(coverfile)
|
206
|
+
coverfile_sty = coverfile.to_s.sub(/\.[^.]+$/, ".tex")
|
207
|
+
if File.exist?(coverfile_sty)
|
208
|
+
File.read(coverfile_sty)
|
209
|
+
else
|
210
|
+
nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def join_with_separator(value, sep)
|
215
|
+
if value.kind_of? Array
|
216
|
+
value.join(sep)
|
217
|
+
else
|
218
|
+
value
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def make_colophon_role(role, config)
|
223
|
+
if config[role].present?
|
224
|
+
return "#{ReVIEW::I18n.t(role)} & #{escape_latex(join_with_separator(config[role], ReVIEW::I18n.t("names_splitter")))} \\\\\n"
|
225
|
+
else
|
226
|
+
""
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def make_colophon(config)
|
231
|
+
colophon = ""
|
232
|
+
config["colophon_order"].each do |role|
|
233
|
+
colophon += make_colophon_role(role, config)
|
234
|
+
end
|
235
|
+
colophon
|
236
|
+
end
|
237
|
+
|
238
|
+
def make_authors(config)
|
239
|
+
authors = ""
|
240
|
+
if config["aut"].present?
|
241
|
+
authors = join_with_separator(config["aut"], ReVIEW::I18n.t("names_splitter")) + ReVIEW::I18n.t("author_postfix")
|
242
|
+
end
|
243
|
+
if config["csl"].present?
|
244
|
+
authors += " \\\\\n"+join_with_separator(config["csl"], ReVIEW::I18n.t("names_splitter")) + ReVIEW::I18n.t("supervisor_postfix")
|
245
|
+
end
|
246
|
+
if config["trl"].present?
|
247
|
+
authors += " \\\\\n"+join_with_separator(config["trl"], ReVIEW::I18n.t("names_splitter")) + ReVIEW::I18n.t("translator_postfix")
|
248
|
+
end
|
249
|
+
authors
|
250
|
+
end
|
251
|
+
|
252
|
+
def get_template(config)
|
253
|
+
dclass = config["texdocumentclass"] || []
|
254
|
+
documentclass = dclass[0] || "jsbook"
|
255
|
+
documentclassoption = dclass[1] || "oneside"
|
256
|
+
|
257
|
+
okuduke = make_colophon(config)
|
258
|
+
authors = make_authors(config)
|
259
|
+
|
260
|
+
custom_titlepage = make_custom_titlepage(config["coverfile"])
|
261
|
+
|
262
|
+
template = File.expand_path('layout.tex.erb', File.dirname(__FILE__))
|
263
|
+
layout_file = File.join(@basedir, "layouts", "layout.tex.erb")
|
264
|
+
if File.exist?(layout_file)
|
265
|
+
template = layout_file
|
266
|
+
end
|
267
|
+
|
268
|
+
erb = ERB.new(File.open(template).read)
|
269
|
+
values = config # must be 'values' for legacy files
|
270
|
+
erb.result(binding)
|
271
|
+
end
|
272
|
+
|
273
|
+
def copyStyToDir(dirname, copybase, extname = "sty")
|
274
|
+
unless File.directory?(dirname)
|
275
|
+
$stderr.puts "No such directory - #{dirname}"
|
276
|
+
return
|
277
|
+
end
|
278
|
+
|
279
|
+
Dir.open(dirname) {|dir|
|
280
|
+
dir.each {|fname|
|
281
|
+
next if fname =~ /^\./
|
282
|
+
if fname =~ /\.(#{extname})$/i
|
283
|
+
Dir.mkdir(copybase) unless File.exist?(copybase)
|
284
|
+
FileUtils.cp "#{dirname}/#{fname}", copybase
|
285
|
+
end
|
286
|
+
}
|
287
|
+
}
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|