review 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +293 -6
  4. data/.rubocop_todo.yml +3 -608
  5. data/.travis.yml +6 -13
  6. data/README.md +5 -3
  7. data/Rakefile +6 -6
  8. data/bin/review-catalog-converter +2 -2
  9. data/bin/review-check +1 -1
  10. data/bin/review-compile +1 -2
  11. data/bin/review-init +6 -3
  12. data/bin/review-validate +3 -3
  13. data/bin/review-vol +2 -1
  14. data/doc/NEWS.ja.md +138 -25
  15. data/doc/NEWS.md +137 -25
  16. data/doc/config.yml.sample +2 -2
  17. data/doc/config.yml.sample-simple +1 -1
  18. data/doc/format.ja.md +86 -5
  19. data/doc/format.md +67 -2
  20. data/doc/makeindex.ja.md +95 -0
  21. data/doc/makeindex.md +97 -0
  22. data/doc/sample.css +214 -0
  23. data/lib/epubmaker.rb +6 -6
  24. data/lib/epubmaker/epubcommon.rb +19 -47
  25. data/lib/epubmaker/epubv2.rb +3 -1
  26. data/lib/epubmaker/epubv3.rb +4 -26
  27. data/lib/epubmaker/producer.rb +46 -46
  28. data/lib/epubmaker/zip_exporter.rb +86 -0
  29. data/lib/review/book/base.rb +13 -15
  30. data/lib/review/book/chapter.rb +2 -1
  31. data/lib/review/book/compilable.rb +9 -9
  32. data/lib/review/book/image_finder.rb +13 -13
  33. data/lib/review/book/index.rb +2 -2
  34. data/lib/review/book/volume.rb +2 -2
  35. data/lib/review/builder.rb +57 -1
  36. data/lib/review/catalog.rb +2 -2
  37. data/lib/review/compiler.rb +15 -7
  38. data/lib/review/configure.rb +11 -0
  39. data/lib/review/epubmaker.rb +403 -401
  40. data/lib/review/ewbbuilder.rb +16 -16
  41. data/lib/review/htmlbuilder.rb +42 -58
  42. data/lib/review/htmltoc.rb +1 -1
  43. data/lib/review/htmlutils.rb +50 -4
  44. data/lib/review/i18n.rb +2 -2
  45. data/lib/review/idgxmlbuilder.rb +30 -47
  46. data/lib/review/latexbuilder.rb +86 -41
  47. data/lib/review/latexutils.rb +19 -19
  48. data/lib/review/markdownbuilder.rb +16 -4
  49. data/lib/review/md2inaobuilder.rb +0 -9
  50. data/lib/review/pdfmaker.rb +91 -48
  51. data/lib/review/preprocessor.rb +1 -1
  52. data/lib/review/rstbuilder.rb +763 -0
  53. data/lib/review/sec_counter.rb +7 -9
  54. data/lib/review/tocparser.rb +3 -3
  55. data/lib/review/tocprinter.rb +5 -5
  56. data/lib/review/topbuilder.rb +48 -56
  57. data/lib/review/version.rb +1 -1
  58. data/lib/review/webmaker.rb +6 -7
  59. data/review.gemspec +1 -0
  60. data/templates/latex/layout.tex.erb +27 -2
  61. data/test/assets/test_template.tex +10 -1
  62. data/test/book_test_helper.rb +1 -2
  63. data/test/run_test.rb +10 -0
  64. data/test/sample-book/src/style.css +215 -0
  65. data/test/sample-book/src/vendor/jumoline/lppl.txt +416 -0
  66. data/test/test_book.rb +0 -1
  67. data/test/test_catalog.rb +1 -0
  68. data/test/test_converter.rb +1 -1
  69. data/test/test_epub3maker.rb +44 -51
  70. data/test/test_epubmaker.rb +82 -38
  71. data/test/test_epubmaker_cmd.rb +1 -1
  72. data/test/test_extentions_hash.rb +8 -1
  73. data/test/test_htmlbuilder.rb +411 -18
  74. data/test/test_i18n.rb +17 -0
  75. data/test/test_idgxmlbuilder.rb +88 -3
  76. data/test/test_image_finder.rb +18 -0
  77. data/test/test_index.rb +2 -0
  78. data/test/test_latexbuilder.rb +96 -8
  79. data/test/test_makerhelper.rb +2 -2
  80. data/test/test_markdownbuilder.rb +22 -1
  81. data/test/test_md2inaobuilder.rb +0 -5
  82. data/test/test_pdfmaker.rb +54 -36
  83. data/test/test_pdfmaker_cmd.rb +1 -1
  84. data/test/test_rstbuilder.rb +356 -0
  85. data/test/test_textutils.rb +14 -4
  86. data/test/test_topbuilder.rb +23 -4
  87. data/test/test_zip_exporter.rb +113 -0
  88. metadata +28 -2
