gepub 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/gepub.gemspec +1 -2
  4. data/lib/gepub/version.rb +1 -1
  5. metadata +4 -110
  6. data/spec/bindings_spec.rb +0 -34
  7. data/spec/book_spec.rb +0 -307
  8. data/spec/builder_spec.rb +0 -614
  9. data/spec/example_spec.rb +0 -192
  10. data/spec/fixtures/builder/img/cover.jpg +0 -0
  11. data/spec/fixtures/builder/resources/noise.m4 +0 -0
  12. data/spec/fixtures/builder/resources/noise_2.m4a +0 -0
  13. data/spec/fixtures/builder/text/cover.xhtml +0 -11
  14. data/spec/fixtures/builder/text/localresource.conf +0 -2
  15. data/spec/fixtures/builder/text/memo.txt +0 -1
  16. data/spec/fixtures/builder/text/nav.xhtml +0 -12
  17. data/spec/fixtures/epubcheck-4.1.1/CHANGELOG.txt +0 -92
  18. data/spec/fixtures/epubcheck-4.1.1/LICENSE.txt +0 -28
  19. data/spec/fixtures/epubcheck-4.1.1/README.txt +0 -101
  20. data/spec/fixtures/epubcheck-4.1.1/THIRD-PARTY.txt +0 -60
  21. data/spec/fixtures/epubcheck-4.1.1/epubcheck.jar +0 -0
  22. data/spec/fixtures/epubcheck-4.1.1/lib/Saxon-HE-9.8.0-8.jar +0 -0
  23. data/spec/fixtures/epubcheck-4.1.1/lib/animal-sniffer-annotations-1.14.jar +0 -0
  24. data/spec/fixtures/epubcheck-4.1.1/lib/checker-compat-qual-2.0.0.jar +0 -0
  25. data/spec/fixtures/epubcheck-4.1.1/lib/common-image-3.4.1.jar +0 -0
  26. data/spec/fixtures/epubcheck-4.1.1/lib/common-io-3.4.1.jar +0 -0
  27. data/spec/fixtures/epubcheck-4.1.1/lib/common-lang-3.4.1.jar +0 -0
  28. data/spec/fixtures/epubcheck-4.1.1/lib/commons-compress-1.18.jar +0 -0
  29. data/spec/fixtures/epubcheck-4.1.1/lib/error_prone_annotations-2.1.3.jar +0 -0
  30. data/spec/fixtures/epubcheck-4.1.1/lib/guava-24.0-android.jar +0 -0
  31. data/spec/fixtures/epubcheck-4.1.1/lib/imageio-core-3.4.1.jar +0 -0
  32. data/spec/fixtures/epubcheck-4.1.1/lib/imageio-jpeg-3.4.1.jar +0 -0
  33. data/spec/fixtures/epubcheck-4.1.1/lib/imageio-metadata-3.4.1.jar +0 -0
  34. data/spec/fixtures/epubcheck-4.1.1/lib/j2objc-annotations-1.1.jar +0 -0
  35. data/spec/fixtures/epubcheck-4.1.1/lib/jackson-core-asl-1.9.12.jar +0 -0
  36. data/spec/fixtures/epubcheck-4.1.1/lib/jackson-mapper-asl-1.9.12.jar +0 -0
  37. data/spec/fixtures/epubcheck-4.1.1/lib/jing-20120724.0.0.jar +0 -0
  38. data/spec/fixtures/epubcheck-4.1.1/lib/jsr305-1.3.9.jar +0 -0
  39. data/spec/fixtures/epubcheck-4.1.1/lib/sac-1.3.jar +0 -0
  40. data/spec/fixtures/epubcheck-4.1.1/licenses/Apache-2.0.txt +0 -201
  41. data/spec/fixtures/epubcheck-4.1.1/licenses/BSD-3-Clause.txt +0 -27
  42. data/spec/fixtures/epubcheck-4.1.1/licenses/MPL-1.0.txt +0 -360
  43. data/spec/fixtures/epubcheck-4.1.1/licenses/W3C.txt +0 -16
  44. data/spec/fixtures/testdata/0.html +0 -12
  45. data/spec/fixtures/testdata/1.html +0 -10
  46. data/spec/fixtures/testdata/image1.jpg +0 -0
  47. data/spec/fixtures/testdata/package_2_0.opf +0 -23
  48. data/spec/fixtures/testdata/test.opf +0 -69
  49. data/spec/fixtures/testdata/test2.opf +0 -63
  50. data/spec/fixtures/testdata/test_with_bindings.opf +0 -67
  51. data/spec/fixtures/testdata/wasteland-20120118.epub +0 -0
  52. data/spec/gepub_deprectad_api_spec.rb +0 -229
  53. data/spec/gepub_spec.rb +0 -229
  54. data/spec/manifest_spec.rb +0 -36
  55. data/spec/metadata_spec.rb +0 -219
  56. data/spec/package_spec.rb +0 -150
  57. data/spec/spec_helper.rb +0 -57
  58. data/spec/spine_spec.rb +0 -55
