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,733 +0,0 @@
1
- require 'test_helper'
2
- require 'review/configure'
3
- require 'review/epubmaker'
4
-
5
- class EPUB3MakerTest < Test::Unit::TestCase
6
- def setup
7
- config = ReVIEW::Configure.values
8
- config.merge!(
9
- 'bookname' => 'sample',
10
- 'title' => 'Sample Book',
11
- 'epubversion' => 3,
12
- 'urnid' => 'http://example.jp/',
13
- 'date' => '2011-01-01',
14
- 'language' => 'en',
15
- 'modified' => '2014-12-13T14:15:16Z',
16
- 'titlepage' => nil
17
- )
18
- @producer = ReVIEW::EPUBMaker::Producer.new(config)
19
- end
20
-
21
- def test_initialize
22
- assert ReVIEW::EPUBMaker::Producer.new(ReVIEW::Configure.values)
23
- end
24
-
25
- def test_resource_en
26
- @producer.config['language'] = 'en'
27
- @producer.modify_config
28
- assert_equal 'Table of Contents', ReVIEW::I18n.t('toctitle')
29
- end
30
-
31
- def test_resource_ja
32
- @producer.config['language'] = 'ja'
33
- @producer.modify_config
34
- assert_equal '目次', ReVIEW::I18n.t('toctitle')
35
- end
36
-
37
- def test_mimetype
38
- output = @producer.instance_eval { @epub.mimetype }
39
- assert_equal 'application/epub+zip', output
40
- end
41
-
42
- def test_container
43
- output = @producer.instance_eval { @epub.container }
44
- expect = <<EOT
45
- <?xml version="1.0" encoding="UTF-8"?>
46
- <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
47
- <rootfiles>
48
- <rootfile full-path="OEBPS/sample.opf" media-type="application/oebps-package+xml" />
49
- </rootfiles>
50
- </container>
51
- EOT
52
- assert_equal expect, output
53
- end
54
-
55
- def test_stage1_opf
56
- output = @producer.instance_eval { @epub.opf }
57
- expect = <<EOT
58
- <?xml version="1.0" encoding="UTF-8"?>
59
- <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en">
60
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
61
- <dc:title id="title">Sample Book</dc:title>
62
- <dc:language id="language">en</dc:language>
63
- <dc:date id="date">2011-01-01</dc:date>
64
- <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
65
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
66
- </metadata>
67
- <manifest>
68
- <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
69
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
70
- </manifest>
71
- <spine page-progression-direction="ltr">
72
- <itemref idref="sample" linear="no"/>
73
- </spine>
74
- <guide>
75
- <reference type="cover" title="Cover" href="sample.html"/>
76
- <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
77
- </guide>
78
- </package>
79
- EOT
80
- assert_equal expect, output
81
- end
82
-
83
- def test_stage1_opf_ebpaj
84
- @producer.config.merge!(
85
- 'opf_prefix' => { 'ebpaj' => 'http://www.ebpaj.jp/' },
86
- 'opf_meta' => { 'ebpaj:guide-version' => '1.1.2' }
87
- )
88
- @producer.modify_config
89
- output = @producer.instance_eval { @epub.opf }
90
- expect = <<EOT
91
- <?xml version="1.0" encoding="UTF-8"?>
92
- <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en" prefix="ebpaj: http://www.ebpaj.jp/">
93
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
94
- <dc:title id="title">Sample Book</dc:title>
95
- <dc:language id="language">en</dc:language>
96
- <dc:date id="date">2011-01-01</dc:date>
97
- <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
98
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
99
- <meta property="ebpaj:guide-version">1.1.2</meta>
100
- </metadata>
101
- <manifest>
102
- <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
103
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
104
- </manifest>
105
- <spine page-progression-direction="ltr">
106
- <itemref idref="sample" linear="no"/>
107
- </spine>
108
- <guide>
109
- <reference type="cover" title="Cover" href="sample.html"/>
110
- <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
111
- </guide>
112
- </package>
113
- EOT
114
- assert_equal expect, output
115
- end
116
-
117
- def test_stage1_opf_fileas
118
- @producer.config.merge!('title' => { 'name' => 'これは書籍です', 'file-as' => 'コレハショセキデス' },
119
- 'aut' => [{ 'name' => '著者A', 'file-as' => 'チョシャA' }, { 'name' => '著者B', 'file-as' => 'チョシャB' }],
120
- 'pbl' => [{ 'name' => '出版社', 'file-as' => 'シュッパンシャ' }])
121
- @producer.modify_config
122
- output = @producer.instance_eval { @epub.opf }
123
- expect = <<EOT
124
- <?xml version="1.0" encoding="UTF-8"?>
125
- <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en">
126
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
127
- <dc:title id="title">これは書籍です</dc:title>
128
- <meta refines="#title" property="file-as">コレハショセキデス</meta>
129
- <dc:language id="language">en</dc:language>
130
- <dc:date id="date">2011-01-01</dc:date>
131
- <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
132
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
133
- <dc:creator id="aut-0">著者A</dc:creator>
134
- <meta refines="#aut-0" property="role" scheme="marc:relators">aut</meta>
135
- <meta refines="#aut-0" property="file-as">チョシャA</meta>
136
- <dc:creator id="aut-1">著者B</dc:creator>
137
- <meta refines="#aut-1" property="role" scheme="marc:relators">aut</meta>
138
- <meta refines="#aut-1" property="file-as">チョシャB</meta>
139
- <dc:contributor id="pbl-0">出版社</dc:contributor>
140
- <meta refines="#pbl-0" property="role" scheme="marc:relators">pbl</meta>
141
- <meta refines="#pbl-0" property="file-as">シュッパンシャ</meta>
142
- <dc:publisher id="pub-pbl-0">出版社</dc:publisher>
143
- <meta refines="#pub-pbl-0" property="role" scheme="marc:relators">pbl</meta>
144
- <meta refines="#pub-pbl-0" property="file-as">シュッパンシャ</meta>
145
- </metadata>
146
- <manifest>
147
- <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
148
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
149
- </manifest>
150
- <spine page-progression-direction="ltr">
151
- <itemref idref="sample" linear="no"/>
152
- </spine>
153
- <guide>
154
- <reference type="cover" title="Cover" href="sample.html"/>
155
- <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
156
- </guide>
157
- </package>
158
- EOT
159
- assert_equal expect, output
160
- end
161
-
162
- def test_stage1_ncx
163
- output = @producer.instance_eval { @epub.ncx([]) }
164
- expect = <<EOT
165
- <?xml version="1.0" encoding="UTF-8"?>
166
- <!DOCTYPE html>
167
- <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">
168
- <head>
169
- <meta charset="UTF-8" />
170
- <meta name="generator" content="Re:VIEW" />
171
- <title>Table of Contents</title>
172
- </head>
173
- <body>
174
- <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
175
- <h1 class="toc-title">Table of Contents</h1>
176
-
177
- <ol class="toc-h1"></ol> </nav>
178
- </body>
179
- </html>
180
- EOT
181
- assert_equal expect, output
182
- end
183
-
184
- def stage2
185
- # add one item
186
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: 'CH01', level: 1)
187
- end
188
-
189
- def test_stage2_add_l1item
190
- stage2
191
- expect = ReVIEW::EPUBMaker::Content.new(file: 'ch01.html',
192
- id: 'ch01-html',
193
- media: 'application/xhtml+xml',
194
- title: 'CH01',
195
- level: 1)
196
- assert_equal expect, @producer.contents[0]
197
- end
198
-
199
- def test_stage2_opf
200
- stage2
201
- output = @producer.instance_eval { @epub.opf }
202
- expect = <<EOT
203
- <?xml version="1.0" encoding="UTF-8"?>
204
- <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en">
205
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
206
- <dc:title id="title">Sample Book</dc:title>
207
- <dc:language id="language">en</dc:language>
208
- <dc:date id="date">2011-01-01</dc:date>
209
- <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
210
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
211
- </metadata>
212
- <manifest>
213
- <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
214
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
215
- <item id="ch01-html" href="ch01.html" media-type="application/xhtml+xml"/>
216
- </manifest>
217
- <spine page-progression-direction="ltr">
218
- <itemref idref="sample" linear="no"/>
219
- <itemref idref="ch01-html"/>
220
- </spine>
221
- <guide>
222
- <reference type="cover" title="Cover" href="sample.html"/>
223
- <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
224
- </guide>
225
- </package>
226
- EOT
227
- assert_equal expect, output
228
- end
229
-
230
- def test_stage2_ncx
231
- stage2
232
- output = @producer.instance_eval { @epub.ncx([]) }
233
- expect = <<EOT
234
- <?xml version="1.0" encoding="UTF-8"?>
235
- <!DOCTYPE html>
236
- <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">
237
- <head>
238
- <meta charset="UTF-8" />
239
- <meta name="generator" content="Re:VIEW" />
240
- <title>Table of Contents</title>
241
- </head>
242
- <body>
243
- <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
244
- <h1 class="toc-title">Table of Contents</h1>
245
-
246
- <ol class="toc-h1"><li><a href="ch01.html">CH01</a></li>
247
- </ol> </nav>
248
- </body>
249
- </html>
250
- EOT
251
- assert_equal expect, output
252
- end
253
-
254
- def stage3
255
- # add more items
256
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: %Q(CH01<>&"), level: 1)
257
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', title: 'CH02', level: 1)
258
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', title: 'CH02.1', level: 2)
259
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', title: 'CH02.1.1', level: 3)
260
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1', title: 'CH02.1.1.1', level: 4)
261
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1.1', title: 'CH02.1.1.1.1', level: 5)
262
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.2', title: 'CH02.1.1.2', level: 4)
263
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', title: 'CH02.2', level: 2)
264
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', title: 'CH02.2.1', level: 3)
265
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', title: 'CH03', level: 1, properties: ['mathml'])
266
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', title: 'CH03.1', level: 2)
267
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', title: 'CH03.1.1', level: 3)
268
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', title: 'CH04', level: 1)
269
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.png')
270
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg')
271
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG')
272
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG')
273
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF')
274
- @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.css')
275
- end
276
-
277
- def test_stage3_add_various_items
278
- stage3
279
- expect = [
280
- ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1),
281
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1),
282
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2),
283
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3),
284
- 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),
285
- 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),
286
- 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),
287
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2),
288
- ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3),
289
- ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1, properties: ['mathml']),
290
- ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2),
291
- ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3),
292
- ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1),
293
- ReVIEW::EPUBMaker::Content.new(file: 'sample.png', id: 'sample-png', media: 'image/png'),
294
- ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg'),
295
- ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg'),
296
- ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml'),
297
- ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif'),
298
- ReVIEW::EPUBMaker::Content.new(file: 'sample.css', id: 'sample-css', media: 'text/css')
299
- ]
300
-
301
- assert_equal expect, @producer.contents
302
- end
303
-
304
- def test_stage3_opf
305
- stage3
306
- output = @producer.instance_eval { @epub.opf }
307
- expect = <<EOT
308
- <?xml version="1.0" encoding="UTF-8"?>
309
- <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en">
310
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
311
- <dc:title id="title">Sample Book</dc:title>
312
- <dc:language id="language">en</dc:language>
313
- <dc:date id="date">2011-01-01</dc:date>
314
- <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
315
- <dc:identifier id="BookId">http://example.jp/</dc:identifier>
316
- </metadata>
317
- <manifest>
318
- <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
319
- <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
320
- <item id="ch01-html" href="ch01.html" media-type="application/xhtml+xml"/>
321
- <item id="ch02-html" href="ch02.html" media-type="application/xhtml+xml"/>
322
- <item id="ch03-html" href="ch03.html" media-type="application/xhtml+xml" properties="mathml"/>
323
- <item id="ch04-html" href="ch04.html" media-type="application/xhtml+xml"/>
324
- <item id="sample-GIF" href="sample.GIF" media-type="image/gif"/>
325
- <item id="sample-JPEG" href="sample.JPEG" media-type="image/jpeg"/>
326
- <item id="sample-SvG" href="sample.SvG" media-type="image/svg+xml"/>
327
- <item id="sample-css" href="sample.css" media-type="text/css"/>
328
- <item id="sample-jpg" href="sample.jpg" media-type="image/jpeg"/>
329
- <item id="sample-png" href="sample.png" media-type="image/png"/>
330
- </manifest>
331
- <spine page-progression-direction="ltr">
332
- <itemref idref="sample" linear="no"/>
333
- <itemref idref="ch01-html"/>
334
- <itemref idref="ch02-html"/>
335
- <itemref idref="ch03-html"/>
336
- <itemref idref="ch04-html"/>
337
- </spine>
338
- <guide>
339
- <reference type="cover" title="Cover" href="sample.html"/>
340
- <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
341
- </guide>
342
- </package>
343
- EOT
344
- assert_equal expect, output
345
- end
346
-
347
- def test_stage3_ncx
348
- stage3
349
- @producer.config['toclevel'] = 2
350
- output = @producer.instance_eval { @epub.ncx([]) }
351
- expect = <<EOT
352
- <?xml version="1.0" encoding="UTF-8"?>
353
- <!DOCTYPE html>
354
- <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">
355
- <head>
356
- <meta charset="UTF-8" />
357
- <meta name="generator" content="Re:VIEW" />
358
- <title>Table of Contents</title>
359
- </head>
360
- <body>
361
- <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
362
- <h1 class="toc-title">Table of Contents</h1>
363
-
364
- <ol class="toc-h1"><li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
365
- <li><a href="ch02.html">CH02</a>
366
- <ol class="toc-h2"><li><a href="ch02.html#S1">CH02.1</a></li>
367
- <li><a href="ch02.html#S2">CH02.2</a></li>
368
- </ol></li>
369
- <li><a href="ch03.html">CH03</a>
370
- <ol class="toc-h2"><li><a href="ch03.html#S1">CH03.1</a></li>
371
- </ol></li>
372
- <li><a href="ch04.html">CH04</a></li>
373
- </ol> </nav>
374
- </body>
375
- </html>
376
- EOT
377
- assert_equal expect, output
378
- end
379
-
380
- def test_stage3_mytoc
381
- stage3
382
- @producer.config['toclevel'] = 2
383
- output = @producer.instance_eval { @epub.mytoc }
384
- expect = <<EOT
385
- <?xml version="1.0" encoding="UTF-8"?>
386
- <!DOCTYPE html>
387
- <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">
388
- <head>
389
- <meta charset="UTF-8" />
390
- <meta name="generator" content="Re:VIEW" />
391
- <title>Table of Contents</title>
392
- </head>
393
- <body>
394
- <h1 class="toc-title">Table of Contents</h1>
395
-
396
- <ul class="toc-h1"><li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
397
- <li><a href="ch02.html">CH02</a>
398
- <ul class="toc-h2"><li><a href="ch02.html#S1">CH02.1</a></li>
399
- <li><a href="ch02.html#S2">CH02.2</a></li>
400
- </ul></li>
401
- <li><a href="ch03.html">CH03</a>
402
- <ul class="toc-h2"><li><a href="ch03.html#S1">CH03.1</a></li>
403
- </ul></li>
404
- <li><a href="ch04.html">CH04</a></li>
405
- </ul></body>
406
- </html>
407
- EOT
408
- assert_equal expect, output
409
- end
410
-
411
- def test_stage3_flat
412
- @producer.config.deep_merge!(
413
- 'toclevel' => 2,
414
- 'epubmaker' => { 'flattoc' => true, 'flattocindent' => false }
415
- )
416
- @producer.modify_config
417
- stage3
418
- output = @producer.instance_eval { @epub.mytoc }
419
- expect = <<EOT
420
- <?xml version="1.0" encoding="UTF-8"?>
421
- <!DOCTYPE html>
422
- <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">
423
- <head>
424
- <meta charset="UTF-8" />
425
- <meta name="generator" content="Re:VIEW" />
426
- <title>Table of Contents</title>
427
- </head>
428
- <body>
429
- <h1 class="toc-title">Table of Contents</h1>
430
- <ul class="toc-h1">
431
- <li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
432
- <li><a href="ch02.html">CH02</a></li>
433
- <li><a href="ch02.html#S1">CH02.1</a></li>
434
- <li><a href="ch02.html#S2">CH02.2</a></li>
435
- <li><a href="ch03.html">CH03</a></li>
436
- <li><a href="ch03.html#S1">CH03.1</a></li>
437
- <li><a href="ch04.html">CH04</a></li>
438
- </ul>
439
- </body>
440
- </html>
441
- EOT
442
- assert_equal expect, output
443
- end
444
-
445
- def test_stage3_cover
446
- stage3
447
- output = @producer.instance_eval { @epub.cover }
448
- expect = <<EOT
449
- <?xml version="1.0" encoding="UTF-8"?>
450
- <!DOCTYPE html>
451
- <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">
452
- <head>
453
- <meta charset="UTF-8" />
454
- <meta name="generator" content="Re:VIEW" />
455
- <title>Sample Book</title>
456
- </head>
457
- <body epub:type="cover">
458
- <h1 class="cover-title">Sample Book</h1>
459
- </body>
460
- </html>
461
- EOT
462
- assert_equal expect, output
463
- end
464
-
465
- def test_stage3_cover_with_image
466
- stage3
467
- @producer.config['coverimage'] = 'sample.png'
468
- @producer.modify_config
469
- output = @producer.instance_eval { @epub.cover }
470
- expect = <<EOT
471
- <?xml version="1.0" encoding="UTF-8"?>
472
- <!DOCTYPE html>
473
- <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">
474
- <head>
475
- <meta charset="UTF-8" />
476
- <meta name="generator" content="Re:VIEW" />
477
- <title>Sample Book</title>
478
- </head>
479
- <body epub:type="cover">
480
- <div id="cover-image" class="cover-image">
481
- <img src="sample.png" alt="Sample Book" class="max"/>
482
- </div>
483
- </body>
484
- </html>
485
- EOT
486
- assert_equal expect, output
487
- end
488
-
489
- def test_colophon_default
490
- @producer.config.merge!('aut' => ['Mr.Smith'],
491
- 'pbl' => ['BLUEPRINT'])
492
- @producer.modify_config
493
- output = @producer.instance_eval { @epub.colophon }
494
- expect = <<EOT
495
- <?xml version="1.0" encoding="UTF-8"?>
496
- <!DOCTYPE html>
497
- <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">
498
- <head>
499
- <meta charset="UTF-8" />
500
- <meta name="generator" content="Re:VIEW" />
501
- <title>Colophon</title>
502
- </head>
503
- <body>
504
- <div class="colophon">
505
- <p class="title">Sample Book</p>
506
- <div class="pubhistory">
507
- <p>published by Jan. 1, 2011</p>
508
- </div>
509
- <table class="colophon">
510
- <tr><th>Author</th><td>Mr.Smith</td></tr>
511
- <tr><th>Publisher</th><td>BLUEPRINT</td></tr>
512
- </table>
513
- </div>
514
- </body>
515
- </html>
516
- EOT
517
- assert_equal expect, output
518
- end
519
-
520
- def test_colophon_pht
521
- @producer.config.merge!('aut' => ['Mr.Smith'],
522
- 'pbl' => ['BLUEPRINT'],
523
- 'pht' => ['Mrs.Smith'])
524
- @producer.modify_config
525
- output = @producer.instance_eval { @epub.colophon }
526
- expect = <<EOT
527
- <?xml version="1.0" encoding="UTF-8"?>
528
- <!DOCTYPE html>
529
- <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">
530
- <head>
531
- <meta charset="UTF-8" />
532
- <meta name="generator" content="Re:VIEW" />
533
- <title>Colophon</title>
534
- </head>
535
- <body>
536
- <div class="colophon">
537
- <p class="title">Sample Book</p>
538
- <div class="pubhistory">
539
- <p>published by Jan. 1, 2011</p>
540
- </div>
541
- <table class="colophon">
542
- <tr><th>Author</th><td>Mr.Smith</td></tr>
543
- <tr><th>Publisher</th><td>BLUEPRINT</td></tr>
544
- <tr><th>Director of Photography</th><td>Mrs.Smith</td></tr>
545
- </table>
546
- </div>
547
- </body>
548
- </html>
549
- EOT
550
- assert_equal expect, output
551
- end
552
-
553
- def test_colophon_history
554
- @producer.config.merge!('aut' => 'Mr.Smith',
555
- 'pbl' => 'BLUEPRINT',
556
- 'pht' => 'Mrs.Smith',
557
- 'language' => 'ja')
558
- @producer.modify_config
559
- history = @producer.instance_eval { @epub.colophon_history }
560
- expect = <<EOT
561
- <div class="pubhistory">
562
- <p>2011年1月1日 発行</p>
563
- </div>
564
- EOT
565
- assert_equal expect, history
566
- end
567
-
568
- def test_colophon_history_2
569
- @producer.config.merge!('aut' => ['Mr.Smith'],
570
- 'pbl' => ['BLUEPRINT'],
571
- 'pht' => ['Mrs.Smith'],
572
- 'language' => 'ja',
573
- 'history' => [['2011-08-03 v1.0.0版発行', '2012-02-15 v1.1.0版発行']])
574
- @producer.modify_config
575
- history = @producer.instance_eval { @epub.colophon_history }
576
- expect = <<EOT
577
- <div class="pubhistory">
578
- <p>2011年8月3日 v1.0.0版発行</p>
579
- <p>2012年2月15日 v1.1.0版発行</p>
580
- </div>
581
- EOT
582
- assert_equal expect, history
583
- end
584
-
585
- def test_colophon_history_date
586
- @producer.config.merge!('aut' => ['Mr.Smith'],
587
- 'pbl' => ['BLUEPRINT'],
588
- 'pht' => ['Mrs.Smith'],
589
- 'language' => 'ja',
590
- 'history' => [['2011-08-03', '2012-02-15']])
591
- @producer.modify_config
592
- history = @producer.instance_eval { @epub.colophon_history }
593
- expect = <<EOT
594
- <div class="pubhistory">
595
- <p>2011年8月3日 初版第1刷 発行</p>
596
- <p>2012年2月15日 初版第2刷 発行</p>
597
- </div>
598
- EOT
599
- assert_equal expect, history
600
- end
601
-
602
- def test_colophon_history_date2
603
- @producer.config.merge!('aut' => ['Mr.Smith'],
604
- 'pbl' => ['BLUEPRINT'],
605
- 'pht' => ['Mrs.Smith'],
606
- 'language' => 'ja',
607
- 'history' => [['2011-08-03', '2012-02-15'],
608
- ['2012-10-01'],
609
- ['2013-03-01']])
610
- @producer.modify_config
611
- history = @producer.instance_eval { @epub.colophon_history }
612
- expect = <<EOT
613
- <div class="pubhistory">
614
- <p>2011年8月3日 初版第1刷 発行</p>
615
- <p>2012年2月15日 初版第2刷 発行</p>
616
- <p>2012年10月1日 第2版第1刷 発行</p>
617
- <p>2013年3月1日 第3版第1刷 発行</p>
618
- </div>
619
- EOT
620
- assert_equal expect, history
621
- end
622
-
623
- def test_detect_mathml
624
- Dir.mktmpdir do |dir|
625
- epubmaker = ReVIEW::EPUBMaker.new
626
- path = File.join(dir, 'test.html')
627
- html = <<EOT
628
- <?xml version="1.0" encoding="UTF-8"?>
629
- <!DOCTYPE html>
630
- <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">
631
- <head>
632
- <meta charset="UTF-8" />
633
- <meta name="generator" content="Re:VIEW" />
634
- <title>Colophon</title>
635
- </head>
636
- <body>
637
- <div>
638
- <p><span class="equation"><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mfrac><mrow><mo stretchy='false'>-</mo><mi>b</mi><mo stretchy='false'>&#xb1;</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo stretchy='false'>-</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math></span></p>
639
- </div>
640
- </body>
641
- </html>
642
- EOT
643
- File.write(path, html)
644
- assert_equal ['mathml'], epubmaker.detect_properties(path)
645
- end
646
- end
647
-
648
- def test_detect_mathml_ns
649
- Dir.mktmpdir do |dir|
650
- epubmaker = ReVIEW::EPUBMaker.new
651
- path = File.join(dir, 'test.html')
652
- html = <<EOT
653
- <?xml version="1.0" encoding="UTF-8"?>
654
- <!DOCTYPE html>
655
- <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">
656
- <head>
657
- <meta charset="UTF-8" />
658
- <meta name="generator" content="Re:VIEW" />
659
- <title>Colophon</title>
660
- </head>
661
- <body>
662
- <div>
663
- <p><span class="equation"><m:math xmlns:m='http://www.w3.org/1998/Math/MathML' display='inline'><m:mfrac><m:mrow><m:mo stretchy='false'>-</m:mo><m:mi>b</m:mi><m:mo stretchy='false'>&#xb1;</m:mo><m:msqrt><m:mrow><m:msup><m:mi>b</m:mi><m:mn>2</m:mn></m:msup><m:mo stretchy='false'>-</m:mo><m:mn>4</m:mn><m:mi>a</m:mi><m:mi>c</m:mi></m:mrow></m:msqrt></m:mrow><m:mrow><m:mn>2</m:mn><m:mi>a</m:mi></m:mrow></m:mfrac></m:math></span></p>
664
- </div>
665
- </body>
666
- </html>
667
- EOT
668
- File.write(path, html)
669
- assert_equal ['mathml'], epubmaker.detect_properties(path)
670
- end
671
- end
672
-
673
- def test_image_size
674
- begin
675
- require 'image_size'
676
- rescue LoadError
677
- $stderr.puts 'skip test_image_size (cannot find image_size.rb)'
678
- return true
679
- end
680
- epubmaker = ReVIEW::EPUBMaker.new
681
- epubmaker.instance_eval do
682
- def warn(msg)
683
- $stderr.puts msg
684
- end
685
- end
686
- _out, err = capture_output do
687
- epubmaker.check_image_size(assets_dir, 5500, %w[png gif jpg jpeg svg ttf woff otf])
688
- end
689
-
690
- expected = <<-EOS
691
- large.gif: 250x150 exceeds a limit. suggeted value is 95x57
692
- large.jpg: 250x150 exceeds a limit. suggeted value is 95x57
693
- large.png: 250x150 exceeds a limit. suggeted value is 95x57
694
- large.svg: 250x150 exceeds a limit. suggeted value is 95x57
695
- EOS
696
- assert_equal expected, err
697
- end
698
-
699
- def test_build_part
700
- Dir.mktmpdir do |tmpdir|
701
- book = ReVIEW::Book::Base.new
702
- book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re])
703
- io1 = StringIO.new("//list[sampletest][a]{\nfoo\n//}\n")
704
- chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
705
- part1 = ReVIEW::Book::Part.new(book, 1, [chap1])
706
- book.parts = [part1]
707
- epubmaker = ReVIEW::EPUBMaker.new
708
- epubmaker.instance_eval do
709
- @config = book.config
710
- @producer = ReVIEW::EPUBMaker::Producer.new(@config)
711
- end
712
- epubmaker.build_part(part1, tmpdir, 'part1.html')
713
-
714
- expected = <<-EOB
715
- <?xml version="1.0" encoding="UTF-8"?>
716
- <!DOCTYPE html>
717
- <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="ja">
718
- <head>
719
- <meta charset="UTF-8" />
720
- <meta name="generator" content="Re:VIEW" />
721
- <title></title>
722
- </head>
723
- <body>
724
- <div class="part">
725
- <h1 class="part-number">第I部</h1>
726
- </div>
727
- </body>
728
- </html>
729
- EOB
730
- assert_equal expected, File.read(File.join(tmpdir, 'part1.html'))
731
- end
732
- end
733
- end