review 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-tex.yml +31 -0
- data/.github/workflows/ruby-win.yml +3 -3
- data/.github/workflows/ruby.yml +1 -1
- data/.rubocop.yml +15 -7
- data/NEWS.ja.md +108 -0
- data/NEWS.md +108 -0
- data/README.md +7 -6
- data/Rakefile +7 -2
- data/bin/review +2 -4
- data/bin/review-catalog-converter +3 -3
- data/bin/review-check +6 -8
- data/bin/review-checkdep +1 -4
- data/bin/review-compile +2 -5
- data/bin/review-epub2html +1 -4
- data/bin/review-epubmaker +3 -4
- data/bin/review-idgxmlmaker +1 -3
- data/bin/review-index +11 -5
- data/bin/review-init +1 -4
- data/bin/review-pdfmaker +1 -3
- data/bin/review-preproc +2 -4
- data/bin/review-textmaker +1 -3
- data/bin/review-update +1 -4
- data/bin/review-validate +3 -3
- data/bin/review-vol +1 -4
- data/bin/review-webmaker +1 -3
- data/doc/config.yml.sample +21 -5
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +21 -10
- data/doc/format.md +21 -10
- data/doc/quickstart.ja.md +11 -1
- data/doc/quickstart.md +11 -2
- data/lib/review.rb +1 -1
- data/lib/review/book/base.rb +4 -0
- data/lib/review/book/book_unit.rb +3 -0
- data/lib/review/book/chapter.rb +3 -0
- data/lib/review/book/index.rb +1 -0
- data/lib/review/book/volume.rb +1 -0
- data/lib/review/builder.rb +8 -1
- data/lib/review/call_hook.rb +20 -0
- data/lib/review/catalog.rb +1 -0
- data/lib/review/compiler.rb +27 -10
- data/lib/review/configure.rb +64 -7
- data/lib/review/epubmaker.rb +93 -96
- data/lib/review/epubmaker/content.rb +113 -0
- data/lib/review/epubmaker/epubcommon.rb +372 -0
- data/lib/review/epubmaker/epubv2.rb +178 -0
- data/lib/review/epubmaker/epubv3.rb +231 -0
- data/lib/review/epubmaker/producer.rb +168 -0
- data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
- data/lib/review/epubmaker/zip_exporter.rb +84 -0
- data/lib/review/exception.rb +6 -0
- data/lib/review/htmlbuilder.rb +36 -49
- data/lib/review/htmlutils.rb +1 -1
- data/lib/review/i18n.rb +1 -0
- data/lib/review/idgxmlbuilder.rb +33 -30
- data/lib/review/idgxmlmaker.rb +3 -1
- data/lib/review/img_math.rb +245 -0
- data/lib/review/index_builder.rb +1 -0
- data/lib/review/init.rb +4 -4
- data/lib/review/latexbox.rb +58 -0
- data/lib/review/latexbuilder.rb +30 -19
- data/lib/review/latexutils.rb +9 -1
- data/lib/review/lineinput.rb +112 -2
- data/lib/review/logger.rb +41 -2
- data/lib/review/makerhelper.rb +2 -205
- data/lib/review/markdownbuilder.rb +32 -1
- data/lib/review/pdfmaker.rb +31 -29
- data/lib/review/plaintextbuilder.rb +9 -1
- data/lib/review/preprocessor.rb +12 -6
- data/lib/review/rstbuilder.rb +1 -1
- data/lib/review/sec_counter.rb +1 -0
- data/lib/review/template.rb +6 -0
- data/lib/review/textmaker.rb +11 -7
- data/lib/review/textutils.rb +2 -10
- data/lib/review/tocprinter.rb +85 -68
- data/lib/review/topbuilder.rb +18 -11
- data/lib/review/update.rb +5 -6
- data/lib/review/version.rb +1 -1
- data/lib/review/volumeprinter.rb +4 -5
- data/lib/review/webmaker.rb +18 -13
- data/lib/review/webtocprinter.rb +10 -9
- data/lib/review/yamlloader.rb +2 -1
- data/review.gemspec +5 -3
- data/samples/sample-book/src/config-epub2.yml +1 -1
- data/samples/sample-book/src/config.yml +1 -1
- data/samples/sample-book/src/lib/tasks/review.rake +17 -1
- data/samples/syntax-book/ch01.re +1 -1
- data/samples/syntax-book/ch02.re +21 -6
- data/samples/syntax-book/ch03.re +1 -1
- data/samples/syntax-book/images/img3-2.png +0 -0
- data/templates/html/_colophon.html.erb +23 -0
- data/templates/html/_colophon_history.html.erb +9 -0
- data/templates/html/_cover.html.erb +10 -0
- data/templates/html/_part_body.html.erb +6 -0
- data/templates/html/_titlepage.html.erb +20 -0
- data/templates/html/layout-html5.html.erb +6 -0
- data/templates/html/layout-xhtml1.html.erb +6 -0
- data/templates/latex/config.erb +8 -0
- data/templates/latex/review-jlreq/review-base.sty +4 -5
- data/templates/latex/review-jlreq/review-jlreq.cls +10 -2
- data/templates/latex/review-jlreq/review-style.sty +6 -1
- data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
- data/templates/latex/review-jsbook/review-base.sty +5 -7
- data/templates/latex/review-jsbook/review-jsbook.cls +10 -2
- data/templates/latex/review-jsbook/review-style.sty +6 -1
- data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
- data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
- data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
- data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
- data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
- data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
- data/templates/web/html/layout-html5.html.erb +6 -5
- data/templates/web/html/layout-xhtml1.html.erb +6 -0
- data/test/assets/header_listener.html +35 -0
- data/test/assets/img_math/img1.png +0 -0
- data/test/assets/img_math/img2.png +0 -0
- data/test/assets/img_math/img3.png +0 -0
- data/test/assets/syntax_book_index_detail.txt +58 -0
- data/test/assets/test_template.tex +4 -1
- data/test/assets/test_template_backmatter.tex +4 -1
- data/test/run_test.rb +1 -1
- data/test/test_book_chapter.rb +2 -2
- data/test/test_catalog_converter_cmd.rb +1 -1
- data/test/test_epub3maker.rb +168 -124
- data/test/test_epubmaker.rb +243 -131
- data/test/test_epubmaker_cmd.rb +2 -2
- data/test/test_helper.rb +5 -4
- data/test/test_htmlbuilder.rb +64 -6
- data/test/test_idgxmlbuilder.rb +13 -0
- data/test/test_idgxmlmaker_cmd.rb +7 -3
- data/test/test_img_math.rb +111 -0
- data/test/test_indexbuilder.rb +5 -5
- data/test/test_latexbuilder.rb +107 -4
- data/test/test_lineinput.rb +20 -93
- data/test/test_markdownbuilder.rb +29 -0
- data/test/test_pdfmaker.rb +71 -0
- data/test/test_pdfmaker_cmd.rb +2 -2
- data/test/test_plaintextbuilder.rb +10 -18
- data/test/test_reviewheaderlistener.rb +49 -0
- data/test/test_template.rb +12 -2
- data/test/test_textmaker_cmd.rb +5 -1
- data/test/test_tocprinter.rb +46 -0
- data/test/test_topbuilder.rb +6 -1
- data/test/test_update.rb +34 -34
- data/test/test_zip_exporter.rb +5 -6
- metadata +91 -17
- data/lib/epubmaker.rb +0 -23
- data/lib/epubmaker/content.rb +0 -111
- data/lib/epubmaker/epubcommon.rb +0 -449
- data/lib/epubmaker/epubv2.rb +0 -142
- data/lib/epubmaker/epubv3.rb +0 -235
- data/lib/epubmaker/producer.rb +0 -375
- data/lib/epubmaker/zip_exporter.rb +0 -81
- data/lib/lineinput.rb +0 -155
data/test/test_epubmaker.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'epubmaker'
|
3
2
|
require 'review/epubmaker'
|
4
3
|
|
5
4
|
class EPUBMakerTest < Test::Unit::TestCase
|
6
|
-
include EPUBMaker
|
7
|
-
|
8
5
|
def setup
|
9
|
-
|
10
|
-
|
6
|
+
config = ReVIEW::Configure.values
|
7
|
+
config.merge!(
|
11
8
|
'bookname' => 'sample',
|
12
9
|
'title' => 'Sample Book',
|
13
10
|
'epubversion' => 2,
|
@@ -16,30 +13,32 @@ class EPUBMakerTest < Test::Unit::TestCase
|
|
16
13
|
'language' => 'en',
|
17
14
|
'titlepage' => nil
|
18
15
|
)
|
19
|
-
@
|
16
|
+
@producer = ReVIEW::EPUBMaker::Producer.new(config)
|
20
17
|
end
|
21
18
|
|
22
19
|
def test_initialize
|
23
|
-
assert Producer.new
|
20
|
+
assert ReVIEW::EPUBMaker::Producer.new(ReVIEW::Configure.values)
|
24
21
|
end
|
25
22
|
|
26
23
|
def test_resource_en
|
27
|
-
@producer.
|
28
|
-
|
24
|
+
@producer.config['language'] = 'en'
|
25
|
+
@producer.modify_config
|
26
|
+
assert_equal 'Table of Contents', ReVIEW::I18n.t('toctitle')
|
29
27
|
end
|
30
28
|
|
31
29
|
def test_resource_ja
|
32
|
-
@producer.
|
33
|
-
|
30
|
+
@producer.config['language'] = 'ja'
|
31
|
+
@producer.modify_config
|
32
|
+
assert_equal '目次', ReVIEW::I18n.t('toctitle')
|
34
33
|
end
|
35
34
|
|
36
35
|
def test_mimetype
|
37
|
-
@producer.mimetype
|
38
|
-
assert_equal 'application/epub+zip',
|
36
|
+
output = @producer.instance_eval { @epub.mimetype }
|
37
|
+
assert_equal 'application/epub+zip', output
|
39
38
|
end
|
40
39
|
|
41
40
|
def test_container
|
42
|
-
@producer.container
|
41
|
+
output = @producer.instance_eval { @epub.container }
|
43
42
|
expect = <<EOT
|
44
43
|
<?xml version="1.0" encoding="UTF-8"?>
|
45
44
|
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
|
@@ -48,11 +47,11 @@ class EPUBMakerTest < Test::Unit::TestCase
|
|
48
47
|
</rootfiles>
|
49
48
|
</container>
|
50
49
|
EOT
|
51
|
-
assert_equal expect,
|
50
|
+
assert_equal expect, output
|
52
51
|
end
|
53
52
|
|
54
53
|
def test_stage1_opf
|
55
|
-
@producer.opf
|
54
|
+
output = @producer.instance_eval { @epub.opf }
|
56
55
|
expect = <<EOT
|
57
56
|
<?xml version="1.0" encoding="UTF-8"?>
|
58
57
|
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
|
@@ -74,12 +73,13 @@ EOT
|
|
74
73
|
</guide>
|
75
74
|
</package>
|
76
75
|
EOT
|
77
|
-
assert_equal expect,
|
76
|
+
assert_equal expect, output
|
78
77
|
end
|
79
78
|
|
80
79
|
def test_stage1_opf_escape
|
81
80
|
@producer.config['title'] = 'Sample<>Book'
|
82
|
-
@producer.
|
81
|
+
@producer.modify_config
|
82
|
+
output = @producer.instance_eval { @epub.opf }
|
83
83
|
expect = <<EOT
|
84
84
|
<?xml version="1.0" encoding="UTF-8"?>
|
85
85
|
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
|
@@ -101,11 +101,11 @@ EOT
|
|
101
101
|
</guide>
|
102
102
|
</package>
|
103
103
|
EOT
|
104
|
-
assert_equal expect,
|
104
|
+
assert_equal expect, output
|
105
105
|
end
|
106
106
|
|
107
107
|
def test_stage1_ncx
|
108
|
-
@producer.ncx(
|
108
|
+
output = @producer.instance_eval { @epub.ncx([]) }
|
109
109
|
expect = <<EOT
|
110
110
|
<?xml version="1.0" encoding="UTF-8"?>
|
111
111
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
@@ -131,12 +131,13 @@ EOT
|
|
131
131
|
</navMap>
|
132
132
|
</ncx>
|
133
133
|
EOT
|
134
|
-
assert_equal expect,
|
134
|
+
assert_equal expect, output
|
135
135
|
end
|
136
136
|
|
137
137
|
def test_stage1_ncx_escape
|
138
138
|
@producer.config['title'] = 'Sample<>Book'
|
139
|
-
@producer.
|
139
|
+
@producer.modify_config
|
140
|
+
output = @producer.instance_eval { @epub.ncx([]) }
|
140
141
|
expect = <<EOT
|
141
142
|
<?xml version="1.0" encoding="UTF-8"?>
|
142
143
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
@@ -162,27 +163,27 @@ EOT
|
|
162
163
|
</navMap>
|
163
164
|
</ncx>
|
164
165
|
EOT
|
165
|
-
assert_equal expect,
|
166
|
+
assert_equal expect, output
|
166
167
|
end
|
167
168
|
|
168
169
|
def stage2
|
169
170
|
# add one item
|
170
|
-
@producer.contents << Content.new(
|
171
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: 'CH01', level: 1)
|
171
172
|
end
|
172
173
|
|
173
174
|
def test_stage2_add_l1item
|
174
175
|
stage2
|
175
|
-
expect = EPUBMaker::Content.new('ch01.html',
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
expect = ReVIEW::EPUBMaker::Content.new(file: 'ch01.html',
|
177
|
+
id: 'ch01-html',
|
178
|
+
media: 'application/xhtml+xml',
|
179
|
+
title: 'CH01',
|
180
|
+
level: 1)
|
180
181
|
assert_equal expect, @producer.contents[0]
|
181
182
|
end
|
182
183
|
|
183
184
|
def test_stage2_opf
|
184
185
|
stage2
|
185
|
-
@producer.opf
|
186
|
+
output = @producer.instance_eval { @epub.opf }
|
186
187
|
expect = <<EOT
|
187
188
|
<?xml version="1.0" encoding="UTF-8"?>
|
188
189
|
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
|
@@ -206,12 +207,12 @@ EOT
|
|
206
207
|
</guide>
|
207
208
|
</package>
|
208
209
|
EOT
|
209
|
-
assert_equal expect,
|
210
|
+
assert_equal expect, output
|
210
211
|
end
|
211
212
|
|
212
213
|
def test_stage2_ncx
|
213
214
|
stage2
|
214
|
-
@producer.ncx(
|
215
|
+
output = @producer.instance_eval { @epub.ncx([]) }
|
215
216
|
expect = <<EOT
|
216
217
|
<?xml version="1.0" encoding="UTF-8"?>
|
217
218
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
@@ -243,54 +244,54 @@ EOT
|
|
243
244
|
</navMap>
|
244
245
|
</ncx>
|
245
246
|
EOT
|
246
|
-
assert_equal expect,
|
247
|
+
assert_equal expect, output
|
247
248
|
end
|
248
249
|
|
249
250
|
def stage3
|
250
251
|
# add more items
|
251
|
-
@producer.contents << Content.new(
|
252
|
-
@producer.contents << Content.new(
|
253
|
-
@producer.contents << Content.new(
|
254
|
-
@producer.contents << Content.new(
|
255
|
-
@producer.contents << Content.new(
|
256
|
-
@producer.contents << Content.new(
|
257
|
-
@producer.contents << Content.new(
|
258
|
-
@producer.contents << Content.new(
|
259
|
-
@producer.contents << Content.new(
|
260
|
-
@producer.contents << Content.new(
|
261
|
-
@producer.contents << Content.new(
|
262
|
-
@producer.contents << Content.new(
|
263
|
-
@producer.contents << Content.new(
|
264
|
-
@producer.contents << Content.new(
|
265
|
-
@producer.contents << Content.new(
|
266
|
-
@producer.contents << Content.new(
|
267
|
-
@producer.contents << Content.new(
|
268
|
-
@producer.contents << Content.new(
|
269
|
-
@producer.contents << Content.new(
|
252
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: %Q(CH01<>&"), level: 1)
|
253
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', title: 'CH02', level: 1)
|
254
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', title: 'CH02.1', level: 2)
|
255
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', title: 'CH02.1.1', level: 3)
|
256
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1', title: 'CH02.1.1.1', level: 4)
|
257
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1.1', title: 'CH02.1.1.1.1', level: 5)
|
258
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.2', title: 'CH02.1.1.2', level: 4)
|
259
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', title: 'CH02.2', level: 2)
|
260
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', title: 'CH02.2.1', level: 3)
|
261
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', title: 'CH03', level: 1)
|
262
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', title: 'CH03.1', level: 2)
|
263
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', title: 'CH03.1.1', level: 3)
|
264
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', title: 'CH04', level: 1)
|
265
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.png')
|
266
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg')
|
267
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG')
|
268
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG')
|
269
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF')
|
270
|
+
@producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.css')
|
270
271
|
end
|
271
272
|
|
272
273
|
def test_stage3_add_various_items
|
273
274
|
stage3
|
274
275
|
expect = [
|
275
|
-
Content.new('ch01.html', 'ch01-html', 'application/xhtml+xml', %Q(CH01<>&"), 1),
|
276
|
-
Content.new('ch02.html', 'ch02-html', 'application/xhtml+xml', 'CH02', 1),
|
277
|
-
Content.new('ch02.html#S1', 'ch02-html#S1', 'html#s1', 'CH02.1', 2),
|
278
|
-
Content.new('ch02.html#S1.1', 'ch02-html#S1-1', '1', 'CH02.1.1', 3),
|
279
|
-
Content.new('ch02.html#S1.1.1', 'ch02-html#S1-1-1', '1', 'CH02.1.1.1', 4),
|
280
|
-
Content.new('ch02.html#S1.1.1.1', 'ch02-html#S1-1-1-1', '1', 'CH02.1.1.1.1', 5),
|
281
|
-
Content.new('ch02.html#S1.1.2', 'ch02-html#S1-1-2', '2', 'CH02.1.1.2', 4),
|
282
|
-
Content.new('ch02.html#S2', 'ch02-html#S2', 'html#s2', 'CH02.2', 2),
|
283
|
-
Content.new('ch02.html#S2.1', 'ch02-html#S2-1', '1', 'CH02.2.1', 3),
|
284
|
-
Content.new('ch03.html', 'ch03-html', 'application/xhtml+xml', 'CH03', 1),
|
285
|
-
Content.new('ch03.html#S1', 'ch03-html#S1', 'html#s1', 'CH03.1', 2),
|
286
|
-
Content.new('ch03.html#S1.1', 'ch03-html#S1-1', '1', 'CH03.1.1', 3),
|
287
|
-
Content.new('ch04.html', 'ch04-html', 'application/xhtml+xml', 'CH04', 1),
|
288
|
-
Content.new('sample.png', 'sample-png', 'image/png'),
|
289
|
-
Content.new('sample.jpg', 'sample-jpg', 'image/jpeg'),
|
290
|
-
Content.new('sample.JPEG', 'sample-JPEG', 'image/jpeg'),
|
291
|
-
Content.new('sample.SvG', 'sample-SvG', 'image/svg+xml'),
|
292
|
-
Content.new('sample.GIF', 'sample-GIF', 'image/gif'),
|
293
|
-
Content.new('sample.css', 'sample-css', 'text/css')
|
276
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1),
|
277
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1),
|
278
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2),
|
279
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3),
|
280
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4),
|
281
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1.1', id: 'ch02-html#S1-1-1-1', media: '1', title: 'CH02.1.1.1.1', level: 5),
|
282
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4),
|
283
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2),
|
284
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3),
|
285
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1),
|
286
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2),
|
287
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3),
|
288
|
+
ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1),
|
289
|
+
ReVIEW::EPUBMaker::Content.new(file: 'sample.png', id: 'sample-png', media: 'image/png'),
|
290
|
+
ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg'),
|
291
|
+
ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg'),
|
292
|
+
ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml'),
|
293
|
+
ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif'),
|
294
|
+
ReVIEW::EPUBMaker::Content.new(file: 'sample.css', id: 'sample-css', media: 'text/css')
|
294
295
|
]
|
295
296
|
|
296
297
|
assert_equal expect, @producer.contents
|
@@ -298,7 +299,7 @@ EOT
|
|
298
299
|
|
299
300
|
def test_stage3_opf
|
300
301
|
stage3
|
301
|
-
@producer.opf
|
302
|
+
output = @producer.instance_eval { @epub.opf }
|
302
303
|
expect = <<EOT
|
303
304
|
<?xml version="1.0" encoding="UTF-8"?>
|
304
305
|
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
|
@@ -334,12 +335,12 @@ EOT
|
|
334
335
|
</guide>
|
335
336
|
</package>
|
336
337
|
EOT
|
337
|
-
assert_equal expect,
|
338
|
+
assert_equal expect, output
|
338
339
|
end
|
339
340
|
|
340
341
|
def test_stage3_ncx
|
341
342
|
stage3
|
342
|
-
@producer.ncx(
|
343
|
+
output = @producer.instance_eval { @epub.ncx([]) }
|
343
344
|
expect = <<EOT
|
344
345
|
<?xml version="1.0" encoding="UTF-8"?>
|
345
346
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
@@ -443,12 +444,14 @@ EOT
|
|
443
444
|
</navMap>
|
444
445
|
</ncx>
|
445
446
|
EOT
|
446
|
-
assert_equal expect,
|
447
|
+
assert_equal expect, output
|
447
448
|
end
|
448
449
|
|
449
450
|
def test_stage3_mytoc
|
450
451
|
stage3
|
451
|
-
@producer.
|
452
|
+
@producer.config['toclevel'] = 2
|
453
|
+
@producer.modify_config
|
454
|
+
output = @producer.instance_eval { @epub.mytoc }
|
452
455
|
expect = <<EOT
|
453
456
|
<?xml version="1.0" encoding="UTF-8"?>
|
454
457
|
<!DOCTYPE html>
|
@@ -473,13 +476,17 @@ EOT
|
|
473
476
|
</ul></body>
|
474
477
|
</html>
|
475
478
|
EOT
|
476
|
-
assert_equal expect,
|
479
|
+
assert_equal expect, output
|
477
480
|
end
|
478
481
|
|
479
482
|
def test_stage3_flat
|
480
|
-
@producer.
|
483
|
+
@producer.config.deep_merge!(
|
484
|
+
'epubmaker' => { 'flattoc' => true, 'flattocindent' => false },
|
485
|
+
'toclevel' => 2
|
486
|
+
)
|
487
|
+
@producer.modify_config
|
481
488
|
stage3
|
482
|
-
@producer.mytoc
|
489
|
+
output = @producer.instance_eval { @epub.mytoc }
|
483
490
|
expect = <<EOT
|
484
491
|
<?xml version="1.0" encoding="UTF-8"?>
|
485
492
|
<!DOCTYPE html>
|
@@ -503,12 +510,12 @@ EOT
|
|
503
510
|
</body>
|
504
511
|
</html>
|
505
512
|
EOT
|
506
|
-
assert_equal expect,
|
513
|
+
assert_equal expect, output
|
507
514
|
end
|
508
515
|
|
509
516
|
def test_stage3_cover
|
510
517
|
stage3
|
511
|
-
@producer.cover
|
518
|
+
output = @producer.instance_eval { @epub.cover }
|
512
519
|
expect = <<EOT
|
513
520
|
<?xml version="1.0" encoding="UTF-8"?>
|
514
521
|
<!DOCTYPE html>
|
@@ -523,13 +530,14 @@ EOT
|
|
523
530
|
</body>
|
524
531
|
</html>
|
525
532
|
EOT
|
526
|
-
assert_equal expect,
|
533
|
+
assert_equal expect, output
|
527
534
|
end
|
528
535
|
|
529
536
|
def test_stage3_cover_escape
|
530
537
|
stage3
|
531
538
|
@producer.config['title'] = 'Sample<>Book'
|
532
|
-
@producer.
|
539
|
+
@producer.modify_config
|
540
|
+
output = @producer.instance_eval { @epub.cover }
|
533
541
|
expect = <<EOT
|
534
542
|
<?xml version="1.0" encoding="UTF-8"?>
|
535
543
|
<!DOCTYPE html>
|
@@ -544,13 +552,14 @@ EOT
|
|
544
552
|
</body>
|
545
553
|
</html>
|
546
554
|
EOT
|
547
|
-
assert_equal expect,
|
555
|
+
assert_equal expect, output
|
548
556
|
end
|
549
557
|
|
550
558
|
def test_stage3_cover_with_image
|
551
559
|
stage3
|
552
560
|
@producer.config['coverimage'] = 'sample.png'
|
553
|
-
@producer.
|
561
|
+
@producer.modify_config
|
562
|
+
output = @producer.instance_eval { @epub.cover }
|
554
563
|
expect = <<EOT
|
555
564
|
<?xml version="1.0" encoding="UTF-8"?>
|
556
565
|
<!DOCTYPE html>
|
@@ -567,14 +576,17 @@ EOT
|
|
567
576
|
</body>
|
568
577
|
</html>
|
569
578
|
EOT
|
570
|
-
assert_equal expect,
|
579
|
+
assert_equal expect, output
|
571
580
|
end
|
572
581
|
|
573
582
|
def test_stage3_cover_with_image_escape
|
574
583
|
stage3
|
575
|
-
@producer.config
|
576
|
-
|
577
|
-
|
584
|
+
@producer.config.merge!(
|
585
|
+
'title' => 'Sample<>Book',
|
586
|
+
'coverimage' => 'sample.png'
|
587
|
+
)
|
588
|
+
@producer.modify_config
|
589
|
+
output = @producer.instance_eval { @epub.cover }
|
578
590
|
expect = <<EOT
|
579
591
|
<?xml version="1.0" encoding="UTF-8"?>
|
580
592
|
<!DOCTYPE html>
|
@@ -591,14 +603,17 @@ EOT
|
|
591
603
|
</body>
|
592
604
|
</html>
|
593
605
|
EOT
|
594
|
-
assert_equal expect,
|
606
|
+
assert_equal expect, output
|
595
607
|
end
|
596
608
|
|
597
609
|
def test_colophon_default
|
598
|
-
@producer.config
|
599
|
-
|
600
|
-
|
601
|
-
|
610
|
+
@producer.config.merge!(
|
611
|
+
'aut' => ['Mr.Smith'],
|
612
|
+
'pbl' => ['BLUEPRINT'],
|
613
|
+
'isbn' => '9784797372274'
|
614
|
+
)
|
615
|
+
@producer.modify_config
|
616
|
+
output = @producer.instance_eval { @epub.colophon }
|
602
617
|
expect = <<EOT
|
603
618
|
<?xml version="1.0" encoding="UTF-8"?>
|
604
619
|
<!DOCTYPE html>
|
@@ -623,17 +638,20 @@ EOT
|
|
623
638
|
</body>
|
624
639
|
</html>
|
625
640
|
EOT
|
626
|
-
assert_equal expect,
|
641
|
+
assert_equal expect, output
|
627
642
|
end
|
628
643
|
|
629
644
|
def test_colophon_default_escape_and_multiple
|
630
|
-
@producer.config
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
645
|
+
@producer.config.merge!(
|
646
|
+
'title' => '<&Sample Book>',
|
647
|
+
'subtitle' => 'Sample<>Subtitle',
|
648
|
+
'aut' => ['Mr.Smith', 'Mr.&Anderson'],
|
649
|
+
'pbl' => ['BLUEPRINT', 'COPY<>EDIT'],
|
650
|
+
'isbn' => '9784797372274',
|
651
|
+
'rights' => ['COPYRIGHT 2016 <>', '& REVIEW']
|
652
|
+
)
|
653
|
+
@producer.modify_config
|
654
|
+
output = @producer.instance_eval { @epub.colophon }
|
637
655
|
expect = <<EOT
|
638
656
|
<?xml version="1.0" encoding="UTF-8"?>
|
639
657
|
<!DOCTYPE html>
|
@@ -659,19 +677,22 @@ EOT
|
|
659
677
|
</body>
|
660
678
|
</html>
|
661
679
|
EOT
|
662
|
-
assert_equal expect,
|
680
|
+
assert_equal expect, output
|
663
681
|
end
|
664
682
|
|
665
683
|
def test_colophon_history
|
666
|
-
@producer.config
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
684
|
+
@producer.config.merge!(
|
685
|
+
'aut' => ['Mr.Smith'],
|
686
|
+
'pbl' => ['BLUEPRINT'],
|
687
|
+
'pht' => ['Mrs.Smith'],
|
688
|
+
'language' => 'ja',
|
689
|
+
'history' =>
|
671
690
|
[['2011-08-03',
|
672
691
|
'2012-02-15'],
|
673
692
|
['2012-10-01'],
|
674
693
|
['2013-03-01']]
|
694
|
+
)
|
695
|
+
@producer.modify_config
|
675
696
|
epub = @producer.instance_eval { @epub }
|
676
697
|
result = epub.colophon_history
|
677
698
|
expect = <<-EOT
|
@@ -686,14 +707,17 @@ EOT
|
|
686
707
|
end
|
687
708
|
|
688
709
|
def test_colophon_history_freeformat
|
689
|
-
@producer.config
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
710
|
+
@producer.config.merge!(
|
711
|
+
'aut' => ['Mr.Smith'],
|
712
|
+
'pbl' => ['BLUEPRINT'],
|
713
|
+
'pht' => ['Mrs.Smith'],
|
714
|
+
'language' => 'ja',
|
715
|
+
'history' =>
|
694
716
|
[['2011年8月3日 ver 1.1.0発行'],
|
695
717
|
['2011年10月12日 ver 1.2.0発行'],
|
696
718
|
['2012年1月31日 ver 1.2.1発行']]
|
719
|
+
)
|
720
|
+
@producer.modify_config
|
697
721
|
|
698
722
|
epub = @producer.instance_eval { @epub }
|
699
723
|
result = epub.colophon_history
|
@@ -708,10 +732,13 @@ EOT
|
|
708
732
|
end
|
709
733
|
|
710
734
|
def test_colophon_pht
|
711
|
-
@producer.config
|
712
|
-
|
713
|
-
|
714
|
-
|
735
|
+
@producer.config.merge!(
|
736
|
+
'aut' => ['Mr.Smith'],
|
737
|
+
'pbl' => ['BLUEPRINT'],
|
738
|
+
'pht' => ['Mrs.Smith']
|
739
|
+
)
|
740
|
+
@producer.modify_config
|
741
|
+
output = @producer.instance_eval { @epub.colophon }
|
715
742
|
expect = <<EOT
|
716
743
|
<?xml version="1.0" encoding="UTF-8"?>
|
717
744
|
<!DOCTYPE html>
|
@@ -736,28 +763,37 @@ EOT
|
|
736
763
|
</body>
|
737
764
|
</html>
|
738
765
|
EOT
|
739
|
-
assert_equal expect,
|
766
|
+
assert_equal expect, output
|
740
767
|
end
|
741
768
|
|
742
769
|
def test_isbn13
|
743
770
|
@producer.config['isbn'] = '9784797372274'
|
744
|
-
|
771
|
+
@producer.modify_config
|
772
|
+
isbn = @producer.instance_eval { @epub.isbn_hyphen }
|
773
|
+
assert_equal '978-4-79737-227-4', isbn
|
745
774
|
end
|
746
775
|
|
747
776
|
def test_isbn10
|
748
777
|
@producer.config['isbn'] = '4797372273'
|
749
|
-
|
778
|
+
@producer.modify_config
|
779
|
+
isbn = @producer.instance_eval { @epub.isbn_hyphen }
|
780
|
+
assert_equal '4-79737-227-3', isbn
|
750
781
|
end
|
751
782
|
|
752
783
|
def test_isbn_nil
|
753
784
|
@producer.config['isbn'] = nil
|
754
|
-
|
785
|
+
@producer.modify_config
|
786
|
+
isbn = @producer.instance_eval { @epub.isbn_hyphen }
|
787
|
+
assert_equal nil, isbn
|
755
788
|
end
|
756
789
|
|
757
790
|
def test_title
|
758
|
-
@producer.config
|
759
|
-
|
760
|
-
|
791
|
+
@producer.config.merge!(
|
792
|
+
'aut' => ['Mr.Smith'],
|
793
|
+
'pbl' => ['BLUEPRINT']
|
794
|
+
)
|
795
|
+
@producer.modify_config
|
796
|
+
output = @producer.instance_eval { @epub.titlepage }
|
761
797
|
expect = <<EOT
|
762
798
|
<?xml version="1.0" encoding="UTF-8"?>
|
763
799
|
<!DOCTYPE html>
|
@@ -784,13 +820,16 @@ EOT
|
|
784
820
|
</body>
|
785
821
|
</html>
|
786
822
|
EOT
|
787
|
-
assert_equal expect,
|
823
|
+
assert_equal expect, output
|
788
824
|
end
|
789
825
|
|
790
826
|
def test_title_single_value_param
|
791
|
-
@producer.config
|
792
|
-
|
793
|
-
|
827
|
+
@producer.config.merge!(
|
828
|
+
'aut' => 'Mr.Smith',
|
829
|
+
'pbl' => 'BLUEPRINT'
|
830
|
+
)
|
831
|
+
@producer.modify_config
|
832
|
+
output = @producer.instance_eval { @epub.titlepage }
|
794
833
|
expect = <<EOT
|
795
834
|
<?xml version="1.0" encoding="UTF-8"?>
|
796
835
|
<!DOCTYPE html>
|
@@ -817,13 +856,86 @@ EOT
|
|
817
856
|
</body>
|
818
857
|
</html>
|
819
858
|
EOT
|
820
|
-
assert_equal expect,
|
859
|
+
assert_equal expect, output
|
821
860
|
end
|
822
861
|
|
823
862
|
def test_epub_unsafe_id
|
824
|
-
content = Content.new(
|
863
|
+
content = ReVIEW::EPUBMaker::Content.new(file: 'sample.png')
|
825
864
|
assert_equal 'sample-png', content.id
|
826
|
-
content = Content.new(
|
865
|
+
content = ReVIEW::EPUBMaker::Content.new(file: 'sample-&()-=+@:,漢字.png')
|
827
866
|
assert_equal 'sample-_25_26_25_28_25_29-_25_3D_25_2B_25_40_25_3A_25_2C_25_E6_25_BC_25_A2_25_E5_25_AD_25_97-png', content.id
|
828
867
|
end
|
868
|
+
|
869
|
+
def epubmaker_instance
|
870
|
+
Dir.mktmpdir do |tmpdir|
|
871
|
+
epubmaker = ReVIEW::EPUBMaker.new
|
872
|
+
epubmaker.instance_eval do
|
873
|
+
@config = ReVIEW::Configure.create(maker: 'epubmaker')
|
874
|
+
@config['titlepage'] = nil
|
875
|
+
@producer = ReVIEW::EPUBMaker::Producer.new(@config)
|
876
|
+
|
877
|
+
@htmltoc = ReVIEW::HTMLToc.new(tmpdir)
|
878
|
+
|
879
|
+
def config
|
880
|
+
@config
|
881
|
+
end
|
882
|
+
|
883
|
+
def error(s)
|
884
|
+
raise ApplicationError, s
|
885
|
+
end
|
886
|
+
end
|
887
|
+
|
888
|
+
File.write(File.join(tmpdir, 'exist.css'), 'body {}')
|
889
|
+
File.write(File.join(tmpdir, 'exist.html'), '<html></html>')
|
890
|
+
|
891
|
+
Dir.chdir(tmpdir) do
|
892
|
+
Dir.mkdir('test')
|
893
|
+
yield(epubmaker, File.join(tmpdir, 'test'))
|
894
|
+
end
|
895
|
+
end
|
896
|
+
end
|
897
|
+
|
898
|
+
def test_copy_static_file
|
899
|
+
epubmaker_instance do |epubmaker, tmpdir|
|
900
|
+
epubmaker.config['stylesheet'] = ['exist.css']
|
901
|
+
assert_nothing_raised { epubmaker.copy_stylesheet(tmpdir) }
|
902
|
+
|
903
|
+
epubmaker.config['stylesheet'] = ['nothing.css']
|
904
|
+
e = assert_raise(ApplicationError) { epubmaker.copy_stylesheet(tmpdir) }
|
905
|
+
assert_equal 'stylesheet: nothing.css is not found.', e.message
|
906
|
+
end
|
907
|
+
|
908
|
+
epubmaker_instance do |epubmaker, tmpdir|
|
909
|
+
epubmaker.config['titlepage'] = true
|
910
|
+
epubmaker.config['titlefile'] = 'exist.html'
|
911
|
+
assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) }
|
912
|
+
|
913
|
+
epubmaker.config['titlefile'] = 'nothing.html'
|
914
|
+
e = assert_raise(ApplicationError) { epubmaker.copy_frontmatter(tmpdir) }
|
915
|
+
assert_equal 'titlefile: nothing.html is not found.', e.message
|
916
|
+
end
|
917
|
+
|
918
|
+
# XXX: only `cover' is allowed to have invalid file name.
|
919
|
+
%w[originaltitlefile creditfile].each do |name|
|
920
|
+
epubmaker_instance do |epubmaker, tmpdir|
|
921
|
+
epubmaker.config[name] = 'exist.html'
|
922
|
+
assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) }
|
923
|
+
|
924
|
+
epubmaker.config[name] = 'nothing.html'
|
925
|
+
e = assert_raise(ApplicationError) { epubmaker.copy_frontmatter(tmpdir) }
|
926
|
+
assert_equal "#{name}: nothing.html is not found.", e.message
|
927
|
+
end
|
928
|
+
end
|
929
|
+
|
930
|
+
%w[profile advfile colophon backcover].each do |name|
|
931
|
+
epubmaker_instance do |epubmaker, tmpdir|
|
932
|
+
epubmaker.config[name] = 'exist.html'
|
933
|
+
assert_nothing_raised { epubmaker.copy_backmatter(tmpdir) }
|
934
|
+
|
935
|
+
epubmaker.config[name] = 'nothing.html'
|
936
|
+
e = assert_raise(ApplicationError) { epubmaker.copy_backmatter(tmpdir) }
|
937
|
+
assert_equal "#{name}: nothing.html is not found.", e.message
|
938
|
+
end
|
939
|
+
end
|
940
|
+
end
|
829
941
|
end
|