@@ -1,614 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.dirname(__FILE__) + '/spec_helper.rb'
3
- require 'rubygems'
4
- describe GEPUB::Builder do
5
- context 'metadata generating' do
6
- it 'should generate language' do
7
- builder = GEPUB::Builder.new {
8
- language 'ja'
9
- }
10
- expect(builder.instance_eval { @book.language }.to_s).to eq('ja')
11
- end
12
-
13
- it 'should generate uid' do
14
- builder = GEPUB::Builder.new {
15
- unique_identifier 'http://example.jp/as_url', 'BookID', 'url'
16
- }
17
- expect(builder.instance_eval { @book.identifier }.to_s).to eq('http://example.jp/as_url')
18
- expect(builder.instance_eval { @book.identifier_list[0]['id']}).to eq('BookID')
19
- expect(builder.instance_eval { @book.identifier_list[0].identifier_type}.to_s).to eq('url')
20
- end
21
-
22
- it 'should generate title' do
23
- builder = GEPUB::Builder.new {
24
- title 'The Book Title'
25
- }
26
- expect(builder.instance_eval { @book.title }.to_s).to eq('The Book Title')
27
- expect(builder.instance_eval { @book.title.title_type }.to_s).to eq('main')
28
- end
29
-
30
- it 'should generate title with type ' do
31
- builder = GEPUB::Builder.new {
32
- subtitle 'the sub-title'
33
- }
34
- expect(builder.instance_eval { @book.title }.to_s).to eq('the sub-title')
35
- expect(builder.instance_eval { @book.title.title_type }.to_s).to eq('subtitle')
36
- end
37
-
38
- it 'should generate collection title ' do
39
- builder = GEPUB::Builder.new {
40
- collection 'the collection', 3
41
- }
42
- expect(builder.instance_eval { @book.title }.to_s).to eq('the collection')
43
- expect(builder.instance_eval { @book.title.title_type }.to_s).to eq('collection')
44
- expect(builder.instance_eval { @book.title.group_position }.to_s).to eq('3')
45
- end
46
-
47
- it 'should refine title: alternates ' do
48
- builder = GEPUB::Builder.new {
49
- collection 'the collection', 3
50
- alt 'ja' => 'シリーズ'
51
- }
52
- expect(builder.instance_eval { @book.title }.to_s).to eq('the collection')
53
- expect(builder.instance_eval { @book.title.title_type }.to_s).to eq('collection')
54
- expect(builder.instance_eval { @book.title.list_alternates['ja'] }.to_s).to eq('シリーズ')
55
- end
56
-
57
- it 'should refine title: file_as ' do
58
- builder = GEPUB::Builder.new {
59
- title 'メインタイトル'
60
- file_as 'main title'
61
- }
62
- expect(builder.instance_eval { @book.title }.to_s).to eq('メインタイトル')
63
- expect(builder.instance_eval { @book.title.title_type }.to_s).to eq('main')
64
- expect(builder.instance_eval { @book.title.file_as }.to_s).to eq('main title')
65
- end
66
-
67
- it 'should refine title: alt and file_as ' do
68
- builder = GEPUB::Builder.new {
69
- title 'メインタイトル'
70
- file_as 'main title'
71
- alt 'en' => 'The Main Title'
72
- }
73
- expect(builder.instance_eval { @book.title }.to_s).to eq('メインタイトル')
74
- expect(builder.instance_eval { @book.title.title_type }.to_s).to eq('main')
75
- expect(builder.instance_eval { @book.title.file_as }.to_s).to eq('main title')
76
- expect(builder.instance_eval { @book.title.list_alternates['en'] }.to_s).to eq('The Main Title')
77
- end
78
-
79
- it 'should generate creator ' do
80
- builder = GEPUB::Builder.new {
81
- creator 'The Main Author'
82
- }
83
- expect(builder.instance_eval { @book.creator }.to_s).to eq('The Main Author')
84
- end
85
-
86
- it 'should generate creator with role' do
87
- builder = GEPUB::Builder.new {
88
- creator 'The Illustrator', 'ill'
89
- }
90
- expect(builder.instance_eval { @book.creator }.to_s).to eq('The Illustrator')
91
- expect(builder.instance_eval { @book.creator.role}.to_s).to eq('ill')
92
- end
93
-
94
- it 'should generate contributor ' do
95
- builder = GEPUB::Builder.new {
96
- contributor 'contributor', 'edt'
97
- }
98
- expect(builder.instance_eval { @book.contributor }.to_s).to eq('contributor')
99
- expect(builder.instance_eval { @book.contributor.role}.to_s).to eq('edt')
100
- end
101
-
102
- it 'should generate multiple creators ' do
103
- builder = GEPUB::Builder.new {
104
- creators 'First Author', 'Second Author', ['Third Person', 'edt']
105
- }
106
- expect(builder.instance_eval { @book.creator_list }.size).to eq(3)
107
- expect(builder.instance_eval { @book.creator_list[0] }.to_s).to eq('First Author')
108
- expect(builder.instance_eval { @book.creator_list[1] }.to_s).to eq('Second Author')
109
- expect(builder.instance_eval { @book.creator_list[2] }.to_s).to eq('Third Person')
110
- expect(builder.instance_eval { @book.creator_list[2].role }.to_s).to eq('edt')
111
- end
112
-
113
- it 'should generate multiple creators, and then add file_as at once ' do
114
- builder = GEPUB::Builder.new {
115
- creators 'First Author', 'Second Author', ['Third Person', 'edt']
116
- file_as '1st', '2nd', '3rd'
117
- }
118
- expect(builder.instance_eval { @book.creator_list }.size).to eq(3)
119
- expect(builder.instance_eval { @book.creator_list[0] }.to_s).to eq('First Author')
120
- expect(builder.instance_eval { @book.creator_list[0].file_as }.to_s).to eq('1st')
121
- expect(builder.instance_eval { @book.creator_list[1] }.to_s).to eq('Second Author')
122
- expect(builder.instance_eval { @book.creator_list[1].file_as }.to_s).to eq('2nd')
123
- expect(builder.instance_eval { @book.creator_list[2] }.to_s).to eq('Third Person')
124
- expect(builder.instance_eval { @book.creator_list[2].file_as }.to_s).to eq('3rd')
125
- expect(builder.instance_eval { @book.creator_list[2].role }.to_s).to eq('edt')
126
- end
127
-
128
-
129
- it 'should generate multiple creators, and multiple alternates ' do
130
- builder = GEPUB::Builder.new {
131
- creators 'First Author', 'Second Author', ['Third Person', 'edt']
132
- alts(
133
- 'ja' => ['最初','二番目', '三番目'],
134
- 'en' => ['first','second','third']
135
- )
136
- }
137
- expect(builder.instance_eval { @book.creator_list }.size).to eq(3)
138
- expect(builder.instance_eval { @book.creator_list[0] }.to_s).to eq('First Author')
139
- expect(builder.instance_eval { @book.creator_list[0].list_alternates['ja'] }.to_s).to eq('最初')
140
- expect(builder.instance_eval { @book.creator_list[0].list_alternates['en'] }.to_s).to eq('first')
141
- expect(builder.instance_eval { @book.creator_list[1] }.to_s).to eq('Second Author')
142
- expect(builder.instance_eval { @book.creator_list[1].list_alternates['ja'] }.to_s).to eq('二番目')
143
- expect(builder.instance_eval { @book.creator_list[1].list_alternates['en'] }.to_s).to eq('second')
144
- expect(builder.instance_eval { @book.creator_list[2] }.to_s).to eq('Third Person')
145
- expect(builder.instance_eval { @book.creator_list[2].list_alternates['ja'] }.to_s).to eq('三番目')
146
- expect(builder.instance_eval { @book.creator_list[2].list_alternates['en'] }.to_s).to eq('third')
147
- expect(builder.instance_eval { @book.creator_list[2].role }.to_s).to eq('edt')
148
- end
149
- end
150
- context 'resources' do
151
- it 'should add a file to book' do
152
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
153
- builder = GEPUB::Builder.new {
154
- resources(:workdir => workdir) {
155
- file('text/memo.txt')
156
- }
157
- }
158
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
159
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt').content.chomp }).to eq('just a plain text.')
160
- end
161
-
162
- it 'should add files to book' do
163
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
164
- builder = GEPUB::Builder.new {
165
- resources(:workdir => workdir) {
166
- files('text/memo.txt','text/cover.xhtml')
167
- }
168
- }
169
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
170
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt').content.chomp }).to eq('just a plain text.')
171
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }).not_to be_nil
172
- end
173
-
174
- it 'should add files to book with glob' do
175
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
176
- builder = GEPUB::Builder.new {
177
- resources(:workdir => workdir) {
178
- glob 'text/*.{txt,xhtml}'
179
- }
180
- }
181
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
182
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt').content.chomp }).to eq('just a plain text.')
183
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }).not_to be_nil
184
- end
185
-
186
- it 'should add files to book with import with prefix' do
187
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
188
- builder = GEPUB::Builder.new {
189
- resources(:workdir => workdir) {
190
- import 'text/localresource.conf'
191
- }
192
- }
193
- expect(builder.instance_eval{ @book.item_by_href('memo.txt') }).not_to be_nil
194
- expect(builder.instance_eval{ @book.item_by_href('memo.txt').content.chomp }).to eq('just a plain text.')
195
- expect(builder.instance_eval{ @book.item_by_href('cover.xhtml') }).not_to be_nil
196
- end
197
-
198
- it 'should add files to book with import with prefix' do
199
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
200
- builder = GEPUB::Builder.new {
201
- resources(:workdir => workdir) {
202
- import 'text/localresource.conf', :dir_prefix => 'text'
203
- }
204
- }
205
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
206
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt').content.chomp }).to eq('just a plain text.')
207
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }).not_to be_nil
208
- end
209
-
210
- it 'should add a file with id' do
211
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
212
- builder = GEPUB::Builder.new {
213
- resources(:workdir => workdir) {
214
- file('text/memo.txt')
215
- id 'the_id_of_memo.txt'
216
- }
217
- }
218
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
219
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt').id }).to eq('the_id_of_memo.txt')
220
- end
221
-
222
- it 'should add files to book from IO object' do
223
- io = File.new(File.join(File.dirname(__FILE__),'fixtures', 'builder', 'text', 'memo.txt'))
224
- builder = GEPUB::Builder.new {
225
- resources() {
226
- file('text/memo.txt' => io)
227
- }
228
- }
229
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
230
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt').content.chomp }).to eq('just a plain text.')
231
- end
232
-
233
- it 'should add image file as cover' do
234
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
235
- builder = GEPUB::Builder.new {
236
- resources(:workdir => workdir) {
237
- cover_image 'img/cover.jpg'
238
- }
239
- }
240
- expect(builder.instance_eval{ @book.item_by_href('img/cover.jpg') }).not_to be_nil
241
- expect(builder.instance_eval{ @book.item_by_href('img/cover.jpg').properties.member? 'cover-image' }).to eq(true)
242
- end
243
-
244
- it 'should add file as nav' do
245
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
246
- builder = GEPUB::Builder.new {
247
- resources(:workdir => workdir) {
248
- nav 'text/nav.xhtml'
249
- }
250
- }
251
- expect(builder.instance_eval{ @book.item_by_href('text/nav.xhtml') }).not_to be_nil
252
- expect(builder.instance_eval{ @book.item_by_href('text/nav.xhtml').properties.member? 'nav' }).to eq(true)
253
- end
254
-
255
- it 'should specify mediatype' do
256
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
257
- builder = GEPUB::Builder.new {
258
- resources(:workdir => workdir) {
259
- file('resources/noise.m4')
260
- media_type('audio/mp4')
261
- }
262
- }
263
- expect(builder.instance_eval{ @book.item_by_href('resources/noise.m4') }).not_to be_nil
264
- expect(builder.instance_eval{ @book.item_by_href('resources/noise.m4').media_type }).to eq('audio/mp4')
265
- end
266
-
267
- it 'should specify mediatype to files' do
268
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
269
- builder = GEPUB::Builder.new {
270
- resources(:workdir => workdir) {
271
- files('resources/noise.m4', 'resources/noise_2.m4a')
272
- media_type('audio/mp4')
273
- }
274
- }
275
- expect(builder.instance_eval{ @book.item_by_href('resources/noise.m4') }).not_to be_nil
276
- expect(builder.instance_eval{ @book.item_by_href('resources/noise.m4').media_type }).to eq('audio/mp4')
277
-
278
- expect(builder.instance_eval{ @book.item_by_href('resources/noise_2.m4a') }).not_to be_nil
279
- expect(builder.instance_eval{ @book.item_by_href('resources/noise_2.m4a').media_type }).to eq('audio/mp4')
280
- end
281
-
282
- it 'should specify mediatype to files using with_media_type' do
283
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
284
- builder = GEPUB::Builder.new {
285
- resources(:workdir => workdir) {
286
- with_media_type('audio/mp4') {
287
- file('resources/noise.m4')
288
- file('resources/noise_2.m4a')
289
- }
290
- file('text/cover.xhtml')
291
- }
292
- }
293
- expect(builder.instance_eval{ @book.item_by_href('resources/noise.m4') }).not_to be_nil
294
- expect(builder.instance_eval{ @book.item_by_href('resources/noise.m4').media_type }).to eq('audio/mp4')
295
-
296
- expect(builder.instance_eval{ @book.item_by_href('resources/noise_2.m4a') }).not_to be_nil
297
- expect(builder.instance_eval{ @book.item_by_href('resources/noise_2.m4a').media_type }).to eq('audio/mp4')
298
-
299
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }).not_to be_nil
300
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml').media_type }).to eq('application/xhtml+xml')
301
- end
302
-
303
- it 'should specify bindings handler' do
304
- builder = GEPUB::Builder.new {
305
- resources {
306
- file 'scripts/handler.xhtml' => nil
307
- handles 'application/x-some-foregin-type'
308
- }
309
- }
310
- builder.instance_eval{
311
- @book.get_handler_of('application/x-some-foregin-type').id == @book.item_by_href('scripts/handler.xhtml').id
312
- }
313
- end
314
-
315
- it 'should add files to book in spine' do
316
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
317
- builder = GEPUB::Builder.new {
318
- resources(:workdir => workdir) {
319
- ordered {
320
- file('text/cover.xhtml')
321
- file('text/memo.txt')
322
- }
323
- }
324
- }
325
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }).not_to be_nil
326
- expect(builder.instance_eval{ @book.spine_items[0].href }).to eq('text/cover.xhtml')
327
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
328
- expect(builder.instance_eval{ @book.spine_items[1].href }).to eq('text/memo.txt')
329
- end
330
-
331
- it 'should add files and heading' do
332
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
333
- builder = GEPUB::Builder.new {
334
- resources(:workdir => workdir) {
335
- ordered {
336
- file('text/cover.xhtml')
337
- heading 'cover page'
338
- file('text/memo.txt')
339
- heading 'memo text'
340
- }
341
- }
342
- }
343
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }).not_to be_nil
344
- expect(builder.instance_eval{ @book.spine_items[0].href }).to eq('text/cover.xhtml')
345
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
346
- expect(builder.instance_eval{ @book.spine_items[1].href }).to eq('text/memo.txt')
347
- expect(builder.instance_eval{ @book.instance_eval { @toc[0][:item].href }}).to eq('text/cover.xhtml')
348
- expect(builder.instance_eval{ @book.instance_eval { @toc[0][:text] }}).to eq('cover page')
349
- expect(builder.instance_eval{ @book.instance_eval { @toc[1][:item].href }}).to eq('text/memo.txt')
350
- expect(builder.instance_eval{ @book.instance_eval { @toc[1][:text] }}).to eq('memo text')
351
- end
352
-
353
- it 'should add files and page-spread-property' do
354
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
355
- builder = GEPUB::Builder.new {
356
- resources(:workdir => workdir) {
357
- ordered {
358
- file('text/cover.xhtml')
359
- page_spread_left
360
- file('text/memo.txt')
361
- page_spread_right
362
- }
363
- }
364
- }
365
- expect(builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }).not_to be_nil
366
- expect(builder.instance_eval{ @book.spine.itemref_list[0].properties[0] }).to eq('page-spread-left')
367
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
368
- expect(builder.instance_eval{ @book.spine.itemref_list[1].properties[0] }).to eq('page-spread-right')
369
- end
370
-
371
- it 'should add files and rendition property' do
372
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
373
- builder = GEPUB::Builder.new {
374
- resources(:workdir => workdir) {
375
- ordered {
376
- file('text/cover.xhtml')
377
- file('text/memo.txt')
378
- rendition_layout 'pre-paginated'
379
- rendition_orientation 'landscape'
380
- rendition_spread 'both'
381
- }
382
- }
383
- }
384
- expect(builder.instance_eval{ @book.item_by_href('text/memo.txt') }).not_to be_nil
385
- expect(builder.instance_eval{ @book.spine.itemref_list[1].properties[0] }).to eq('rendition:layout-pre-paginated')
386
- expect(builder.instance_eval{ @book.spine.itemref_list[1].properties[1] }).to eq('rendition:orientation-landscape')
387
- expect(builder.instance_eval{ @book.spine.itemref_list[1].properties[2] }).to eq('rendition:spread-both')
388
- xml = builder.instance_eval{
389
- Nokogiri::XML::Document.parse @book.opf_xml
390
- }
391
- expect(xml.root['prefix']).to eq 'rendition: http://www.idpf.org/vocab/rendition/#'
392
- end
393
-
394
- it 'whould handle ibooks version' do
395
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
396
- builder = GEPUB::Builder.new {
397
- ibooks_version '1.1.1'
398
- resources(:workdir => workdir) {
399
- ordered {
400
- file('text/cover.xhtml')
401
- file('text/memo.txt')
402
- }
403
- }
404
- }
405
- xml = builder.instance_eval{
406
- Nokogiri::XML::Document.parse @book.opf_xml
407
- }
408
- expect(xml.root['prefix']).to eq 'ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/'
409
- expect(xml.at_xpath("//xmlns:meta[@property='ibooks:version']").content).to eq '1.1.1'
410
- end
411
-
412
- it 'handle ibooks scroll-axis' do
413
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
414
- builder = GEPUB::Builder.new {
415
- ibooks_scroll_axis :vertical
416
- resources(:workdir => workdir) {
417
- ordered {
418
- file('text/cover.xhtml')
419
- file('text/memo.txt')
420
- }
421
- }
422
- }
423
- xml = builder.instance_eval{
424
- Nokogiri::XML::Document.parse @book.opf_xml
425
- }
426
- expect(xml.root['prefix']).to eq 'ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/'
427
- expect(xml.at_xpath("//xmlns:meta[@property='ibooks:scroll-axis']").content).to eq 'vertical'
428
- end
429
-
430
- it 'should handle fallback chain' do
431
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
432
- builder = GEPUB::Builder.new {
433
- resources(:workdir => workdir) {
434
- fallback_group {
435
- file 'chap3_docbook.xml' => nil
436
- media_type('application/docbook+xml')
437
- file 'chap3.xml' => nil
438
- media_type("application/z3986-auth+xml")
439
- file 'chap3.xhtml' => nil
440
- }
441
- }
442
- }
443
- book = builder.instance_eval {
444
- @book
445
- }
446
- fallbackid = book.item_by_href('chap3_docbook.xml').fallback
447
- expect(book.items[fallbackid].href).to eq 'chap3.xml'
448
- fallbackid = book.items[fallbackid].fallback
449
- expect(book.items[fallbackid].href).to eq 'chap3.xhtml'
450
- end
451
-
452
- it 'should handle fallback chain with fallback_chain_files' do
453
- # in this test, do not supply
454
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
455
- builder = GEPUB::Builder.new {
456
- resources(:workdir => workdir) {
457
- fallback_chain_files({'chap3_docbook.xml' => nil}, {'chap3.xml' => nil}, {'chap3.xhtml' => nil})
458
- }
459
- }
460
- book = builder.instance_eval { @book }
461
- fallbackid = book.item_by_href('chap3_docbook.xml').fallback
462
- expect(book.items[fallbackid].href).to eq 'chap3.xml'
463
- fallbackid = book.items[fallbackid].fallback
464
- expect(book.items[fallbackid].href).to eq 'chap3.xhtml'
465
- end
466
-
467
- it 'should handle fallback chain with fallback_chain_files in with_media_type' do
468
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
469
- builder = GEPUB::Builder.new {
470
- resources(:workdir => workdir) {
471
- with_media_type('application/docbook+xml', 'application/z3986-auth+xml', 'application/xhtml+xml') {
472
- fallback_chain_files({'chap3_docbook.xml' => nil}, {'chap3.xml' => nil}, {'chap3.xhtml' => nil})
473
- }
474
- }
475
- }
476
- book = builder.instance_eval { @book }
477
- expect(book.item_by_href('chap3_docbook.xml').media_type).to eq 'application/docbook+xml'
478
- fallbackid = book.item_by_href('chap3_docbook.xml').fallback
479
- expect(book.items[fallbackid].href).to eq 'chap3.xml'
480
- expect(book.items[fallbackid].media_type).to eq 'application/z3986-auth+xml'
481
-
482
- fallbackid = book.items[fallbackid].fallback
483
- expect(book.items[fallbackid].href).to eq 'chap3.xhtml'
484
- expect(book.items[fallbackid].media_type).to eq 'application/xhtml+xml'
485
- end
486
-
487
- it 'should handle fallback chain in spine' do
488
- workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
489
- builder = GEPUB::Builder.new {
490
- unique_identifier 'uid'
491
-
492
- resources(:workdir => workdir) {
493
- ordered {
494
- fallback_group {
495
- file 'chap3_docbook.xml' => nil
496
- media_type('application/docbook+xml')
497
- file 'chap3.xml' => nil
498
- media_type("application/z3986-auth+xml")
499
- file 'chap3.xhtml' => nil
500
- }
501
- }
502
- }
503
- }
504
- book = builder.instance_eval { @book }
505
- book.cleanup
506
- fallbackid = book.item_by_href('chap3_docbook.xml').fallback
507
- expect(book.items[fallbackid].href).to eq 'chap3.xml'
508
- fallbackid = book.items[fallbackid].fallback
509
- expect(book.items[fallbackid].href).to eq 'chap3.xhtml'
510
-
511
- expect(book.spine_items.size).to eq 1
512
- book.spine_items[0].href == 'chap3_docbook.xhtml'
513
- end
514
-
515
- it 'should create remote-resources' do
516
- builder = GEPUB::Builder.new {
517
- unique_identifier 'uid'
518
- resources {
519
- file 'with_remote.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head></head><body><div><p><video src="http://foo.bar">no video</video></p></div></body></html>')
520
- }
521
- }
522
- prop = builder.instance_eval {
523
- @book.item_by_href('with_remote.xhtml').properties[0]
524
- }
525
- expect(prop).to eq 'remote-resources'
526
- end
527
-
528
- it 'should handle remote resource URL' do
529
- GEPUB::Builder.new {
530
- unique_identifier 'uid'
531
- resources {
532
- file 'http://foo.bar'
533
- }
534
- }
535
- # this should not raise 'No such file or directory'
536
- end
537
-
538
- it 'should handle mathml' do
539
- builder = GEPUB::Builder.new {
540
- unique_identifier 'uid'
541
- resources {
542
- file 'mathml.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head></head><body><div><p><math xmlns="http://www.w3.org/1998/Math/MathML"></math></p></div></body></html>')
543
- }
544
- }
545
- prop = builder.instance_eval {
546
- @book.item_by_href('mathml.xhtml').properties[0]
547
- }
548
- expect(prop).to eq 'mathml'
549
- end
550
-
551
- it 'should handle svg' do
552
- builder = GEPUB::Builder.new {
553
- unique_identifier 'uid'
554
- resources {
555
- file 'svg.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head></head><body><div><p><svg xmlns="http://www.w3.org/2000/svg"></svg></p></div></body></html>')
556
- }
557
- }
558
- prop = builder.instance_eval {
559
- @book.item_by_href('svg.xhtml').properties[0]
560
- }
561
- expect(prop).to eq 'svg'
562
- end
563
-
564
- it 'should handle epub:switch' do
565
- builder = GEPUB::Builder.new {
566
- unique_identifier 'uid'
567
- resources {
568
- file 'switch.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head></head><body><div><p>
569
- <epub:switch>
570
- <epub:case required-namespace="http://www.xml-cml.org/schema">
571
- <cml xmlns="http://www.xml-cml.org/schema">
572
- <molecule id="sulfuric-acid">
573
- <formula id="f1" concise="H 2 S 1 O 4"/>
574
- </molecule>
575
- </cml>
576
- </epub:case>
577
- <epub:default>
578
- <p>H<sub>2</sub>SO<sub>4</sub></p>
579
- </epub:default>
580
- </epub:switch></p></div></body></html>')
581
- }
582
- }
583
- prop = builder.instance_eval {
584
- @book.item_by_href('switch.xhtml').properties[0]
585
- }
586
- expect(prop).to eq 'switch'
587
- end
588
-
589
- it 'should handle scripted property' do
590
- builder = GEPUB::Builder.new {
591
- unique_identifier 'uid'
592
- resources {
593
- file 'scripted.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head><script>alert("scripted");</script></head><body><div><p>text comes here</p></div></body></html>')
594
- }
595
- }
596
- expect(builder.instance_eval {
597
- @book.item_by_href('scripted.xhtml').properties[0]
598
- }).to eq 'scripted'
599
- end
600
-
601
- it 'should handle optional file' do
602
- builder = GEPUB::Builder.new {
603
- optional_file 'META-INF/test.xml' => StringIO.new('<test></test>')
604
- }
605
- expect(builder.instance_eval {
606
- @book.optional_files.size
607
- }).to eq 1
608
-
609
- expect(builder.instance_eval {
610
- @book.optional_files['META-INF/test.xml']
611
- }).not_to be_nil
612
- end
613
- end
614
- end