review 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/epubmaker/epubcommon.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
1
|
# = epubcommon.rb -- super class for EPUBv2 and EPUBv3
|
|
4
2
|
#
|
|
5
3
|
# Copyright (c) 2010-2017 Kenshi Muto and Masayoshi Takahashi
|
|
@@ -15,10 +13,9 @@ require 'review/template'
|
|
|
15
13
|
require 'cgi'
|
|
16
14
|
|
|
17
15
|
module EPUBMaker
|
|
18
|
-
|
|
19
16
|
# EPUBCommon is the common class for EPUB producer.
|
|
20
17
|
class EPUBCommon
|
|
21
|
-
# Construct object with parameter hash +
|
|
18
|
+
# Construct object with parameter hash +config+ and message resource hash +res+.
|
|
22
19
|
def initialize(producer)
|
|
23
20
|
@body_ext = ''
|
|
24
21
|
@producer = producer
|
|
@@ -27,41 +24,41 @@ module EPUBMaker
|
|
|
27
24
|
|
|
28
25
|
# Return mimetype content.
|
|
29
26
|
def mimetype
|
|
30
|
-
|
|
27
|
+
'application/epub+zip'
|
|
31
28
|
end
|
|
32
29
|
|
|
33
30
|
def opf_path
|
|
34
|
-
"OEBPS/#{@producer.
|
|
31
|
+
"OEBPS/#{@producer.config['bookname']}.opf"
|
|
35
32
|
end
|
|
36
33
|
|
|
37
34
|
def opf_coverimage
|
|
38
|
-
s =
|
|
39
|
-
if @producer.
|
|
35
|
+
s = ''
|
|
36
|
+
if @producer.config['coverimage']
|
|
40
37
|
file = nil
|
|
41
38
|
@producer.contents.each do |item|
|
|
42
|
-
if item.media.start_with?('image')
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
next if !item.media.start_with?('image') || item.file !~ /#{@producer.config["coverimage"]}\Z/
|
|
40
|
+
|
|
41
|
+
s << %Q( <meta name="cover" content="#{item.id}"/>\n)
|
|
42
|
+
file = item.file
|
|
43
|
+
break
|
|
47
44
|
end
|
|
48
|
-
raise "coverimage #{@producer.
|
|
45
|
+
raise "coverimage #{@producer.config['coverimage']} not found. Abort." if file.nil?
|
|
49
46
|
end
|
|
50
47
|
s
|
|
51
48
|
end
|
|
52
49
|
|
|
53
50
|
def ncx_isbn
|
|
54
|
-
uid = @producer.
|
|
55
|
-
%Q
|
|
51
|
+
uid = @producer.config['isbn'] || @producer.config['urnid']
|
|
52
|
+
%Q( <meta name="dtb:uid" content="#{uid}"/>\n)
|
|
56
53
|
end
|
|
57
54
|
|
|
58
55
|
def ncx_doctitle
|
|
59
56
|
<<EOT
|
|
60
57
|
<docTitle>
|
|
61
|
-
<text>#{CGI.escapeHTML(@producer.
|
|
58
|
+
<text>#{CGI.escapeHTML(@producer.config['title'])}</text>
|
|
62
59
|
</docTitle>
|
|
63
60
|
<docAuthor>
|
|
64
|
-
<text>#{@producer.
|
|
61
|
+
<text>#{@producer.config['aut'].nil? ? '' : CGI.escapeHTML(join_with_separator(@producer.config['aut'], ReVIEW::I18n.t('names_splitter')))}</text>
|
|
65
62
|
</docAuthor>
|
|
66
63
|
EOT
|
|
67
64
|
end
|
|
@@ -71,21 +68,21 @@ EOT
|
|
|
71
68
|
<navMap>
|
|
72
69
|
<navPoint id="top" playOrder="1">
|
|
73
70
|
<navLabel>
|
|
74
|
-
<text>#{CGI.escapeHTML(@producer.
|
|
71
|
+
<text>#{CGI.escapeHTML(@producer.config['title'])}</text>
|
|
75
72
|
</navLabel>
|
|
76
|
-
<content src="#{@producer.
|
|
73
|
+
<content src="#{@producer.config['cover']}"/>
|
|
77
74
|
</navPoint>
|
|
78
75
|
EOT
|
|
79
76
|
|
|
80
77
|
nav_count = 2
|
|
81
78
|
|
|
82
|
-
unless @producer.
|
|
79
|
+
unless @producer.config['mytoc'].nil?
|
|
83
80
|
s << <<EOT
|
|
84
81
|
<navPoint id="toc" playOrder="#{nav_count}">
|
|
85
82
|
<navLabel>
|
|
86
|
-
<text>#{CGI.escapeHTML(@producer.res.v(
|
|
83
|
+
<text>#{CGI.escapeHTML(@producer.res.v('toctitle'))}</text>
|
|
87
84
|
</navLabel>
|
|
88
|
-
<content src="#{@producer.
|
|
85
|
+
<content src="#{@producer.config['bookname']}-toc.#{@producer.config['htmlext']}"/>
|
|
89
86
|
</navPoint>
|
|
90
87
|
EOT
|
|
91
88
|
nav_count += 1
|
|
@@ -93,7 +90,7 @@ EOT
|
|
|
93
90
|
|
|
94
91
|
@producer.contents.each do |item|
|
|
95
92
|
next if item.title.nil?
|
|
96
|
-
indent = indentarray.nil? ? [
|
|
93
|
+
indent = indentarray.nil? ? [''] : indentarray
|
|
97
94
|
level = item.level.nil? ? 0 : (item.level - 1)
|
|
98
95
|
level = indent.size - 1 if level >= indent.size
|
|
99
96
|
s << <<EOT
|
|
@@ -122,38 +119,36 @@ EOT
|
|
|
122
119
|
end
|
|
123
120
|
|
|
124
121
|
# Return cover content.
|
|
125
|
-
def cover(type=nil)
|
|
126
|
-
@body_ext = type.nil? ?
|
|
122
|
+
def cover(type = nil)
|
|
123
|
+
@body_ext = type.nil? ? '' : %Q( epub:type="#{type}")
|
|
127
124
|
|
|
128
|
-
if @producer.
|
|
125
|
+
if @producer.config['coverimage']
|
|
129
126
|
file = @producer.coverimage
|
|
130
|
-
|
|
131
|
-
raise "coverimage #{@producer.params["coverimage"]} not found. Abort."
|
|
132
|
-
end
|
|
127
|
+
raise "coverimage #{@producer.config['coverimage']} not found. Abort." unless file
|
|
133
128
|
@body = <<-EOT
|
|
134
129
|
<div id="cover-image" class="cover-image">
|
|
135
|
-
<img src="#{file}" alt="#{CGI.escapeHTML(@producer.
|
|
130
|
+
<img src="#{file}" alt="#{CGI.escapeHTML(@producer.config.name_of('title'))}" class="max"/>
|
|
136
131
|
</div>
|
|
137
132
|
EOT
|
|
138
133
|
else
|
|
139
134
|
@body = <<-EOT
|
|
140
|
-
<h1 class="cover-title">#{CGI.escapeHTML(@producer.
|
|
135
|
+
<h1 class="cover-title">#{CGI.escapeHTML(@producer.config.name_of('title'))}</h1>
|
|
141
136
|
EOT
|
|
142
|
-
if @producer.
|
|
137
|
+
if @producer.config['subtitle']
|
|
143
138
|
@body << <<-EOT
|
|
144
|
-
<h2 class="cover-subtitle">#{CGI.escapeHTML(@producer.
|
|
139
|
+
<h2 class="cover-subtitle">#{CGI.escapeHTML(@producer.config.name_of('subtitle'))}</h2>
|
|
145
140
|
EOT
|
|
146
141
|
end
|
|
147
142
|
end
|
|
148
143
|
|
|
149
|
-
@title = CGI.escapeHTML(@producer.
|
|
150
|
-
@language = @producer.
|
|
151
|
-
@stylesheets = @producer.
|
|
152
|
-
if @producer.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
144
|
+
@title = CGI.escapeHTML(@producer.config.name_of('title'))
|
|
145
|
+
@language = @producer.config['language']
|
|
146
|
+
@stylesheets = @producer.config['stylesheet']
|
|
147
|
+
tmplfile = if @producer.config['htmlversion'].to_i == 5
|
|
148
|
+
File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
149
|
+
else
|
|
150
|
+
File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
151
|
+
end
|
|
157
152
|
tmpl = ReVIEW::Template.load(tmplfile)
|
|
158
153
|
tmpl.result(binding)
|
|
159
154
|
end
|
|
@@ -162,29 +157,29 @@ EOT
|
|
|
162
157
|
# NOTE: this method is not used yet.
|
|
163
158
|
# see lib/review/epubmaker.rb#build_titlepage
|
|
164
159
|
def titlepage
|
|
165
|
-
@title = CGI.escapeHTML(@producer.
|
|
160
|
+
@title = CGI.escapeHTML(@producer.config.name_of('title'))
|
|
166
161
|
|
|
167
162
|
@body = <<EOT
|
|
168
163
|
<h1 class="tp-title">#{@title}</h1>
|
|
169
164
|
EOT
|
|
170
165
|
|
|
171
|
-
if @producer.
|
|
166
|
+
if @producer.config['subtitle']
|
|
172
167
|
@body << <<EOT
|
|
173
|
-
<h2 class="tp-subtitle">#{CGI.escapeHTML(@producer.
|
|
168
|
+
<h2 class="tp-subtitle">#{CGI.escapeHTML(@producer.config.name_of('subtitle'))}</h2>
|
|
174
169
|
EOT
|
|
175
170
|
end
|
|
176
171
|
|
|
177
|
-
if @producer.
|
|
172
|
+
if @producer.config['aut']
|
|
178
173
|
@body << <<EOT
|
|
179
174
|
<p>
|
|
180
175
|
<br />
|
|
181
176
|
<br />
|
|
182
177
|
</p>
|
|
183
|
-
<h2 class="tp-author">#{CGI.escapeHTML(join_with_separator(@producer.
|
|
178
|
+
<h2 class="tp-author">#{CGI.escapeHTML(join_with_separator(@producer.config.names_of('aut'), ReVIEW::I18n.t('names_splitter')))}</h2>
|
|
184
179
|
EOT
|
|
185
180
|
end
|
|
186
181
|
|
|
187
|
-
publisher = @producer.
|
|
182
|
+
publisher = @producer.config.names_of('pbl')
|
|
188
183
|
if publisher
|
|
189
184
|
@body << <<EOT
|
|
190
185
|
<p>
|
|
@@ -193,123 +188,117 @@ EOT
|
|
|
193
188
|
<br />
|
|
194
189
|
<br />
|
|
195
190
|
</p>
|
|
196
|
-
<h3 class="tp-publisher">#{CGI.escapeHTML(join_with_separator(publisher, ReVIEW::I18n.t(
|
|
191
|
+
<h3 class="tp-publisher">#{CGI.escapeHTML(join_with_separator(publisher, ReVIEW::I18n.t('names_splitter')))}</h3>
|
|
197
192
|
EOT
|
|
198
193
|
end
|
|
199
194
|
|
|
200
|
-
@language = @producer.
|
|
201
|
-
@stylesheets = @producer.
|
|
202
|
-
if @producer.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
195
|
+
@language = @producer.config['language']
|
|
196
|
+
@stylesheets = @producer.config['stylesheet']
|
|
197
|
+
tmplfile = if @producer.config['htmlversion'].to_i == 5
|
|
198
|
+
File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
199
|
+
else
|
|
200
|
+
File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
201
|
+
end
|
|
207
202
|
tmpl = ReVIEW::Template.load(tmplfile)
|
|
208
203
|
tmpl.result(binding)
|
|
209
204
|
end
|
|
210
205
|
|
|
211
206
|
# Return colophon content.
|
|
212
207
|
def colophon
|
|
213
|
-
@title = CGI.escapeHTML(@producer.res.v(
|
|
208
|
+
@title = CGI.escapeHTML(@producer.res.v('colophontitle'))
|
|
214
209
|
@body = <<EOT
|
|
215
210
|
<div class="colophon">
|
|
216
211
|
EOT
|
|
217
212
|
|
|
218
|
-
if @producer.
|
|
213
|
+
if @producer.config['subtitle'].nil?
|
|
219
214
|
@body << <<EOT
|
|
220
|
-
<p class="title">#{CGI.escapeHTML(@producer.
|
|
215
|
+
<p class="title">#{CGI.escapeHTML(@producer.config.name_of('title'))}</p>
|
|
221
216
|
EOT
|
|
222
217
|
else
|
|
223
218
|
@body << <<EOT
|
|
224
|
-
<p class="title">#{CGI.escapeHTML(@producer.
|
|
219
|
+
<p class="title">#{CGI.escapeHTML(@producer.config.name_of('title'))}<br /><span class="subtitle">#{CGI.escapeHTML(@producer.config.name_of('subtitle'))}</span></p>
|
|
225
220
|
EOT
|
|
226
221
|
end
|
|
227
222
|
|
|
228
|
-
if @producer.
|
|
229
|
-
@body << colophon_history
|
|
230
|
-
end
|
|
223
|
+
@body << colophon_history if @producer.config['date'] || @producer.config['history']
|
|
231
224
|
|
|
232
|
-
@body << %Q
|
|
233
|
-
@body << @producer.
|
|
234
|
-
if @producer.
|
|
235
|
-
%Q
|
|
225
|
+
@body << %Q( <table class="colophon">\n)
|
|
226
|
+
@body << @producer.config['colophon_order'].map do |role|
|
|
227
|
+
if @producer.config[role]
|
|
228
|
+
%Q( <tr><th>#{CGI.escapeHTML(@producer.res.v(role))}</th><td>#{CGI.escapeHTML(join_with_separator(@producer.config.names_of(role), ReVIEW::I18n.t('names_splitter')))}</td></tr>\n)
|
|
236
229
|
else
|
|
237
|
-
|
|
230
|
+
''
|
|
238
231
|
end
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if @producer.isbn_hyphen
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
@body << %Q
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
254
|
-
else
|
|
255
|
-
tmplfile = File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
256
|
-
end
|
|
232
|
+
end.join
|
|
233
|
+
|
|
234
|
+
@body << %Q( <tr><th>ISBN</th><td>#{@producer.isbn_hyphen}</td></tr>\n) if @producer.isbn_hyphen
|
|
235
|
+
@body << %Q( </table>\n)
|
|
236
|
+
@body << %Q( <p class="copyright">#{join_with_separator(@producer.config.names_of('rights').map { |m| CGI.escapeHTML(m) }, '<br />')}</p>\n) if @producer.config['rights'] && !@producer.config['rights'].empty?
|
|
237
|
+
@body << %Q( </div>\n)
|
|
238
|
+
|
|
239
|
+
@language = @producer.config['language']
|
|
240
|
+
@stylesheets = @producer.config['stylesheet']
|
|
241
|
+
tmplfile = if @producer.config['htmlversion'].to_i == 5
|
|
242
|
+
File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
243
|
+
else
|
|
244
|
+
File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
245
|
+
end
|
|
257
246
|
tmpl = ReVIEW::Template.load(tmplfile)
|
|
258
247
|
tmpl.result(binding)
|
|
259
248
|
end
|
|
260
249
|
|
|
261
250
|
def colophon_history
|
|
262
|
-
buf =
|
|
263
|
-
buf << %Q
|
|
264
|
-
if @producer.
|
|
265
|
-
@producer.
|
|
251
|
+
buf = ''
|
|
252
|
+
buf << %Q( <div class="pubhistory">\n)
|
|
253
|
+
if @producer.config['history']
|
|
254
|
+
@producer.config['history'].each_with_index do |items, edit|
|
|
266
255
|
items.each_with_index do |item, rev|
|
|
267
|
-
editstr =
|
|
268
|
-
revstr = ReVIEW::I18n.t(
|
|
256
|
+
editstr = edit == 0 ? ReVIEW::I18n.t('first_edition') : ReVIEW::I18n.t('nth_edition', (edit + 1).to_s)
|
|
257
|
+
revstr = ReVIEW::I18n.t('nth_impression', (rev + 1).to_s)
|
|
269
258
|
if item =~ /\A\d+\-\d+\-\d+\Z/
|
|
270
|
-
buf << %Q
|
|
259
|
+
buf << %Q( <p>#{ReVIEW::I18n.t('published_by1', [date_to_s(item), editstr + revstr])}</p>\n)
|
|
271
260
|
elsif item =~ /\A(\d+\-\d+\-\d+)[\s ](.+)/
|
|
272
261
|
# custom date with string
|
|
273
262
|
item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
|
|
274
|
-
buf << %Q
|
|
263
|
+
buf << %Q( <p>#{ReVIEW::I18n.t('published_by3', [date_to_s(m[1]), m[2]])}</p>\n)
|
|
275
264
|
end
|
|
276
265
|
else
|
|
277
266
|
# free format
|
|
278
|
-
buf << %Q
|
|
267
|
+
buf << %Q( <p>#{item}</p>\n)
|
|
279
268
|
end
|
|
280
269
|
end
|
|
281
270
|
end
|
|
282
271
|
else
|
|
283
|
-
buf << %Q
|
|
272
|
+
buf << %Q( <p>#{ReVIEW::I18n.t('published_by2', date_to_s(@producer.config['date']))}</p>\n)
|
|
284
273
|
end
|
|
285
|
-
buf << %Q
|
|
274
|
+
buf << %Q( </div>\n)
|
|
286
275
|
buf
|
|
287
276
|
end
|
|
288
277
|
|
|
289
278
|
def date_to_s(date)
|
|
290
279
|
require 'date'
|
|
291
280
|
d = Date.parse(date)
|
|
292
|
-
d.strftime(ReVIEW::I18n.t(
|
|
281
|
+
d.strftime(ReVIEW::I18n.t('date_format'))
|
|
293
282
|
end
|
|
294
283
|
|
|
295
284
|
# Return own toc content.
|
|
296
285
|
def mytoc
|
|
297
|
-
@title = CGI.escapeHTML(@producer.res.v(
|
|
286
|
+
@title = CGI.escapeHTML(@producer.res.v('toctitle'))
|
|
298
287
|
|
|
299
|
-
@body = %Q
|
|
300
|
-
if @producer.
|
|
301
|
-
@body << hierarchy_ncx(
|
|
288
|
+
@body = %Q( <h1 class="toc-title">#{CGI.escapeHTML(@producer.res.v('toctitle'))}</h1>\n)
|
|
289
|
+
if @producer.config['epubmaker']['flattoc'].nil?
|
|
290
|
+
@body << hierarchy_ncx('ul')
|
|
302
291
|
else
|
|
303
|
-
@body << flat_ncx(
|
|
292
|
+
@body << flat_ncx('ul', @producer.config['epubmaker']['flattocindent'])
|
|
304
293
|
end
|
|
305
294
|
|
|
306
|
-
@language = @producer.
|
|
307
|
-
@stylesheets = @producer.
|
|
308
|
-
if @producer.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
295
|
+
@language = @producer.config['language']
|
|
296
|
+
@stylesheets = @producer.config['stylesheet']
|
|
297
|
+
tmplfile = if @producer.config['htmlversion'].to_i == 5
|
|
298
|
+
File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
299
|
+
else
|
|
300
|
+
File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
|
|
301
|
+
end
|
|
313
302
|
tmpl = ReVIEW::Template.load(tmplfile)
|
|
314
303
|
tmpl.result(binding)
|
|
315
304
|
end
|
|
@@ -319,25 +308,25 @@ EOT
|
|
|
319
308
|
level = 1
|
|
320
309
|
find_jump = nil
|
|
321
310
|
has_part = nil
|
|
322
|
-
toclevel = @producer.
|
|
311
|
+
toclevel = @producer.config['toclevel'].to_i
|
|
323
312
|
|
|
324
313
|
# check part existance
|
|
325
314
|
@producer.contents.each do |item|
|
|
326
|
-
if item.notoc
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
315
|
+
next if item.notoc || item.chaptype != 'part'
|
|
316
|
+
|
|
317
|
+
has_part = true
|
|
318
|
+
break
|
|
330
319
|
end
|
|
331
320
|
|
|
332
|
-
if
|
|
321
|
+
if has_part
|
|
333
322
|
@producer.contents.each do |item|
|
|
334
|
-
item.level += 1 if item.chaptype ==
|
|
335
|
-
item.notoc = true if (item.chaptype ==
|
|
323
|
+
item.level += 1 if item.chaptype == 'part' || item.chaptype == 'body'
|
|
324
|
+
item.notoc = true if (item.chaptype == 'pre' || item.chaptype == 'post') && !item.level.nil? && (item.level + 1 == toclevel) # FIXME: part processing
|
|
336
325
|
end
|
|
337
326
|
toclevel += 1
|
|
338
327
|
end
|
|
339
328
|
|
|
340
|
-
doc = REXML::Document.new(%Q
|
|
329
|
+
doc = REXML::Document.new(%Q(<#{type} class="toc-h#{level}"><li /></#{type}>))
|
|
341
330
|
doc.context[:attribute_quote] = :quote
|
|
342
331
|
|
|
343
332
|
e = doc.root.elements[1] # first <li/>
|
|
@@ -345,7 +334,7 @@ EOT
|
|
|
345
334
|
next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > toclevel
|
|
346
335
|
|
|
347
336
|
if item.level == level
|
|
348
|
-
e2 = e.parent.add_element(
|
|
337
|
+
e2 = e.parent.add_element('li')
|
|
349
338
|
e = e2
|
|
350
339
|
elsif item.level > level
|
|
351
340
|
find_jump = true if (item.level - level) > 1
|
|
@@ -353,59 +342,57 @@ EOT
|
|
|
353
342
|
(level + 1).upto(item.level) do |n|
|
|
354
343
|
if e.size == 0
|
|
355
344
|
# empty span for epubcheck
|
|
356
|
-
e.attributes[
|
|
357
|
-
es = e.add_element(
|
|
358
|
-
es.add_text(REXML::Text.new(
|
|
345
|
+
e.attributes['style'] = 'list-style-type: none;'
|
|
346
|
+
es = e.add_element('span', 'style' => 'display:none;')
|
|
347
|
+
es.add_text(REXML::Text.new(' ', false, nil, true))
|
|
359
348
|
end
|
|
360
349
|
|
|
361
|
-
e2 = e.add_element(type,
|
|
362
|
-
e3 = e2.add_element(
|
|
350
|
+
e2 = e.add_element(type, 'class' => "toc-h#{n}")
|
|
351
|
+
e3 = e2.add_element('li')
|
|
363
352
|
e = e3
|
|
364
353
|
end
|
|
365
354
|
level = item.level
|
|
366
355
|
elsif item.level < level
|
|
367
356
|
# shallower
|
|
368
|
-
(level - 1).downto(item.level)
|
|
369
|
-
|
|
370
|
-
end
|
|
371
|
-
e2 = e.parent.add_element("li")
|
|
357
|
+
(level - 1).downto(item.level) { e = e.parent.parent }
|
|
358
|
+
e2 = e.parent.add_element('li')
|
|
372
359
|
e = e2
|
|
373
360
|
level = item.level
|
|
374
361
|
end
|
|
375
|
-
e2 = e.add_element(
|
|
362
|
+
e2 = e.add_element('a', 'href' => item.file)
|
|
376
363
|
e2.add_text(REXML::Text.new(item.title, true))
|
|
377
364
|
end
|
|
378
365
|
|
|
379
|
-
warn
|
|
366
|
+
warn %Q(found level jumping in table of contents. consider to use 'epubmaker:flattoc: true' for strict ePUB validator.) unless find_jump.nil?
|
|
380
367
|
|
|
381
|
-
doc.to_s.gsub(
|
|
368
|
+
doc.to_s.gsub('<li/>', '').gsub('</li>', "</li>\n").gsub("<#{type} ", "\n" + '\&') # ugly
|
|
382
369
|
end
|
|
383
370
|
|
|
384
|
-
def flat_ncx(type, indent=nil)
|
|
385
|
-
s = %Q
|
|
371
|
+
def flat_ncx(type, indent = nil)
|
|
372
|
+
s = %Q(<#{type} class="toc-h1">\n)
|
|
386
373
|
@producer.contents.each do |item|
|
|
387
|
-
next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > @producer.
|
|
388
|
-
is = indent == true ?
|
|
389
|
-
s << %Q
|
|
374
|
+
next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > @producer.config['toclevel'].to_i
|
|
375
|
+
is = indent == true ? ' ' * item.level : ''
|
|
376
|
+
s << %Q(<li><a href="#{item.file}">#{is}#{CGI.escapeHTML(item.title)}</a></li>\n)
|
|
390
377
|
end
|
|
391
|
-
s << %Q
|
|
378
|
+
s << %Q(</#{type}>\n)
|
|
392
379
|
|
|
393
380
|
s
|
|
394
381
|
end
|
|
395
382
|
|
|
396
383
|
def produce_write_common(basedir, tmpdir)
|
|
397
|
-
File.open("#{tmpdir}/mimetype",
|
|
384
|
+
File.open("#{tmpdir}/mimetype", 'w') { |f| @producer.mimetype(f) }
|
|
398
385
|
|
|
399
386
|
FileUtils.mkdir_p("#{tmpdir}/META-INF")
|
|
400
|
-
File.open("#{tmpdir}/META-INF/container.xml",
|
|
387
|
+
File.open("#{tmpdir}/META-INF/container.xml", 'w') { |f| @producer.container(f) }
|
|
401
388
|
|
|
402
389
|
FileUtils.mkdir_p("#{tmpdir}/OEBPS")
|
|
403
|
-
File.open(File.join(tmpdir, opf_path),
|
|
390
|
+
File.open(File.join(tmpdir, opf_path), 'w') { |f| @producer.opf(f) }
|
|
404
391
|
|
|
405
|
-
if File.exist?("#{basedir}/#{@producer.
|
|
406
|
-
FileUtils.cp("#{basedir}/#{@producer.
|
|
392
|
+
if File.exist?("#{basedir}/#{@producer.config['cover']}")
|
|
393
|
+
FileUtils.cp("#{basedir}/#{@producer.config['cover']}", "#{tmpdir}/OEBPS")
|
|
407
394
|
else
|
|
408
|
-
File.open("#{tmpdir}/OEBPS/#{@producer.
|
|
395
|
+
File.open("#{tmpdir}/OEBPS/#{@producer.config['cover']}", 'w') { |f| @producer.cover(f) }
|
|
409
396
|
end
|
|
410
397
|
|
|
411
398
|
@producer.contents.each do |item|
|
|
@@ -418,21 +405,21 @@ EOT
|
|
|
418
405
|
end
|
|
419
406
|
|
|
420
407
|
def legacy_cover_and_title_file(loadfile, writefile)
|
|
421
|
-
@title = @producer.
|
|
422
|
-
s =
|
|
408
|
+
@title = @producer.config['booktitle']
|
|
409
|
+
s = ''
|
|
423
410
|
File.open(loadfile) do |f|
|
|
424
411
|
f.each_line do |l|
|
|
425
412
|
s << l
|
|
426
413
|
end
|
|
427
414
|
end
|
|
428
415
|
|
|
429
|
-
File.open(writefile,
|
|
416
|
+
File.open(writefile, 'w') do |f|
|
|
430
417
|
f.puts s
|
|
431
418
|
end
|
|
432
419
|
end
|
|
433
420
|
|
|
434
421
|
def join_with_separator(value, sep)
|
|
435
|
-
if value.
|
|
422
|
+
if value.is_a?(Array)
|
|
436
423
|
value.join(sep)
|
|
437
424
|
else
|
|
438
425
|
value
|