@@ -25,7 +25,7 @@ class PDFMakerCmdTest < Test::Unit::TestCase
25
25
  if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM
26
26
  config = prepare_samplebook(@tmpdir1)
27
27
  builddir = @tmpdir1 + "/" + config['bookname'] + '-pdf'
28
- assert ! File.exist?(builddir)
28
+ assert !File.exist?(builddir)
29
29
 
30
30
  ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
31
31
  Dir.chdir(@tmpdir1) do
@@ -0,0 +1,356 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'review/compiler'
5
+ require 'review/book'
6
+ require 'review/topbuilder'
7
+ require 'review/i18n'
8
+
9
+ class RSTBuidlerTest < Test::Unit::TestCase
10
+ include ReVIEW
11
+
12
+ def setup
13
+ @builder = RSTBuilder.new()
14
+ @config = ReVIEW::Configure.values
15
+ @config.merge!({
16
+ "secnolevel" => 2,
17
+ "language" => "ja",
18
+ })
19
+ @book = Book::Base.new(nil)
20
+ @book.config = @config
21
+ @compiler = ReVIEW::Compiler.new(@builder)
22
+ @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
23
+ location = Location.new(nil, nil)
24
+ @builder.bind(@compiler, @chapter, location)
25
+
26
+ @builder.instance_eval do
27
+ # to ignore lineno in original method
28
+ def warn(msg)
29
+ puts msg
30
+ end
31
+ end
32
+ I18n.setup(@config["language"])
33
+ end
34
+
35
+ def test_headline_level1
36
+ actual = compile_block("={test} this is test.\n")
37
+ assert_equal %Q|.. _test:\n\n==========================\nthis is test.\n==========================\n\n|, actual
38
+ end
39
+
40
+ def test_headline_level1_without_secno
41
+ @config["secnolevel"] = 0
42
+ actual = compile_block("={test} this is test.\n")
43
+ assert_equal %Q|.. _test:\n\n==========================\nthis is test.\n==========================\n\n|, actual
44
+ end
45
+
46
+ def test_headline_level2
47
+ actual = compile_block("=={test} this is test.\n")
48
+ assert_equal %Q|.. _test:\n\nthis is test.\n==========================\n\n|, actual
49
+ end
50
+
51
+ def test_headline_level3
52
+ actual = compile_block("==={test} this is test.\n")
53
+ assert_equal %Q|.. _test:\n\nthis is test.\n--------------------------\n\n|, actual
54
+ end
55
+
56
+ def test_headline_level3_with_secno
57
+ @config["secnolevel"] = 3
58
+ actual = compile_block("==={test} this is test.\n")
59
+ assert_equal %Q|.. _test:\n\nthis is test.\n--------------------------\n\n|, actual
60
+ end
61
+
62
+ def test_href
63
+ actual = compile_inline("@<href>{http://github.com, GitHub}")
64
+ assert_equal %Q| `GitHub <http://github.com>`_ |, actual
65
+ end
66
+
67
+ def test_href_without_label
68
+ actual = compile_inline("@<href>{http://github.com}")
69
+ assert_equal %Q| `http://github.com <http://github.com>`_ |, actual
70
+ end
71
+
72
+ def test_inline_raw
73
+ actual = compile_inline("@<raw>{@<tt>{inline\}}")
74
+ assert_equal %Q|@<tt>{inline}|, actual
75
+ end
76
+
77
+ def test_inline_ruby
78
+ actual = compile_inline("@<ruby>{coffin,bed}")
79
+ assert_equal %Q| :ruby:`coffin`<bed>`_ |, actual
80
+ end
81
+
82
+ def test_inline_kw
83
+ actual = compile_inline("@<kw>{ISO, International Organization for Standardization } @<kw>{Ruby<>}")
84
+ assert_equal %Q| **ISO(International Organization for Standardization)** **Ruby<>** |, actual
85
+ end
86
+
87
+ def test_inline_maru
88
+ actual = compile_inline("@<maru>{1}@<maru>{20}@<maru>{A}@<maru>{z}")
89
+ assert_equal %Q| :maru:`1` :maru:`20` :maru:`A` :maru:`z` |, actual
90
+ end
91
+
92
+ def test_inline_br
93
+ actual = compile_inline("@<br>{}")
94
+ assert_equal %Q|\n|, actual
95
+ end
96
+
97
+ def test_inline_i
98
+ actual = compile_inline("test @<i>{inline test} test2")
99
+ assert_equal %Q|test *inline test* test2|, actual
100
+ end
101
+
102
+ def test_inline_i_and_escape
103
+ actual = compile_inline("test @<i>{inline<&;\\ test} test2")
104
+ assert_equal %Q|test *inline<&;\\ test* test2|, actual
105
+ end
106
+
107
+ def test_inline_b
108
+ actual = compile_inline("test @<b>{inline test} test2")
109
+ assert_equal %Q|test **inline test** test2|, actual
110
+ end
111
+
112
+ def test_inline_b_and_escape
113
+ actual = compile_inline("test @<b>{inline<&;\\ test} test2")
114
+ assert_equal %Q|test **inline<&;\\ test** test2|, actual
115
+ end
116
+
117
+ def test_inline_tt
118
+ actual = compile_inline("test @<tt>{inline test} test2@<tt>{\\}}")
119
+ assert_equal %Q|test ``inline test`` test2 ``}`` |, actual
120
+ end
121
+
122
+ def test_inline_tti
123
+ actual = compile_inline("test @<tti>{inline test} test2")
124
+ assert_equal %Q|test ``inline test`` test2|, actual
125
+ end
126
+
127
+ def test_inline_ttb
128
+ actual = compile_inline("test @<ttb>{inline test} test2")
129
+ assert_equal %Q|test ``inline test`` test2|, actual
130
+ end
131
+
132
+ def test_inline_uchar
133
+ actual = compile_inline("test @<uchar>{2460} test2")
134
+ assert_equal %Q|test ① test2|, actual
135
+ end
136
+
137
+ def test_inline_comment
138
+ actual = compile_inline("test @<comment>{コメント} test2")
139
+ assert_equal %Q|test test2|, actual
140
+ end
141
+
142
+ def test_inline_comment_for_draft
143
+ @config["draft"] = true
144
+ actual = compile_inline("test @<comment>{コメント} test2")
145
+ assert_equal %Q|test コメント test2|, actual
146
+ end
147
+
148
+ def test_inline_in_table
149
+ actual = compile_block("//table{\n★1☆\t▲2☆\n------------\n★3☆\t▲4☆<>&\n//}\n")
150
+ assert_equal %Q| * - ★1☆\n - ▲2☆\n * - ★3☆\n - ▲4☆<>&\n\n|, actual
151
+ end
152
+
153
+ def test_paragraph
154
+ actual = compile_block("foo\nbar\n")
155
+ assert_equal %Q|foobar\n\n|, actual
156
+ end
157
+
158
+ def test_tabbed_paragraph
159
+ actual = compile_block("\tfoo\nbar\n")
160
+ assert_equal %Q|\tfoobar\n\n|, actual
161
+ end
162
+
163
+ def test_flushright
164
+ actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
165
+ assert_equal %Q|.. flushright::\n\n foobar\nbuz\n\n|, actual
166
+ end
167
+
168
+ def test_noindent
169
+ actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
170
+ assert_equal %Q|foobar\n\nfoo2bar2\n\n|, actual
171
+ end
172
+
173
+ def test_comment
174
+ actual = compile_block("//comment[コメント]")
175
+ assert_equal %Q|\n|, actual
176
+ end
177
+
178
+ def test_comment_for_draft
179
+ @config["draft"] = true
180
+ actual = compile_block("//comment[コメント]")
181
+ assert_equal %Q|\n|, actual
182
+ end
183
+
184
+ def test_list
185
+ def @chapter.list(id)
186
+ Book::ListIndex::Item.new("test",1)
187
+ end
188
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
189
+ assert_equal %Q|.. _samplelist:\n\n-foo\n-bar\n|, actual
190
+ end
191
+
192
+ def test_listnum
193
+ def @chapter.list(id)
194
+ Book::ListIndex::Item.new("test",1)
195
+ end
196
+ actual = compile_block("//listnum[test][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
197
+ assert_equal %Q|.. _test:\n\n1\n2\n\n|, actual
198
+ end
199
+
200
+ def test_emlistnum
201
+ actual = compile_block("//emlistnum[this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
202
+ assert_equal %Q|this is @<b>{test}<&>_\n\n.. code-block:: none\n :linenos:\n\n foo\n bar\n\n|, actual
203
+ end
204
+
205
+ def test_major_blocks
206
+ actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
207
+ expected = %Q(.. note::\n\n A\nB\n\n.. note::\n\n caption\n A\n\n)
208
+ assert_equal expected, actual
209
+
210
+ actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
211
+ expected = %Q(.. memo::\n\n A\nB\n\n.. memo::\n\n caption\n A\n\n)
212
+ assert_equal expected, actual
213
+
214
+ actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
215
+ expected = %Q(.. info::\n\n A\nB\n\n.. info::\n\n caption\n A\n\n)
216
+ assert_equal expected, actual
217
+
218
+ actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
219
+ expected = %Q(.. important::\n\n A\nB\n\n.. important::\n\n caption\n A\n\n)
220
+ assert_equal expected, actual
221
+
222
+ actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
223
+ expected = %Q(.. caution::\n\n A\nB\n\n.. caution::\n\n caption\n A\n\n)
224
+ assert_equal expected, actual
225
+
226
+ actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
227
+ expected = %Q(.. notice::\n\n A\nB\n\n.. notice::\n\n caption\n A\n\n)
228
+ assert_equal expected, actual
229
+
230
+ actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
231
+ expected = %Q(.. warning::\n\n A\nB\n\n.. warning::\n\n caption\n A\n\n)
232
+ assert_equal expected, actual
233
+
234
+ actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
235
+ expected = %Q(.. tip::\n\n A\nB\n\n.. tip::\n\n caption\n A\n\n)
236
+ assert_equal expected, actual
237
+ end
238
+
239
+ def test_image
240
+ def @chapter.image(id)
241
+ item = Book::ImageIndex::Item.new("sampleimg",1)
242
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
243
+ item
244
+ end
245
+
246
+ actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n")
247
+ assert_equal %Q|.. _sampleimg:\n\n.. figure:: images/-/sampleimg.png\n\n sample photo\n\n|, actual
248
+ end
249
+
250
+ def test_image_with_metric
251
+ def @chapter.image(id)
252
+ item = Book::ImageIndex::Item.new("sampleimg",1)
253
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
254
+ item
255
+ end
256
+
257
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\nfoo\n//}\n")
258
+ assert_equal %Q|.. _sampleimg:\n\n.. figure:: images/-/sampleimg.png\n :scale:120.0%\n\n sample photo\n\n|, actual
259
+ end
260
+
261
+ def test_texequation
262
+ actual = compile_block("//texequation{\n\\sin\n1^{2}\n//}\n")
263
+ expected = <<-EOS
264
+ .. math::
265
+
266
+ \\sin 1^{2}
267
+
268
+ EOS
269
+ assert_equal expected, actual
270
+ end
271
+
272
+ def test_inline_raw0
273
+ assert_equal "normal", compile_inline("@<raw>{normal}")
274
+ end
275
+
276
+ def test_inline_raw1
277
+ assert_equal "body", compile_inline("@<raw>{|top|body}")
278
+ end
279
+
280
+ def test_inline_raw2
281
+ assert_equal "body", compile_inline("@<raw>{|top, latex|body}")
282
+ end
283
+
284
+ def test_inline_raw3
285
+ assert_equal "body", compile_inline("@<raw>{|idgxml, html|body}")
286
+ end
287
+
288
+ def test_inline_raw4
289
+ assert_equal "|top body", compile_inline("@<raw>{|top body}")
290
+ end
291
+
292
+ def test_inline_raw5
293
+ assert_equal "nor\nmal", compile_inline("@<raw>{|top|nor\\nmal}")
294
+ end
295
+
296
+ def test_block_raw0
297
+ actual = compile_block("//raw[<>!\"\\n& ]\n")
298
+ expected = %Q(<>!\"\n& )
299
+ assert_equal expected.chomp, actual
300
+ end
301
+
302
+ def test_block_raw1
303
+ actual = compile_block("//raw[|top|<>!\"\\n& ]\n")
304
+ expected = ''
305
+ assert_equal expected.chomp, actual
306
+ end
307
+
308
+ def test_block_raw2
309
+ actual = compile_block("//raw[|top, latex|<>!\"\\n& ]\n")
310
+ expected = ''
311
+ assert_equal expected.chomp, actual
312
+ end
313
+
314
+ def test_block_raw3
315
+ actual = compile_block("//raw[|latex, idgxml|<>!\"\\n& ]\n")
316
+ expected = ''
317
+ assert_equal expected.chomp, actual
318
+ end
319
+
320
+ def test_block_raw4
321
+ actual = compile_block("//raw[|top <>!\"\\n& ]\n")
322
+ expected = %Q(|top <>!\"\n& )
323
+ assert_equal expected.chomp, actual
324
+ end
325
+
326
+ def column_helper(review)
327
+ compile_block(review)
328
+ end
329
+
330
+ def test_column_ref
331
+ review =<<-EOS
332
+ ===[column]{foo} test
333
+
334
+ inside column
335
+
336
+ === next level
337
+
338
+ this is @<column>{foo}.
339
+ EOS
340
+ expected =<<-EOS
341
+ .. column:: test
342
+
343
+ inside column
344
+
345
+
346
+ next level
347
+ --------------------
348
+
349
+ this is test.
350
+
351
+ EOS
352
+
353
+ assert_equal expected, column_helper(review)
354
+ end
355
+
356
+ end
@@ -7,13 +7,23 @@ class TextUtilsTest < Test::Unit::TestCase
7
7
  def setup
8
8
  @tu_nil = Object.new
9
9
  @tu_nil.extend ReVIEW::TextUtils
10
- def @tu_nil.pre_paragraph;nil;end
11
- def @tu_nil.post_paragraph;nil;end
10
+ def @tu_nil.pre_paragraph
11
+ nil
12
+ end
13
+
14
+ def @tu_nil.post_paragraph
15
+ nil
16
+ end
12
17
 
13
18
  @tu_p = Object.new
14
19
  @tu_p.extend ReVIEW::TextUtils
15
- def @tu_p.pre_paragraph;'<p>';end
16
- def @tu_p.post_paragraph;'</p>';end
20
+ def @tu_p.pre_paragraph
21
+ '<p>'
22
+ end
23
+
24
+ def @tu_p.post_paragraph
25
+ '</p>'
26
+ end
17
27
  end
18
28
 
19
29
  def test_detab
@@ -13,9 +13,9 @@ class TOPBuidlerTest < Test::Unit::TestCase
13
13
  @builder = TOPBuilder.new()
14
14
  @config = ReVIEW::Configure.values
15
15
  @config.merge!({
16
- "secnolevel" => 2,
17
- "language" => "ja",
18
- })
16
+ "secnolevel" => 2,
17
+ "language" => "ja",
18
+ })
19
19
  @book = Book::Base.new(nil)
20
20
  @book.config = @config
21
21
  @compiler = ReVIEW::Compiler.new(@builder)
@@ -142,7 +142,7 @@ class TOPBuidlerTest < Test::Unit::TestCase
142
142
  def test_inline_comment_for_draft
143
143
  @config["draft"] = true
144
144
  actual = compile_inline("test @<comment>{コメント} test2")
145
- assert_equal %Q|test ◆→DTP連絡:コメント←◆ test2|, actual
145
+ assert_equal %Q|test ◆→コメント←◆ test2|, actual
146
146
  end
147
147
 
148
148
  def test_inline_in_table
@@ -170,6 +170,17 @@ class TOPBuidlerTest < Test::Unit::TestCase
170
170
  assert_equal %Q|◆→DTP連絡:次の1行インデントなし←◆\nfoobar\nfoo2bar2\n|, actual
171
171
  end
172
172
 
173
+ def test_comment
174
+ actual = compile_block("//comment[コメント]")
175
+ assert_equal %Q||, actual
176
+ end
177
+
178
+ def test_comment_for_draft
179
+ @config["draft"] = true
180
+ actual = compile_block("//comment[コメント]")
181
+ assert_equal %Q|◆→コメント←◆\n|, actual
182
+ end
183
+
173
184
  def test_list
174
185
  def @chapter.list(id)
175
186
  Book::ListIndex::Item.new("test",1)
@@ -191,6 +202,14 @@ class TOPBuidlerTest < Test::Unit::TestCase
191
202
  assert_equal %Q|◆→開始:インラインリスト←◆\n■this is ★test☆<&>_\n 1: foo\n 2: bar\n◆→終了:インラインリスト←◆\n\n|, actual
192
203
  end
193
204
 
205
+ def test_bib
206
+ def @chapter.bibpaper(id)
207
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
208
+ end
209
+
210
+ assert_equal %Q|[1]|, compile_inline("@<bib>{samplebib}")
211
+ end
212
+
194
213
  def test_major_blocks
195
214
  actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
196
215
  expected = %Q(◆→開始:ノート←◆\nA\nB\n◆→終了:ノート←◆\n\n◆→開始:ノート←◆\n■caption\nA\n◆→終了:ノート←◆\n\n)
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'epubmaker'
5
+ require 'epubmaker/zip_exporter'
6
+ require 'fileutils'
7
+
8
+ class ZipExporterTest < Test::Unit::TestCase
9
+ include EPUBMaker
10
+
11
+ def setup
12
+ @tmpdir = Dir.mktmpdir
13
+ @epubdir = "#{@tmpdir}/epubdir"
14
+ FileUtils.mkdir_p("#{@epubdir}/META-INF")
15
+ FileUtils.mkdir_p("#{@epubdir}/OEBPS")
16
+ File.write("#{@epubdir}/mimetype", "application/epub+zip")
17
+
18
+ container_xml = <<-EOB
19
+ <?xml version="1.0" encoding="UTF-8"?>
20
+ <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
21
+ <rootfiles>
22
+ <rootfile full-path="OEBPS/book.opf" media-type="application/oebps-package+xml" />
23
+ </rootfiles>
24
+ </container>
25
+ EOB
26
+
27
+ book_opf = <<-EOB
28
+ <?xml version="1.0"?>
29
+ <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookID" version="2.0">
30
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
31
+ <dc:title>sample epub</dc:title>
32
+ <dc:creator opf:role="aut">AUTHOR</dc:creator>
33
+ <dc:language>ja</dc:language>
34
+ <dc:identifier id="BookID" opf:scheme="URL">http://example.com/epub/sample/sample1.epub</dc:identifier>
35
+ </metadata>
36
+ <manifest>
37
+ <item id="ch1.xhtml" href="OEBPS/ch1.xhtml" media-type="application/xhtml+xml"/>
38
+ </manifest>
39
+ <spine toc="ncx">
40
+ <itemref idref="ch1.xhtml"/>
41
+ </spine>
42
+ <guide>
43
+ <reference type="cover" title="Cover Page" href="OEPBS/ch1.xhtml"/>
44
+ </guide>
45
+ </package>
46
+ EOB
47
+
48
+ ch1_xhtml = <<-EOB
49
+ <html>
50
+ <head>
51
+ <title>test</title>
52
+ </head>
53
+ <body>
54
+ <p>hello, world!</p>
55
+ </body>
56
+ </html>
57
+ EOB
58
+
59
+ File.write("#{@epubdir}/META-INF/container.xml", container_xml)
60
+ File.write("#{@epubdir}/OEBPS/book.opf", book_opf)
61
+ File.write("#{@epubdir}/OEBPS/ch1.xhtml", ch1_xhtml)
62
+ end
63
+
64
+ def test_export_zipcmd
65
+ if Gem.win_platform?
66
+ ## skip this test
67
+ return
68
+ end
69
+
70
+ params = {"epubmaker"=>{}}
71
+ epubfile = File.join(@tmpdir, "test.epub")
72
+ exporter = ZipExporter.new(@epubdir, params)
73
+ exporter.export_zip_extcmd(epubfile)
74
+ assert_true(File.exist?(epubfile))
75
+
76
+ if defined?(Zip)
77
+ File.open(epubfile) do |f|
78
+ ::Zip::InputStream.open(f) do |fzip|
79
+ ## get first entry
80
+ entry = fzip.get_next_entry
81
+ assert_equal "mimetype", entry.name
82
+ assert_equal "application/epub+zip", fzip.read
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def test_export_rubyzip
89
+ if !defined?(Zip)
90
+ ## skip test
91
+ return
92
+ end
93
+ params = {"epubmaker"=>{}}
94
+ epubfile = File.join(@tmpdir, "test.epub")
95
+ exporter = ZipExporter.new(@epubdir, params)
96
+ exporter.export_zip_rubyzip(epubfile)
97
+ assert_true(File.exist?(epubfile))
98
+
99
+ File.open(epubfile) do |f|
100
+ ::Zip::InputStream.open(f) do |fzip|
101
+ ## get first entry
102
+ entry = fzip.get_next_entry
103
+ assert_equal "mimetype", entry.name
104
+ assert_equal "application/epub+zip", fzip.read
105
+ end
106
+ end
107
+ end
108
+
109
+ def teardown
110
+ FileUtils.remove_entry_secure(@tmpdir)
111
+ end
112
+
113
+ end