review 5.0.0 → 5.3.0

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