review 5.6.0 → 5.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +31 -0
  3. data/.github/workflows/ruby-tex.yml +5 -1
  4. data/.github/workflows/ruby-win.yml +1 -1
  5. data/.github/workflows/ruby.yml +2 -2
  6. data/.rubocop.yml +13 -2
  7. data/NEWS.ja.md +39 -0
  8. data/NEWS.md +38 -0
  9. data/README.md +1 -1
  10. data/doc/config.yml.sample +11 -0
  11. data/doc/format.ja.md +50 -2
  12. data/doc/format.md +50 -2
  13. data/lib/review/book/base.rb +2 -2
  14. data/lib/review/book/image_finder.rb +29 -14
  15. data/lib/review/book/index.rb +1 -8
  16. data/lib/review/builder.rb +18 -9
  17. data/lib/review/configure.rb +7 -0
  18. data/lib/review/epubmaker/epubcommon.rb +13 -7
  19. data/lib/review/epubmaker/epubv2.rb +0 -5
  20. data/lib/review/epubmaker/epubv3.rb +9 -1
  21. data/lib/review/epubmaker/producer.rb +2 -3
  22. data/lib/review/epubmaker.rb +14 -5
  23. data/lib/review/htmlbuilder.rb +3 -3
  24. data/lib/review/idgxmlbuilder.rb +4 -3
  25. data/lib/review/idgxmlmaker.rb +13 -2
  26. data/lib/review/img_graph.rb +79 -0
  27. data/lib/review/img_math.rb +9 -2
  28. data/lib/review/init.rb +3 -3
  29. data/lib/review/latexbuilder.rb +1 -1
  30. data/lib/review/lineinput.rb +2 -2
  31. data/lib/review/makerhelper.rb +2 -2
  32. data/lib/review/pdfmaker.rb +14 -6
  33. data/lib/review/plaintextbuilder.rb +13 -1
  34. data/lib/review/textmaker.rb +14 -3
  35. data/lib/review/update.rb +3 -7
  36. data/lib/review/version.rb +1 -1
  37. data/lib/review/yamlloader.rb +0 -3
  38. data/review.gemspec +3 -3
  39. data/samples/syntax-book/Gemfile +1 -1
  40. data/samples/syntax-book/ch02.re +6 -0
  41. data/templates/latex/review-jlreq/review-jlreq.cls +14 -0
  42. data/templates/latex/review-jsbook/review-jsbook.cls +14 -0
  43. data/templates/opf/epubv2.opf.erb +2 -0
  44. data/templates/opf/epubv3.opf.erb +2 -0
  45. data/templates/opf/opf_manifest_epubv2.opf.erb +2 -0
  46. data/templates/opf/opf_manifest_epubv3.opf.erb +2 -0
  47. data/templates/opf/opf_tocx_epubv3.opf.erb +2 -0
  48. metadata +22 -136
  49. data/test/assets/black.eps +0 -280
  50. data/test/assets/fit.png +0 -0
  51. data/test/assets/header_listener.html +0 -35
  52. data/test/assets/img_math/img1.png +0 -0
  53. data/test/assets/img_math/img2.png +0 -0
  54. data/test/assets/img_math/img3.png +0 -0
  55. data/test/assets/large.gif +0 -0
  56. data/test/assets/large.jpg +0 -0
  57. data/test/assets/large.png +0 -0
  58. data/test/assets/large.svg +0 -65
  59. data/test/assets/syntax_book_index_detail.txt +0 -60
  60. data/test/assets/test.xml.erb +0 -3
  61. data/test/assets/test_template.tex +0 -189
  62. data/test/assets/test_template_backmatter.tex +0 -200
  63. data/test/book_test_helper.rb +0 -44
  64. data/test/run_test.rb +0 -12
  65. data/test/test_book.rb +0 -588
  66. data/test/test_book_chapter.rb +0 -329
  67. data/test/test_book_part.rb +0 -53
  68. data/test/test_builder.rb +0 -128
  69. data/test/test_catalog.rb +0 -174
  70. data/test/test_catalog_converter_cmd.rb +0 -73
  71. data/test/test_compiler.rb +0 -52
  72. data/test/test_configure.rb +0 -91
  73. data/test/test_converter.rb +0 -21
  74. data/test/test_epub3maker.rb +0 -733
  75. data/test/test_epubmaker.rb +0 -931
  76. data/test/test_epubmaker_cmd.rb +0 -56
  77. data/test/test_extentions_hash.rb +0 -66
  78. data/test/test_helper.rb +0 -62
  79. data/test/test_htmlbuilder.rb +0 -3315
  80. data/test/test_htmltoc.rb +0 -29
  81. data/test/test_htmlutils.rb +0 -43
  82. data/test/test_i18n.rb +0 -300
  83. data/test/test_idgxmlbuilder.rb +0 -1529
  84. data/test/test_idgxmlmaker_cmd.rb +0 -50
  85. data/test/test_image_finder.rb +0 -81
  86. data/test/test_img_math.rb +0 -120
  87. data/test/test_index.rb +0 -287
  88. data/test/test_indexbuilder.rb +0 -52
  89. data/test/test_latexbuilder.rb +0 -2972
  90. data/test/test_latexbuilder_v2.rb +0 -1654
  91. data/test/test_lineinput.rb +0 -104
  92. data/test/test_location.rb +0 -30
  93. data/test/test_logger.rb +0 -33
  94. data/test/test_makerhelper.rb +0 -44
  95. data/test/test_markdownbuilder.rb +0 -371
  96. data/test/test_md2inaobuilder.rb +0 -90
  97. data/test/test_pdfmaker.rb +0 -354
  98. data/test/test_pdfmaker_cmd.rb +0 -130
  99. data/test/test_plaintextbuilder.rb +0 -1214
  100. data/test/test_preprocessor.rb +0 -196
  101. data/test/test_review_ext.rb +0 -30
  102. data/test/test_reviewheaderlistener.rb +0 -49
  103. data/test/test_rstbuilder.rb +0 -619
  104. data/test/test_sec_counter.rb +0 -156
  105. data/test/test_template.rb +0 -33
  106. data/test/test_textmaker_cmd.rb +0 -58
  107. data/test/test_textutils.rb +0 -187
  108. data/test/test_tocprinter.rb +0 -46
  109. data/test/test_topbuilder.rb +0 -1301
  110. data/test/test_update.rb +0 -473
  111. data/test/test_webtocprinter.rb +0 -195
  112. data/test/test_yamlloader.rb +0 -186
  113. data/test/test_zip_exporter.rb +0 -106
