gepub 0.6.9.2 → 0.7.0beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +1 -1
- data/README.md +6 -2
- data/Rakefile +12 -0
- data/examples/new_book_example.rb +20 -0
- data/gepub.gemspec +2 -1
- data/lib/gepub/book.rb +13 -18
- data/lib/gepub/builder.rb +11 -6
- data/lib/gepub/datemeta.rb +3 -3
- data/lib/gepub/dsl_util.rb +11 -0
- data/lib/gepub/item.rb +3 -30
- data/lib/gepub/meta.rb +19 -5
- data/lib/gepub/metadata.rb +67 -20
- data/lib/gepub/mime.rb +49 -0
- data/lib/gepub/package.rb +35 -52
- data/lib/gepub/resource_builder.rb +2 -2
- data/lib/gepub/version.rb +1 -1
- data/lib/gepub.rb +3 -19
- data/spec/book_spec.rb +16 -15
- data/spec/builder_spec.rb +51 -37
- data/spec/example_spec.rb +9 -21
- data/spec/gepub_spec.rb +4 -23
- data/spec/metadata_spec.rb +18 -11
- data/spec/package_spec.rb +37 -37
- data/spec/spec_helper.rb +14 -7
- data/spec/spine_spec.rb +1 -1
- metadata +31 -14
data/lib/gepub/package.rb
CHANGED
@@ -5,7 +5,7 @@ require 'forwardable'
|
|
5
5
|
module GEPUB
|
6
6
|
# Holds data in opf file.
|
7
7
|
class Package
|
8
|
-
include XMLUtil
|
8
|
+
include XMLUtil, DSLUtil
|
9
9
|
extend Forwardable
|
10
10
|
attr_accessor :path, :metadata, :manifest, :spine, :bindings, :epub_backward_compat, :contents_prefix, :prefixes
|
11
11
|
def_delegators :@manifest, :item_by_href
|
@@ -15,6 +15,7 @@ module GEPUB
|
|
15
15
|
}.flatten
|
16
16
|
def_delegators :@metadata, :set_lastmodified
|
17
17
|
def_delegators :@metadata, :lastmodified
|
18
|
+
def_delegators :@metadata, :modified_now
|
18
19
|
def_delegators :@metadata, :rendition_layout
|
19
20
|
def_delegators :@metadata, :rendition_layout=
|
20
21
|
def_delegators :@metadata, :rendition_orientation
|
@@ -23,6 +24,8 @@ module GEPUB
|
|
23
24
|
def_delegators :@metadata, :rendition_spread=
|
24
25
|
def_delegators :@metadata, :ibooks_version
|
25
26
|
def_delegators :@metadata, :ibooks_version=
|
27
|
+
def_delegators :@metadata, :ibooks_scroll_axis
|
28
|
+
def_delegators :@metadata, :ibooks_scroll_axis=
|
26
29
|
|
27
30
|
def_delegators :@spine, :page_progression_direction=
|
28
31
|
def_delegators :@spine, :page_progression_direction
|
@@ -121,8 +124,17 @@ module GEPUB
|
|
121
124
|
|name|
|
122
125
|
methodbase = name.gsub('-','_').sub('xml:lang', 'lang')
|
123
126
|
define_method(methodbase + '=') { |val| @attributes[name] = val }
|
124
|
-
define_method('set_' + methodbase) { |val|
|
125
|
-
|
127
|
+
define_method('set_' + methodbase) { |val|
|
128
|
+
warn "set_#{methodbase} is obsolete. use #{methodbase} instead."
|
129
|
+
@attributes[name] = val
|
130
|
+
}
|
131
|
+
define_method(methodbase, ->(val=UNASSIGNED) {
|
132
|
+
if unassigned?(val)
|
133
|
+
@attributes[name]
|
134
|
+
else
|
135
|
+
send(methodbase + '=', val)
|
136
|
+
end
|
137
|
+
})
|
126
138
|
}
|
127
139
|
|
128
140
|
def [](x)
|
@@ -134,21 +146,20 @@ module GEPUB
|
|
134
146
|
end
|
135
147
|
|
136
148
|
|
137
|
-
def identifier
|
138
|
-
|
149
|
+
def identifier(identifier=UNASSIGNED)
|
150
|
+
if unassigned?(identifier)
|
151
|
+
@metadata.identifier_by_id(unique_identifier)
|
152
|
+
else
|
153
|
+
self.identifier=(identifier)
|
154
|
+
end
|
139
155
|
end
|
140
156
|
|
141
157
|
def identifier=(identifier)
|
142
|
-
|
158
|
+
primary_identifier(identifier, nil, nil)
|
143
159
|
end
|
144
160
|
|
145
|
-
def
|
146
|
-
|
147
|
-
set_primary_identifier(identifier, id, type)
|
148
|
-
end
|
149
|
-
|
150
|
-
def set_primary_identifier(identifier, id = nil, type = nil)
|
151
|
-
set_unique_identifier(id || @id_pool.generate_key(:prefix => 'BookId', :without_count => true))
|
161
|
+
def primary_identifier(identifier, id = nil, type = nil)
|
162
|
+
unique_identifier(id || @id_pool.generate_key(:prefix => 'BookId', :without_count => true))
|
152
163
|
@metadata.add_identifier identifier, unique_identifier, type
|
153
164
|
end
|
154
165
|
|
@@ -186,37 +197,19 @@ module GEPUB
|
|
186
197
|
@manifest.item_list
|
187
198
|
end
|
188
199
|
|
189
|
-
def
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
def specify_cover_image(item)
|
200
|
-
warn 'specify_cover_image is deprecated. please use Item#cover_image'
|
201
|
-
item.cover_image
|
202
|
-
end
|
203
|
-
|
204
|
-
def locale=(val)
|
205
|
-
warn 'locale= is deprecated. please use #language='
|
206
|
-
@metadata.language = val
|
207
|
-
end
|
208
|
-
|
209
|
-
def locale
|
210
|
-
warn '#locale is deprecated. please use #language'
|
211
|
-
@metadata.language
|
212
|
-
end
|
213
|
-
|
214
|
-
#TODO maybe it should be 'epub_version'
|
215
|
-
def version
|
216
|
-
@attributes['version']
|
200
|
+
def version(val=UNASSIGNED)
|
201
|
+
if unassigned?(val)
|
202
|
+
@attributes['version']
|
203
|
+
else
|
204
|
+
@attributes['version'] = val
|
205
|
+
@metadata.opf_version = val
|
206
|
+
@manifest.opf_version = val
|
207
|
+
@spine.opf_version = val
|
208
|
+
end
|
217
209
|
end
|
218
210
|
|
219
211
|
def set_version(val)
|
212
|
+
warn 'set_version is obsolete: use verion instead.'
|
220
213
|
@attributes['version'] = val
|
221
214
|
@metadata.opf_version = val
|
222
215
|
@manifest.opf_version = val
|
@@ -224,19 +217,9 @@ module GEPUB
|
|
224
217
|
end
|
225
218
|
|
226
219
|
def version=(val)
|
227
|
-
|
220
|
+
version(val)
|
228
221
|
end
|
229
222
|
|
230
|
-
def epub_version=(val)
|
231
|
-
warn 'epub_version= is deprecated. please use #version='
|
232
|
-
@attributes['version'] = val
|
233
|
-
end
|
234
|
-
|
235
|
-
def epub_version
|
236
|
-
warn 'epub_version is deprecated. please use #version'
|
237
|
-
version
|
238
|
-
end
|
239
|
-
|
240
223
|
def enable_rendition
|
241
224
|
@prefixes['rendition'] = 'http://www.idpf.org/vocab/rendition/#'
|
242
225
|
end
|
@@ -30,14 +30,14 @@ module GEPUB
|
|
30
30
|
@files_preprocess = {}
|
31
31
|
current_wd = Dir.getwd
|
32
32
|
Dir.chdir(attributes[:workdir]) unless attributes[:workdir].nil?
|
33
|
-
instance_eval
|
33
|
+
instance_eval(&block)
|
34
34
|
Dir.chdir current_wd
|
35
35
|
true
|
36
36
|
end
|
37
37
|
|
38
38
|
def ordered(&block)
|
39
39
|
@book.ordered {
|
40
|
-
instance_eval
|
40
|
+
instance_eval(&block)
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
data/lib/gepub/version.rb
CHANGED
data/lib/gepub.rb
CHANGED
@@ -1,23 +1,5 @@
|
|
1
|
-
if RUBY_VERSION < '1.9'
|
2
|
-
# hash.key
|
3
|
-
class Hash
|
4
|
-
def key(x)
|
5
|
-
index(x)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
class String
|
9
|
-
def force_to_bin
|
10
|
-
self
|
11
|
-
end
|
12
|
-
end
|
13
|
-
else
|
14
|
-
class String
|
15
|
-
def force_to_bin
|
16
|
-
force_encoding('us-ascii')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
1
|
require 'gepub/version'
|
2
|
+
require 'gepub/dsl_util'
|
21
3
|
require 'gepub/xml_util'
|
22
4
|
require 'gepub/meta'
|
23
5
|
require 'gepub/datemeta'
|
@@ -27,6 +9,7 @@ require 'gepub/manifest'
|
|
27
9
|
require 'gepub/spine'
|
28
10
|
require 'gepub/bindings'
|
29
11
|
require 'gepub/package'
|
12
|
+
require 'gepub/mime'
|
30
13
|
require 'gepub/item'
|
31
14
|
require 'gepub/book'
|
32
15
|
require 'gepub/builder_mixin'
|
@@ -37,3 +20,4 @@ require 'gepub/builder'
|
|
37
20
|
|
38
21
|
|
39
22
|
|
23
|
+
|
data/spec/book_spec.rb
CHANGED
@@ -29,30 +29,31 @@ describe GEPUB::Book do
|
|
29
29
|
describe 'version=' do
|
30
30
|
context 'overwrite version' do
|
31
31
|
it 'will hold new version' do
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
GEPUB::Book.new do |book|
|
33
|
+
book.version = '2.1'
|
34
|
+
expect(book.version).to eq('2.1')
|
35
|
+
end
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
38
39
|
describe 'identifer=' do
|
39
40
|
context 'set identifier' do
|
40
41
|
it 'will set unique-identifier and related attributes' do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
GEPUB::Book.new do |book|
|
43
|
+
book.identifier = 'the-book-identifier'
|
44
|
+
expect(book.identifier).to eq('the-book-identifier')
|
45
|
+
expect(book.identifier_list[0]['id']).to eq(book.unique_identifier)
|
46
|
+
expect(book.identifier_list[0].refiner('identifier-type')).to be_nil
|
47
|
+
end
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
|
-
describe '
|
51
|
+
describe 'primary_identifier' do
|
51
52
|
context 'set identifier with id and type' do
|
52
53
|
it 'will set unique-identifier and related attributes' do
|
53
|
-
book = GEPUB::Book.new
|
54
|
-
|
55
|
-
|
54
|
+
book = GEPUB::Book.new do
|
55
|
+
primary_identifier 'http//example.com/the-identifier', 'MyBookID', 'URL'
|
56
|
+
end
|
56
57
|
expect(book.identifier).to eq('http//example.com/the-identifier')
|
57
58
|
expect(book.unique_identifier).to eq('MyBookID')
|
58
59
|
expect(book.identifier_list[0]['id']).to eq('MyBookID')
|
@@ -230,12 +231,12 @@ describe GEPUB::Book do
|
|
230
231
|
it 'set current time' do
|
231
232
|
book = GEPUB::Book.new
|
232
233
|
now = Time.now
|
233
|
-
book.
|
234
|
+
book.modified_now
|
234
235
|
expect((book.lastmodified.content - now).abs).to be < 2
|
235
236
|
end
|
236
237
|
it 'set time in string' do
|
237
238
|
book = GEPUB::Book.new
|
238
|
-
book.
|
239
|
+
book.lastmodified(Time.parse('2012-9-12 00:00:00Z'))
|
239
240
|
expect(book.lastmodified.content).to eq(Time.parse('2012-9-12 00:00:00 UTC'))
|
240
241
|
end
|
241
242
|
end
|
data/spec/builder_spec.rb
CHANGED
@@ -402,12 +402,31 @@ describe GEPUB::Builder do
|
|
402
402
|
}
|
403
403
|
}
|
404
404
|
}
|
405
|
-
builder.instance_eval{
|
406
|
-
|
407
|
-
|
408
|
-
|
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
|
+
}
|
409
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'
|
410
428
|
end
|
429
|
+
|
411
430
|
it 'should handle fallback chain' do
|
412
431
|
workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
|
413
432
|
builder = GEPUB::Builder.new {
|
@@ -421,13 +440,13 @@ describe GEPUB::Builder do
|
|
421
440
|
}
|
422
441
|
}
|
423
442
|
}
|
424
|
-
builder.instance_eval {
|
425
|
-
|
426
|
-
@book.items[fallbackid].href.should == 'chap3.xml'
|
427
|
-
|
428
|
-
fallbackid = @book.items[fallbackid].fallback
|
429
|
-
@book.items[fallbackid].href.should == 'chap3.xhtml'
|
443
|
+
book = builder.instance_eval {
|
444
|
+
@book
|
430
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'
|
431
450
|
end
|
432
451
|
|
433
452
|
it 'should handle fallback chain with fallback_chain_files' do
|
@@ -438,13 +457,11 @@ describe GEPUB::Builder do
|
|
438
457
|
fallback_chain_files({'chap3_docbook.xml' => nil}, {'chap3.xml' => nil}, {'chap3.xhtml' => nil})
|
439
458
|
}
|
440
459
|
}
|
441
|
-
builder.instance_eval {
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
@book.items[fallbackid].href.should == 'chap3.xhtml'
|
447
|
-
}
|
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'
|
448
465
|
end
|
449
466
|
|
450
467
|
it 'should handle fallback chain with fallback_chain_files in with_media_type' do
|
@@ -456,16 +473,15 @@ describe GEPUB::Builder do
|
|
456
473
|
}
|
457
474
|
}
|
458
475
|
}
|
459
|
-
builder.instance_eval {
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
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'
|
464
481
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
}
|
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'
|
469
485
|
end
|
470
486
|
|
471
487
|
it 'should handle fallback chain in spine' do
|
@@ -485,17 +501,15 @@ describe GEPUB::Builder do
|
|
485
501
|
}
|
486
502
|
}
|
487
503
|
}
|
488
|
-
builder.instance_eval {
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
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'
|
494
510
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
}
|
511
|
+
expect(book.spine_items.size).to eq 1
|
512
|
+
book.spine_items[0].href == 'chap3_docbook.xhtml'
|
499
513
|
end
|
500
514
|
|
501
515
|
it 'should create remote-resources' do
|
@@ -511,7 +525,7 @@ describe GEPUB::Builder do
|
|
511
525
|
end
|
512
526
|
|
513
527
|
it 'should handle remote resource URL' do
|
514
|
-
|
528
|
+
GEPUB::Builder.new {
|
515
529
|
unique_identifier 'uid'
|
516
530
|
resources {
|
517
531
|
file 'http://foo.bar'
|
data/spec/example_spec.rb
CHANGED
@@ -35,11 +35,7 @@ describe 'GEPUB usage' do
|
|
35
35
|
}
|
36
36
|
epubname = File.join(File.dirname(__FILE__), 'example_test_with_builder_buffer.epub')
|
37
37
|
File.open(epubname, 'wb') { |io| io.write builder.generate_epub_stream.string }
|
38
|
-
|
39
|
-
@stdout = capture(:stdout) do
|
40
|
-
puts %x(java -jar #{jar} #{epubname})
|
41
|
-
end
|
42
|
-
expect(@stdout).to include("No errors or warnings detected.")
|
38
|
+
epubcheck(epubname)
|
43
39
|
end
|
44
40
|
|
45
41
|
it 'should generate simple EPUB3 with Builder' do
|
@@ -70,16 +66,12 @@ describe 'GEPUB usage' do
|
|
70
66
|
}
|
71
67
|
epubname = File.join(File.dirname(__FILE__), 'example_test_with_builder.epub')
|
72
68
|
builder.generate_epub(epubname)
|
73
|
-
|
74
|
-
@stdout = capture(:stdout) do
|
75
|
-
puts %x(java -jar #{jar} #{epubname})
|
76
|
-
end
|
77
|
-
expect(@stdout).to include("No errors or warnings detected.")
|
69
|
+
epubcheck(epubname)
|
78
70
|
end
|
79
71
|
|
80
72
|
it 'should generate simple EPUB3 with rather complicated matadata' do
|
81
73
|
book = GEPUB::Book.new
|
82
|
-
book.
|
74
|
+
book.primary_identifier('http:/example.jp/bookid_in_url', 'BookID', 'URL')
|
83
75
|
book.language = 'ja'
|
84
76
|
|
85
77
|
# you can add metadata and its property using block
|
@@ -94,16 +86,16 @@ describe 'GEPUB usage' do
|
|
94
86
|
'th' => 'GEPUB ตัวอย่าง (ญี่ปุ่น)')
|
95
87
|
}
|
96
88
|
# you can do the same thing using method chain
|
97
|
-
book.add_title('これはあくまでサンプルです',nil, GEPUB::TITLE_TYPE::SUBTITLE).
|
89
|
+
book.add_title('これはあくまでサンプルです',nil, GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'this book is just a sample.')
|
98
90
|
book.add_creator('小嶋智') {
|
99
91
|
|creator|
|
100
92
|
creator.display_seq = 1
|
101
93
|
creator.add_alternates('en' => 'KOJIMA Satoshi')
|
102
94
|
}
|
103
|
-
book.add_contributor('電書部').
|
104
|
-
book.add_contributor('アサガヤデンショ').
|
105
|
-
book.add_contributor('湘南電書鼎談').
|
106
|
-
book.add_contributor('電子雑誌トルタル').
|
95
|
+
book.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
|
96
|
+
book.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
|
97
|
+
book.add_contributor('湘南電書鼎談').display_seq(3).add_alternates('en' => 'Shonan Densho Teidan')
|
98
|
+
book.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru')
|
107
99
|
|
108
100
|
imgfile = File.join(File.dirname(__FILE__), 'fixtures', 'testdata', 'image1.jpg')
|
109
101
|
book.add_item('img/image1.jpg',imgfile).cover_image
|
@@ -116,11 +108,7 @@ describe 'GEPUB usage' do
|
|
116
108
|
}
|
117
109
|
epubname = File.join(File.dirname(__FILE__), 'example_test.epub')
|
118
110
|
book.generate_epub(epubname)
|
119
|
-
|
120
|
-
@stdout = capture(:stdout) do
|
121
|
-
puts %x(java -jar #{jar} #{epubname})
|
122
|
-
end
|
123
|
-
expect(@stdout).to include("No errors or warnings detected.")
|
111
|
+
epubcheck(epubname)
|
124
112
|
end
|
125
113
|
end
|
126
114
|
end
|
data/spec/gepub_spec.rb
CHANGED
@@ -168,12 +168,7 @@ EOF
|
|
168
168
|
it "should generate correct epub" do
|
169
169
|
epubname = File.join(File.dirname(__FILE__), 'testepub.epub')
|
170
170
|
@book.generate_epub(epubname)
|
171
|
-
|
172
|
-
@stdout = capture(:stdout) do
|
173
|
-
puts %x(java -jar #{jar} #{epubname})
|
174
|
-
end
|
175
|
-
expect(@stdout).to include("No errors or warnings detected.")
|
176
|
-
|
171
|
+
epubcheck(epubname)
|
177
172
|
end
|
178
173
|
it "should generate correct epub with buffer" do
|
179
174
|
epubname = File.join(File.dirname(__FILE__), 'testepub_buf.epub')
|
@@ -181,12 +176,7 @@ EOF
|
|
181
176
|
|io|
|
182
177
|
io.write @book.generate_epub_stream.string
|
183
178
|
}
|
184
|
-
|
185
|
-
@stdout = capture(:stdout) do
|
186
|
-
puts %x(java -jar #{jar} #{epubname})
|
187
|
-
end
|
188
|
-
expect(@stdout).to include("No errors or warnings detected.")
|
189
|
-
|
179
|
+
epubcheck(epubname)
|
190
180
|
end
|
191
181
|
|
192
182
|
it "should generate correct epub2.0" do
|
@@ -207,21 +197,12 @@ EOF
|
|
207
197
|
'c2')
|
208
198
|
item2.toc_text 'test chapter'
|
209
199
|
@book.generate_epub(epubname)
|
210
|
-
|
211
|
-
@stdout = capture(:stdout) do
|
212
|
-
puts %x(java -jar #{jar} #{epubname})
|
213
|
-
end
|
214
|
-
expect(@stdout).to include("No errors or warnings detected.")
|
215
|
-
|
200
|
+
epubcheck(epubname)
|
216
201
|
end
|
217
202
|
it 'should generate epub with extra file' do
|
218
203
|
epubname = File.join(File.dirname(__FILE__), 'testepub3.epub')
|
219
204
|
@book.add_optional_file('META-INF/foobar.xml', StringIO.new('<foo></foo>'))
|
220
205
|
@book.generate_epub(epubname)
|
221
|
-
|
222
|
-
@stdout = capture(:stdout) do
|
223
|
-
puts %x(java -jar #{jar} #{epubname})
|
224
|
-
end
|
225
|
-
expect(@stdout).to include("No errors or warnings detected.")
|
206
|
+
epubcheck(epubname)
|
226
207
|
end
|
227
208
|
end
|
data/spec/metadata_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
p# -*- coding: utf-8 -*-
|
3
2
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
4
3
|
require 'rubygems'
|
5
4
|
require 'nokogiri'
|
@@ -49,9 +48,9 @@ describe GEPUB::Metadata do
|
|
49
48
|
|
50
49
|
it 'should parse OPF2.0 meta node' do
|
51
50
|
expect(@metadata.oldstyle_meta.size).to eq(1)
|
52
|
-
@metadata.oldstyle_meta[0].name
|
53
|
-
@metadata.oldstyle_meta[0]['name']
|
54
|
-
@metadata.oldstyle_meta[0]['content']
|
51
|
+
expect(@metadata.oldstyle_meta[0].name).to eq 'meta'
|
52
|
+
expect(@metadata.oldstyle_meta[0]['name']).to eq 'cover'
|
53
|
+
expect(@metadata.oldstyle_meta[0]['content']).to eq 'cover-image'
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
@@ -65,9 +64,9 @@ describe GEPUB::Metadata do
|
|
65
64
|
end
|
66
65
|
it 'should parse OPF2.0 meta node' do
|
67
66
|
expect(@metadata.oldstyle_meta.size).to eq(1)
|
68
|
-
@metadata.oldstyle_meta[0].name
|
69
|
-
@metadata.oldstyle_meta[0]['name']
|
70
|
-
@metadata.oldstyle_meta[0]['content']
|
67
|
+
expect(@metadata.oldstyle_meta[0].name).to eq 'meta'
|
68
|
+
expect(@metadata.oldstyle_meta[0]['name']).to eq 'cover'
|
69
|
+
expect(@metadata.oldstyle_meta[0]['content']).to eq 'cover-image'
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
@@ -103,7 +102,7 @@ describe GEPUB::Metadata do
|
|
103
102
|
it 'should write and read multipletitle with type' do
|
104
103
|
metadata = GEPUB::Metadata.new
|
105
104
|
metadata.add_title('The Main Title', 'maintitle', GEPUB::TITLE_TYPE::MAIN)
|
106
|
-
metadata.add_title('The Book Series', 'series', GEPUB::TITLE_TYPE::COLLECTION).
|
105
|
+
metadata.add_title('The Book Series', 'series', GEPUB::TITLE_TYPE::COLLECTION).group_position(1)
|
107
106
|
expect(metadata.title.to_s).to eq('The Main Title')
|
108
107
|
expect(metadata.title.title_type.to_s).to eq('main')
|
109
108
|
|
@@ -114,7 +113,7 @@ describe GEPUB::Metadata do
|
|
114
113
|
|
115
114
|
it 'should handle alternate-script metadata of creator, not using method chain' do
|
116
115
|
metadata = GEPUB::Metadata.new
|
117
|
-
metadata.add_creator('TheCreator', 'author', 'aut').
|
116
|
+
metadata.add_creator('TheCreator', 'author', 'aut').display_seq(1).file_as('Creator, The').add_alternates({ 'ja-JP' => '作成者' })
|
118
117
|
expect(metadata.creator.to_s).to eq('TheCreator')
|
119
118
|
expect(metadata.creator.to_s('ja')).to eq('作成者')
|
120
119
|
end
|
@@ -154,6 +153,14 @@ describe GEPUB::Metadata do
|
|
154
153
|
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
|
155
154
|
end
|
156
155
|
|
156
|
+
it 'should handle date with Time object by content = ' do
|
157
|
+
metadata = GEPUB::Metadata.new
|
158
|
+
a = Time.parse '2012-02-27 20:00:00 UTC'
|
159
|
+
metadata.add_date('2011-01-01', 'date')
|
160
|
+
metadata.date.content = a
|
161
|
+
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
|
162
|
+
end
|
163
|
+
|
157
164
|
it 'should handle date with a not W3C-DTF string' do
|
158
165
|
metadata = GEPUB::Metadata.new
|
159
166
|
metadata.add_date('2012-02-28 05:00:00 +0900', 'date')
|
@@ -173,7 +180,7 @@ describe GEPUB::Metadata do
|
|
173
180
|
|
174
181
|
it 'should generate metadata with creator refiner' do
|
175
182
|
metadata = GEPUB::Metadata.new
|
176
|
-
metadata.add_creator('TheCreator', nil, 'aut').
|
183
|
+
metadata.add_creator('TheCreator', nil, 'aut').display_seq(1).file_as('Creator, The').add_alternates({ 'ja-JP' => '作成者' })
|
177
184
|
builder = Nokogiri::XML::Builder.new { |xml|
|
178
185
|
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
179
186
|
metadata.to_xml(xml)
|
@@ -191,7 +198,7 @@ describe GEPUB::Metadata do
|
|
191
198
|
|
192
199
|
it 'should generate metadata with old style meta tag' do
|
193
200
|
metadata = GEPUB::Metadata.new
|
194
|
-
metadata.add_creator('TheCreator', nil, 'aut').
|
201
|
+
metadata.add_creator('TheCreator', nil, 'aut').display_seq(1).file_as('Creator, The').add_alternates({ 'ja-JP' => '作成者' })
|
195
202
|
metadata.add_oldstyle_meta(nil, { 'name' => 'cover', 'content' => 'cover.jpg' })
|
196
203
|
builder = Nokogiri::XML::Builder.new { |xml|
|
197
204
|
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|