@@ -1,931 +0,0 @@
1
- require 'test_helper'
2
- require 'review/epubmaker'
3
-
4
- class EPUBMakerTest < Test::Unit::TestCase
5
- def setup
6
- config = ReVIEW::Configure.values
7
- config.merge!(
8
- 'bookname' => 'sample',
9
- 'booktitle' => 'Sample Book',
10
- 'title' => 'Sample Book',
11
- 'epubversion' => 2,
12
- 'urnid' => 'http://example.jp/',
13
- 'date' => '2011-01-01',
14
- 'language' => 'en',
15
- 'titlepage' => nil
16
- )
17
- @log_io = StringIO.new
18
- ReVIEW.logger = ReVIEW::Logger.new(@log_io)
19
- @producer = ReVIEW::EPUBMaker::Producer.new(config)
20
- end
21
-
22
- def test_initialize
23
- assert ReVIEW::EPUBMaker::Producer.new(ReVIEW::Configure.values)
24
- end
25
-
26
- def test_resource_en
27
- @producer.config['language'] = 'en'
28
- @producer.modify_config
29
- assert_equal 'Table of Contents', ReVIEW::I18n.t('toctitle')
30
- end
31
-
32
- def test_resource_ja
33
- @producer.config['language'] = 'ja'
34
- @producer.modify_config
35
- assert_equal '目次', ReVIEW::I18n.t('toctitle')
36
- end
37
-
38
- def test_mimetype
39
- output = @producer.instance_eval { @epub.mimetype }
40
- assert_equal 'application/epub+zip', output
41
- end
42
-
43
- def test_container
44
- output = @producer.instance_eval { @epub.container }
45
- expect = <<EOT
46
- <?xml version="1.0" encoding="UTF-8"?>
47
- <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
48
- <rootfiles>
49
- <rootfile full-path="OEBPS/sample.opf" media-type="application/oebps-package+xml" />
50
- </rootfiles>
51
- </container>
52
- EOT
53
- assert_equal expect, output
54
- end
55
-
56
- def test_stage1_opf
57
- output = @producer.instance_eval { @epub.opf }
58
- expect = <<EOT
59
- <?xml version="1.0" encoding="UTF-8"?>
60
- <package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
61
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
62
- <dc:title>Sample Book</dc:title>
63
- <dc:language>en</dc:language>
64
- <dc:date>2011-01-01</dc:date>
65
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
66
- </metadata>
67
- <manifest>
68
- <item id="ncx" href="sample.ncx" media-type="application/x-dtbncx+xml"/>
69
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
70
- </manifest>
71
- <spine toc="ncx">
72
- <itemref idref="sample" linear="no"/>
73
- </spine>
74
- <guide>
75
- <reference type="cover" title="Cover" href="sample.html"/>
76
- </guide>
77
- </package>
78
- EOT
79
- assert_equal expect, output
80
- end
81
-
82
- def test_stage1_opf_escape
83
- @producer.config['title'] = 'Sample<>Book'
84
- @producer.modify_config
85
- output = @producer.instance_eval { @epub.opf }
86
- expect = <<EOT
87
- <?xml version="1.0" encoding="UTF-8"?>
88
- <package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
89
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
90
- <dc:title>Sample&lt;&gt;Book</dc:title>
91
- <dc:language>en</dc:language>
92
- <dc:date>2011-01-01</dc:date>
93
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
94
- </metadata>
95
- <manifest>
96
- <item id="ncx" href="sample.ncx" media-type="application/x-dtbncx+xml"/>
97
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
98
- </manifest>
99
- <spine toc="ncx">
100
- <itemref idref="sample" linear="no"/>
101
- </spine>
102
- <guide>
103
- <reference type="cover" title="Cover" href="sample.html"/>
104
- </guide>
105
- </package>
106
- EOT
107
- assert_equal expect, output
108
- end
109
-
110
- def test_stage1_ncx
111
- output = @producer.instance_eval { @epub.ncx([]) }
112
- expect = <<EOT
113
- <?xml version="1.0" encoding="UTF-8"?>
114
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
115
- <head>
116
- <meta name="dtb:depth" content="1"/>
117
- <meta name="dtb:totalPageCount" content="0"/>
118
- <meta name="dtb:maxPageNumber" content="0"/>
119
- <meta name="dtb:uid" content="http://example.jp/"/>
120
- </head>
121
- <docTitle>
122
- <text>Sample Book</text>
123
- </docTitle>
124
- <docAuthor>
125
- <text></text>
126
- </docAuthor>
127
- <navMap>
128
- <navPoint id="top" playOrder="1">
129
- <navLabel>
130
- <text>Sample Book</text>
131
- </navLabel>
132
- <content src="sample.html"/>
133
- </navPoint>
134
- </navMap>
135
- </ncx>
136
- EOT
137
- assert_equal expect, output
138
- end
139
-
140
- def test_stage1_ncx_escape
141
- @producer.config['title'] = 'Sample<>Book'
142
- @producer.modify_config
143
- output = @producer.instance_eval { @epub.ncx([]) }
144
- expect = <<EOT
145
- <?xml version="1.0" encoding="UTF-8"?>
146
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
147
- <head>
148
- <meta name="dtb:depth" content="1"/>
149
- <meta name="dtb:totalPageCount" content="0"/>
150
- <meta name="dtb:maxPageNumber" content="0"/>
151
- <meta name="dtb:uid" content="http://example.jp/"/>
152
- </head>
153
- <docTitle>
154
- <text>Sample&lt;&gt;Book</text>
155
- </docTitle>
156
- <docAuthor>
157
- <text></text>
158
- </docAuthor>
159
- <navMap>
160
- <navPoint id="top" playOrder="1">
161
- <navLabel>
162
- <text>Sample&lt;&gt;Book</text>
163
- </navLabel>
164
- <content src="sample.html"/>
165
- </navPoint>
166
- </navMap>
167
- </ncx>
168
- EOT
169
- assert_equal expect, output
170
- end
171
-
172
- def stage2
173
- # add one item
174
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: 'CH01', level: 1)
175
- end
176
-
177
- def test_stage2_add_l1item
178
- stage2
179
- expect = ReVIEW::EPUBMaker::Content.new(file: 'ch01.html',
180
- id: 'ch01-html',
181
- media: 'application/xhtml+xml',
182
- title: 'CH01',
183
- level: 1)
184
- assert_equal expect, @producer.contents[0]
185
- end
186
-
187
- def test_stage2_opf
188
- stage2
189
- output = @producer.instance_eval { @epub.opf }
190
- expect = <<EOT
191
- <?xml version="1.0" encoding="UTF-8"?>
192
- <package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
193
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
194
- <dc:title>Sample Book</dc:title>
195
- <dc:language>en</dc:language>
196
- <dc:date>2011-01-01</dc:date>
197
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
198
- </metadata>
199
- <manifest>
200
- <item id="ncx" href="sample.ncx" media-type="application/x-dtbncx+xml"/>
201
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
202
- <item id="ch01-html" href="ch01.html" media-type="application/xhtml+xml"/>
203
- </manifest>
204
- <spine toc="ncx">
205
- <itemref idref="sample" linear="no"/>
206
- <itemref idref="ch01-html"/>
207
- </spine>
208
- <guide>
209
- <reference type="cover" title="Cover" href="sample.html"/>
210
- </guide>
211
- </package>
212
- EOT
213
- assert_equal expect, output
214
- end
215
-
216
- def test_stage2_ncx
217
- stage2
218
- output = @producer.instance_eval { @epub.ncx([]) }
219
- expect = <<EOT
220
- <?xml version="1.0" encoding="UTF-8"?>
221
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
222
- <head>
223
- <meta name="dtb:depth" content="1"/>
224
- <meta name="dtb:totalPageCount" content="0"/>
225
- <meta name="dtb:maxPageNumber" content="0"/>
226
- <meta name="dtb:uid" content="http://example.jp/"/>
227
- </head>
228
- <docTitle>
229
- <text>Sample Book</text>
230
- </docTitle>
231
- <docAuthor>
232
- <text></text>
233
- </docAuthor>
234
- <navMap>
235
- <navPoint id="top" playOrder="1">
236
- <navLabel>
237
- <text>Sample Book</text>
238
- </navLabel>
239
- <content src="sample.html"/>
240
- </navPoint>
241
- <navPoint id="nav-2" playOrder="2">
242
- <navLabel>
243
- <text>CH01</text>
244
- </navLabel>
245
- <content src="ch01.html"/>
246
- </navPoint>
247
- </navMap>
248
- </ncx>
249
- EOT
250
- assert_equal expect, output
251
- end
252
-
253
- def stage3
254
- # add more items
255
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: %Q(CH01<>&"), level: 1)
256
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', title: 'CH02', level: 1)
257
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', title: 'CH02.1', level: 2)
258
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', title: 'CH02.1.1', level: 3)
259
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1', title: 'CH02.1.1.1', level: 4)
260
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1.1', title: 'CH02.1.1.1.1', level: 5)
261
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.2', title: 'CH02.1.1.2', level: 4)
262
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', title: 'CH02.2', level: 2)
263
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', title: 'CH02.2.1', level: 3)
264
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', title: 'CH03', level: 1)
265
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', title: 'CH03.1', level: 2)
266
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', title: 'CH03.1.1', level: 3)
267
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', title: 'CH04', level: 1)
268
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.png')
269
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg')
270
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG')
271
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG')
272
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF')
273
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.css')
274
- end
275
-
276
- def test_stage3_add_various_items
277
- stage3
278
- expect = [
279
- ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1),
280
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1),
281
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2),
282
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3),
283
- 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),
284
- 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),
285
- 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),
286
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2),
287
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3),
288
- ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1),
289
- ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2),
290
- ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3),
291
- ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1),
292
- ReVIEW::EPUBMaker::Content.new(file: 'sample.png', id: 'sample-png', media: 'image/png'),
293
- ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg'),
294
- ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg'),
295
- ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml'),
296
- ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif'),
297
- ReVIEW::EPUBMaker::Content.new(file: 'sample.css', id: 'sample-css', media: 'text/css')
298
- ]
299
-
300
- assert_equal expect, @producer.contents
301
- end
302
-
303
- def test_stage3_opf
304
- stage3
305
- output = @producer.instance_eval { @epub.opf }
306
- expect = <<EOT
307
- <?xml version="1.0" encoding="UTF-8"?>
308
- <package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
309
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
310
- <dc:title>Sample Book</dc:title>
311
- <dc:language>en</dc:language>
312
- <dc:date>2011-01-01</dc:date>
313
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
314
- </metadata>
315
- <manifest>
316
- <item id="ncx" href="sample.ncx" media-type="application/x-dtbncx+xml"/>
317
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
318
- <item id="ch01-html" href="ch01.html" media-type="application/xhtml+xml"/>
319
- <item id="ch02-html" href="ch02.html" media-type="application/xhtml+xml"/>
320
- <item id="ch03-html" href="ch03.html" media-type="application/xhtml+xml"/>
321
- <item id="ch04-html" href="ch04.html" media-type="application/xhtml+xml"/>
322
- <item id="sample-GIF" href="sample.GIF" media-type="image/gif"/>
323
- <item id="sample-JPEG" href="sample.JPEG" media-type="image/jpeg"/>
324
- <item id="sample-SvG" href="sample.SvG" media-type="image/svg+xml"/>
325
- <item id="sample-css" href="sample.css" media-type="text/css"/>
326
- <item id="sample-jpg" href="sample.jpg" media-type="image/jpeg"/>
327
- <item id="sample-png" href="sample.png" media-type="image/png"/>
328
- </manifest>
329
- <spine toc="ncx">
330
- <itemref idref="sample" linear="no"/>
331
- <itemref idref="ch01-html"/>
332
- <itemref idref="ch02-html"/>
333
- <itemref idref="ch03-html"/>
334
- <itemref idref="ch04-html"/>
335
- </spine>
336
- <guide>
337
- <reference type="cover" title="Cover" href="sample.html"/>
338
- </guide>
339
- </package>
340
- EOT
341
- assert_equal expect, output
342
- end
343
-
344
- def test_stage3_ncx
345
- stage3
346
- output = @producer.instance_eval { @epub.ncx([]) }
347
- expect = <<EOT
348
- <?xml version="1.0" encoding="UTF-8"?>
349
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
350
- <head>
351
- <meta name="dtb:depth" content="1"/>
352
- <meta name="dtb:totalPageCount" content="0"/>
353
- <meta name="dtb:maxPageNumber" content="0"/>
354
- <meta name="dtb:uid" content="http://example.jp/"/>
355
- </head>
356
- <docTitle>
357
- <text>Sample Book</text>
358
- </docTitle>
359
- <docAuthor>
360
- <text></text>
361
- </docAuthor>
362
- <navMap>
363
- <navPoint id="top" playOrder="1">
364
- <navLabel>
365
- <text>Sample Book</text>
366
- </navLabel>
367
- <content src="sample.html"/>
368
- </navPoint>
369
- <navPoint id="nav-2" playOrder="2">
370
- <navLabel>
371
- <text>CH01&lt;&gt;&amp;&quot;</text>
372
- </navLabel>
373
- <content src="ch01.html"/>
374
- </navPoint>
375
- <navPoint id="nav-3" playOrder="3">
376
- <navLabel>
377
- <text>CH02</text>
378
- </navLabel>
379
- <content src="ch02.html"/>
380
- </navPoint>
381
- <navPoint id="nav-4" playOrder="4">
382
- <navLabel>
383
- <text>CH02.1</text>
384
- </navLabel>
385
- <content src="ch02.html#S1"/>
386
- </navPoint>
387
- <navPoint id="nav-5" playOrder="5">
388
- <navLabel>
389
- <text>CH02.1.1</text>
390
- </navLabel>
391
- <content src="ch02.html#S1.1"/>
392
- </navPoint>
393
- <navPoint id="nav-6" playOrder="6">
394
- <navLabel>
395
- <text>CH02.1.1.1</text>
396
- </navLabel>
397
- <content src="ch02.html#S1.1.1"/>
398
- </navPoint>
399
- <navPoint id="nav-7" playOrder="7">
400
- <navLabel>
401
- <text>CH02.1.1.1.1</text>
402
- </navLabel>
403
- <content src="ch02.html#S1.1.1.1"/>
404
- </navPoint>
405
- <navPoint id="nav-8" playOrder="8">
406
- <navLabel>
407
- <text>CH02.1.1.2</text>
408
- </navLabel>
409
- <content src="ch02.html#S1.1.2"/>
410
- </navPoint>
411
- <navPoint id="nav-9" playOrder="9">
412
- <navLabel>
413
- <text>CH02.2</text>
414
- </navLabel>
415
- <content src="ch02.html#S2"/>
416
- </navPoint>
417
- <navPoint id="nav-10" playOrder="10">
418
- <navLabel>
419
- <text>CH02.2.1</text>
420
- </navLabel>
421
- <content src="ch02.html#S2.1"/>
422
- </navPoint>
423
- <navPoint id="nav-11" playOrder="11">
424
- <navLabel>
425
- <text>CH03</text>
426
- </navLabel>
427
- <content src="ch03.html"/>
428
- </navPoint>
429
- <navPoint id="nav-12" playOrder="12">
430
- <navLabel>
431
- <text>CH03.1</text>
432
- </navLabel>
433
- <content src="ch03.html#S1"/>
434
- </navPoint>
435
- <navPoint id="nav-13" playOrder="13">
436
- <navLabel>
437
- <text>CH03.1.1</text>
438
- </navLabel>
439
- <content src="ch03.html#S1.1"/>
440
- </navPoint>
441
- <navPoint id="nav-14" playOrder="14">
442
- <navLabel>
443
- <text>CH04</text>
444
- </navLabel>
445
- <content src="ch04.html"/>
446
- </navPoint>
447
- </navMap>
448
- </ncx>
449
- EOT
450
- assert_equal expect, output
451
- end
452
-
453
- def test_stage3_mytoc
454
- stage3
455
- @producer.config['toclevel'] = 2
456
- @producer.modify_config
457
- output = @producer.instance_eval { @epub.mytoc }
458
- expect = <<EOT
459
- <?xml version="1.0" encoding="UTF-8"?>
460
- <!DOCTYPE html>
461
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
462
- <head>
463
- <meta charset="UTF-8" />
464
- <meta name="generator" content="Re:VIEW" />
465
- <title>Table of Contents</title>
466
- </head>
467
- <body>
468
- <h1 class="toc-title">Table of Contents</h1>
469
-
470
- <ul class="toc-h1"><li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
471
- <li><a href="ch02.html">CH02</a>
472
- <ul class="toc-h2"><li><a href="ch02.html#S1">CH02.1</a></li>
473
- <li><a href="ch02.html#S2">CH02.2</a></li>
474
- </ul></li>
475
- <li><a href="ch03.html">CH03</a>
476
- <ul class="toc-h2"><li><a href="ch03.html#S1">CH03.1</a></li>
477
- </ul></li>
478
- <li><a href="ch04.html">CH04</a></li>
479
- </ul></body>
480
- </html>
481
- EOT
482
- assert_equal expect, output
483
- end
484
-
485
- def test_stage3_flat
486
- @producer.config.deep_merge!(
487
- 'epubmaker' => { 'flattoc' => true, 'flattocindent' => false },
488
- 'toclevel' => 2
489
- )
490
- @producer.modify_config
491
- stage3
492
- output = @producer.instance_eval { @epub.mytoc }
493
- expect = <<EOT
494
- <?xml version="1.0" encoding="UTF-8"?>
495
- <!DOCTYPE html>
496
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
497
- <head>
498
- <meta charset="UTF-8" />
499
- <meta name="generator" content="Re:VIEW" />
500
- <title>Table of Contents</title>
501
- </head>
502
- <body>
503
- <h1 class="toc-title">Table of Contents</h1>
504
- <ul class="toc-h1">
505
- <li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
506
- <li><a href="ch02.html">CH02</a></li>
507
- <li><a href="ch02.html#S1">CH02.1</a></li>
508
- <li><a href="ch02.html#S2">CH02.2</a></li>
509
- <li><a href="ch03.html">CH03</a></li>
510
- <li><a href="ch03.html#S1">CH03.1</a></li>
511
- <li><a href="ch04.html">CH04</a></li>
512
- </ul>
513
- </body>
514
- </html>
515
- EOT
516
- assert_equal expect, output
517
- end
518
-
519
- def test_stage3_cover
520
- stage3
521
- output = @producer.instance_eval { @epub.cover }
522
- expect = <<EOT
523
- <?xml version="1.0" encoding="UTF-8"?>
524
- <!DOCTYPE html>
525
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
526
- <head>
527
- <meta charset="UTF-8" />
528
- <meta name="generator" content="Re:VIEW" />
529
- <title>Sample Book</title>
530
- </head>
531
- <body>
532
- <h1 class="cover-title">Sample Book</h1>
533
- </body>
534
- </html>
535
- EOT
536
- assert_equal expect, output
537
- end
538
-
539
- def test_stage3_cover_escape
540
- stage3
541
- @producer.config['title'] = 'Sample<>Book'
542
- @producer.modify_config
543
- output = @producer.instance_eval { @epub.cover }
544
- expect = <<EOT
545
- <?xml version="1.0" encoding="UTF-8"?>
546
- <!DOCTYPE html>
547
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
548
- <head>
549
- <meta charset="UTF-8" />
550
- <meta name="generator" content="Re:VIEW" />
551
- <title>Sample&lt;&gt;Book</title>
552
- </head>
553
- <body>
554
- <h1 class="cover-title">Sample&lt;&gt;Book</h1>
555
- </body>
556
- </html>
557
- EOT
558
- assert_equal expect, output
559
- end
560
-
561
- def test_stage3_cover_with_image
562
- stage3
563
- @producer.config['coverimage'] = 'sample.png'
564
- @producer.modify_config
565
- output = @producer.instance_eval { @epub.cover }
566
- expect = <<EOT
567
- <?xml version="1.0" encoding="UTF-8"?>
568
- <!DOCTYPE html>
569
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
570
- <head>
571
- <meta charset="UTF-8" />
572
- <meta name="generator" content="Re:VIEW" />
573
- <title>Sample Book</title>
574
- </head>
575
- <body>
576
- <div id="cover-image" class="cover-image">
577
- <img src="sample.png" alt="Sample Book" class="max"/>
578
- </div>
579
- </body>
580
- </html>
581
- EOT
582
- assert_equal expect, output
583
- end
584
-
585
- def test_stage3_cover_with_image_escape
586
- stage3
587
- @producer.config.merge!(
588
- 'title' => 'Sample<>Book',
589
- 'coverimage' => 'sample.png'
590
- )
591
- @producer.modify_config
592
- output = @producer.instance_eval { @epub.cover }
593
- expect = <<EOT
594
- <?xml version="1.0" encoding="UTF-8"?>
595
- <!DOCTYPE html>
596
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
597
- <head>
598
- <meta charset="UTF-8" />
599
- <meta name="generator" content="Re:VIEW" />
600
- <title>Sample&lt;&gt;Book</title>
601
- </head>
602
- <body>
603
- <div id="cover-image" class="cover-image">
604
- <img src="sample.png" alt="Sample&lt;&gt;Book" class="max"/>
605
- </div>
606
- </body>
607
- </html>
608
- EOT
609
- assert_equal expect, output
610
- end
611
-
612
- def test_colophon_default
613
- @producer.config.merge!(
614
- 'aut' => ['Mr.Smith'],
615
- 'pbl' => ['BLUEPRINT'],
616
- 'isbn' => '9784797372274'
617
- )
618
- @producer.modify_config
619
- output = @producer.instance_eval { @epub.colophon }
620
- expect = <<EOT
621
- <?xml version="1.0" encoding="UTF-8"?>
622
- <!DOCTYPE html>
623
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
624
- <head>
625
- <meta charset="UTF-8" />
626
- <meta name="generator" content="Re:VIEW" />
627
- <title>Colophon</title>
628
- </head>
629
- <body>
630
- <div class="colophon">
631
- <p class="title">Sample Book</p>
632
- <div class="pubhistory">
633
- <p>published by Jan. 1, 2011</p>
634
- </div>
635
- <table class="colophon">
636
- <tr><th>Author</th><td>Mr.Smith</td></tr>
637
- <tr><th>Publisher</th><td>BLUEPRINT</td></tr>
638
- <tr><th>ISBN</th><td>978-4-79737-227-4</td></tr>
639
- </table>
640
- </div>
641
- </body>
642
- </html>
643
- EOT
644
- assert_equal expect, output
645
- end
646
-
647
- def test_colophon_default_escape_and_multiple
648
- @producer.config.merge!(
649
- 'title' => '<&Sample Book>',
650
- 'subtitle' => 'Sample<>Subtitle',
651
- 'aut' => ['Mr.Smith', 'Mr.&Anderson'],
652
- 'pbl' => ['BLUEPRINT', 'COPY<>EDIT'],
653
- 'isbn' => '9784797372274',
654
- 'rights' => ['COPYRIGHT 2016 <>', '& REVIEW']
655
- )
656
- @producer.modify_config
657
- output = @producer.instance_eval { @epub.colophon }
658
- expect = <<EOT
659
- <?xml version="1.0" encoding="UTF-8"?>
660
- <!DOCTYPE html>
661
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
662
- <head>
663
- <meta charset="UTF-8" />
664
- <meta name="generator" content="Re:VIEW" />
665
- <title>Colophon</title>
666
- </head>
667
- <body>
668
- <div class="colophon">
669
- <p class="title">&lt;&amp;Sample Book&gt;<br /><span class="subtitle">Sample&lt;&gt;Subtitle</span></p>
670
- <div class="pubhistory">
671
- <p>published by Jan. 1, 2011</p>
672
- </div>
673
- <table class="colophon">
674
- <tr><th>Author</th><td>Mr.Smith, Mr.&amp;Anderson</td></tr>
675
- <tr><th>Publisher</th><td>BLUEPRINT, COPY&lt;&gt;EDIT</td></tr>
676
- <tr><th>ISBN</th><td>978-4-79737-227-4</td></tr>
677
- </table>
678
- <p class="copyright">COPYRIGHT 2016 &lt;&gt;<br />&amp; REVIEW</p>
679
- </div>
680
- </body>
681
- </html>
682
- EOT
683
- assert_equal expect, output
684
- end
685
-
686
- def test_colophon_history
687
- @producer.config.merge!(
688
- 'aut' => ['Mr.Smith'],
689
- 'pbl' => ['BLUEPRINT'],
690
- 'pht' => ['Mrs.Smith'],
691
- 'language' => 'ja',
692
- 'history' =>
693
- [['2011-08-03',
694
- '2012-02-15'],
695
- ['2012-10-01'],
696
- ['2013-03-01']]
697
- )
698
- @producer.modify_config
699
- epub = @producer.instance_eval { @epub }
700
- result = epub.colophon_history
701
- expect = <<-EOT
702
- <div class="pubhistory">
703
- <p>2011年8月3日 初版第1刷 発行</p>
704
- <p>2012年2月15日 初版第2刷 発行</p>
705
- <p>2012年10月1日 第2版第1刷 発行</p>
706
- <p>2013年3月1日 第3版第1刷 発行</p>
707
- </div>
708
- EOT
709
- assert_equal expect, result
710
- end
711
-
712
- def test_colophon_history_freeformat
713
- @producer.config.merge!(
714
- 'aut' => ['Mr.Smith'],
715
- 'pbl' => ['BLUEPRINT'],
716
- 'pht' => ['Mrs.Smith'],
717
- 'language' => 'ja',
718
- 'history' =>
719
- [['2011年8月3日 ver 1.1.0発行'],
720
- ['2011年10月12日 ver 1.2.0発行'],
721
- ['2012年1月31日 ver 1.2.1発行']]
722
- )
723
- @producer.modify_config
724
-
725
- epub = @producer.instance_eval { @epub }
726
- result = epub.colophon_history
727
- expect = <<-EOT
728
- <div class="pubhistory">
729
- <p>2011年8月3日 ver 1.1.0発行</p>
730
- <p>2011年10月12日 ver 1.2.0発行</p>
731
- <p>2012年1月31日 ver 1.2.1発行</p>
732
- </div>
733
- EOT
734
- assert_equal expect, result
735
- end
736
-
737
- def test_colophon_pht
738
- @producer.config.merge!(
739
- 'aut' => ['Mr.Smith'],
740
- 'pbl' => ['BLUEPRINT'],
741
- 'pht' => ['Mrs.Smith']
742
- )
743
- @producer.modify_config
744
- output = @producer.instance_eval { @epub.colophon }
745
- expect = <<EOT
746
- <?xml version="1.0" encoding="UTF-8"?>
747
- <!DOCTYPE html>
748
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
749
- <head>
750
- <meta charset="UTF-8" />
751
- <meta name="generator" content="Re:VIEW" />
752
- <title>Colophon</title>
753
- </head>
754
- <body>
755
- <div class="colophon">
756
- <p class="title">Sample Book</p>
757
- <div class="pubhistory">
758
- <p>published by Jan. 1, 2011</p>
759
- </div>
760
- <table class="colophon">
761
- <tr><th>Author</th><td>Mr.Smith</td></tr>
762
- <tr><th>Publisher</th><td>BLUEPRINT</td></tr>
763
- <tr><th>Director of Photography</th><td>Mrs.Smith</td></tr>
764
- </table>
765
- </div>
766
- </body>
767
- </html>
768
- EOT
769
- assert_equal expect, output
770
- end
771
-
772
- def test_isbn13
773
- @producer.config['isbn'] = '9784797372274'
774
- @producer.modify_config
775
- isbn = @producer.instance_eval { @epub.isbn_hyphen }
776
- assert_equal '978-4-79737-227-4', isbn
777
- end
778
-
779
- def test_isbn10
780
- @producer.config['isbn'] = '4797372273'
781
- @producer.modify_config
782
- isbn = @producer.instance_eval { @epub.isbn_hyphen }
783
- assert_equal '4-79737-227-3', isbn
784
- end
785
-
786
- def test_isbn_nil
787
- @producer.config['isbn'] = nil
788
- @producer.modify_config
789
- isbn = @producer.instance_eval { @epub.isbn_hyphen }
790
- assert_equal nil, isbn
791
- end
792
-
793
- def test_title
794
- @producer.config.merge!(
795
- 'aut' => ['Mr.Smith'],
796
- 'pbl' => ['BLUEPRINT']
797
- )
798
- @producer.modify_config
799
- output = @producer.instance_eval { @epub.titlepage }
800
- expect = <<EOT
801
- <?xml version="1.0" encoding="UTF-8"?>
802
- <!DOCTYPE html>
803
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
804
- <head>
805
- <meta charset="UTF-8" />
806
- <meta name="generator" content="Re:VIEW" />
807
- <title>Sample Book</title>
808
- </head>
809
- <body>
810
- <div class="titlepage">
811
- <h1 class="tp-title">Sample Book</h1>
812
- <h2 class="tp-author">Mr.Smith</h2>
813
- <h3 class="tp-publisher">BLUEPRINT</h3>
814
- </div>
815
- </body>
816
- </html>
817
- EOT
818
- assert_equal expect, output
819
- end
820
-
821
- def test_title_single_value_param
822
- @producer.config.merge!(
823
- 'aut' => 'Mr.Smith',
824
- 'pbl' => 'BLUEPRINT'
825
- )
826
- @producer.modify_config
827
- output = @producer.instance_eval { @epub.titlepage }
828
- expect = <<EOT
829
- <?xml version="1.0" encoding="UTF-8"?>
830
- <!DOCTYPE html>
831
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
832
- <head>
833
- <meta charset="UTF-8" />
834
- <meta name="generator" content="Re:VIEW" />
835
- <title>Sample Book</title>
836
- </head>
837
- <body>
838
- <div class="titlepage">
839
- <h1 class="tp-title">Sample Book</h1>
840
- <h2 class="tp-author">Mr.Smith</h2>
841
- <h3 class="tp-publisher">BLUEPRINT</h3>
842
- </div>
843
- </body>
844
- </html>
845
- EOT
846
- assert_equal expect, output
847
- end
848
-
849
- def test_epub_unsafe_id
850
- content = ReVIEW::EPUBMaker::Content.new(file: 'sample.png')
851
- assert_equal 'sample-png', content.id
852
- content = ReVIEW::EPUBMaker::Content.new(file: 'sample-&()-=+@:,漢字.png')
853
- 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
854
- end
855
-
856
- def epubmaker_instance
857
- Dir.mktmpdir do |tmpdir|
858
- epubmaker = ReVIEW::EPUBMaker.new
859
- epubmaker.instance_eval do
860
- @config = ReVIEW::Configure.create(maker: 'epubmaker')
861
- @config['titlepage'] = nil
862
- @producer = ReVIEW::EPUBMaker::Producer.new(@config)
863
-
864
- @htmltoc = ReVIEW::HTMLToc.new(tmpdir)
865
-
866
- def config
867
- @config
868
- end
869
-
870
- def error(s)
871
- raise ApplicationError, s
872
- end
873
- end
874
-
875
- File.write(File.join(tmpdir, 'exist.css'), 'body {}')
876
- File.write(File.join(tmpdir, 'exist.html'), '<html></html>')
877
-
878
- Dir.chdir(tmpdir) do
879
- Dir.mkdir('test')
880
- yield(epubmaker, File.join(tmpdir, 'test'))
881
- end
882
- end
883
- end
884
-
885
- def test_copy_static_file
886
- epubmaker_instance do |epubmaker, tmpdir|
887
- epubmaker.config['stylesheet'] = ['exist.css']
888
- assert_nothing_raised { epubmaker.copy_stylesheet(tmpdir) }
889
-
890
- epubmaker.config['stylesheet'] = ['nothing.css']
891
- assert_raise(SystemExit) { epubmaker.copy_stylesheet(tmpdir) }
892
- assert_equal "ERROR --: stylesheet: nothing.css is not found.\n", @log_io.string
893
- end
894
-
895
- epubmaker_instance do |epubmaker, tmpdir|
896
- epubmaker.config['titlepage'] = true
897
- epubmaker.config['titlefile'] = 'exist.html'
898
- assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) }
899
-
900
- epubmaker.config['titlefile'] = 'nothing.html'
901
- @log_io.string = ''
902
- assert_raise(SystemExit) { epubmaker.copy_frontmatter(tmpdir) }
903
- assert_equal "ERROR --: titlefile: nothing.html is not found.\n", @log_io.string
904
- end
905
-
906
- # XXX: only `cover' is allowed to have invalid file name.
907
- %w[originaltitlefile creditfile].each do |name|
908
- epubmaker_instance do |epubmaker, tmpdir|
909
- epubmaker.config[name] = 'exist.html'
910
- assert_nothing_raised { epubmaker.copy_frontmatter(tmpdir) }
911
-
912
- epubmaker.config[name] = 'nothing.html'
913
- @log_io.string = ''
914
- assert_raise(SystemExit) { epubmaker.copy_frontmatter(tmpdir) }
915
- assert_equal "ERROR --: #{name}: nothing.html is not found.\n", @log_io.string
916
- end
917
- end
918
-
919
- %w[profile advfile colophon backcover].each do |name|
920
- epubmaker_instance do |epubmaker, tmpdir|
921
- epubmaker.config[name] = 'exist.html'
922
- assert_nothing_raised { epubmaker.copy_backmatter(tmpdir) }
923
-
924
- epubmaker.config[name] = 'nothing.html'
925
- @log_io.string = ''
926
- assert_raise(SystemExit) { epubmaker.copy_backmatter(tmpdir) }
927
- assert_equal "ERROR --: #{name}: nothing.html is not found.\n", @log_io.string
928
- end
929
- end
930
- end
931
- end