gepub 1.0.2 → 1.0.3
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/README.md +3 -3
- data/gepub.gemspec +1 -2
- data/lib/gepub/version.rb +1 -1
- metadata +4 -110
- data/spec/bindings_spec.rb +0 -34
- data/spec/book_spec.rb +0 -307
- data/spec/builder_spec.rb +0 -614
- data/spec/example_spec.rb +0 -192
- data/spec/fixtures/builder/img/cover.jpg +0 -0
- data/spec/fixtures/builder/resources/noise.m4 +0 -0
- data/spec/fixtures/builder/resources/noise_2.m4a +0 -0
- data/spec/fixtures/builder/text/cover.xhtml +0 -11
- data/spec/fixtures/builder/text/localresource.conf +0 -2
- data/spec/fixtures/builder/text/memo.txt +0 -1
- data/spec/fixtures/builder/text/nav.xhtml +0 -12
- data/spec/fixtures/epubcheck-4.1.1/CHANGELOG.txt +0 -92
- data/spec/fixtures/epubcheck-4.1.1/LICENSE.txt +0 -28
- data/spec/fixtures/epubcheck-4.1.1/README.txt +0 -101
- data/spec/fixtures/epubcheck-4.1.1/THIRD-PARTY.txt +0 -60
- data/spec/fixtures/epubcheck-4.1.1/epubcheck.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/Saxon-HE-9.8.0-8.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/animal-sniffer-annotations-1.14.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/checker-compat-qual-2.0.0.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/common-image-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/common-io-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/common-lang-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/commons-compress-1.18.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/error_prone_annotations-2.1.3.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/guava-24.0-android.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/imageio-core-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/imageio-jpeg-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/imageio-metadata-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/j2objc-annotations-1.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jackson-core-asl-1.9.12.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jackson-mapper-asl-1.9.12.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jing-20120724.0.0.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jsr305-1.3.9.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/sac-1.3.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/licenses/Apache-2.0.txt +0 -201
- data/spec/fixtures/epubcheck-4.1.1/licenses/BSD-3-Clause.txt +0 -27
- data/spec/fixtures/epubcheck-4.1.1/licenses/MPL-1.0.txt +0 -360
- data/spec/fixtures/epubcheck-4.1.1/licenses/W3C.txt +0 -16
- data/spec/fixtures/testdata/0.html +0 -12
- data/spec/fixtures/testdata/1.html +0 -10
- data/spec/fixtures/testdata/image1.jpg +0 -0
- data/spec/fixtures/testdata/package_2_0.opf +0 -23
- data/spec/fixtures/testdata/test.opf +0 -69
- data/spec/fixtures/testdata/test2.opf +0 -63
- data/spec/fixtures/testdata/test_with_bindings.opf +0 -67
- data/spec/fixtures/testdata/wasteland-20120118.epub +0 -0
- data/spec/gepub_deprectad_api_spec.rb +0 -229
- data/spec/gepub_spec.rb +0 -229
- data/spec/manifest_spec.rb +0 -36
- data/spec/metadata_spec.rb +0 -219
- data/spec/package_spec.rb +0 -150
- data/spec/spec_helper.rb +0 -57
- data/spec/spine_spec.rb +0 -55
data/spec/gepub_spec.rb
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
describe GEPUB::Item do
|
7
|
-
it "should return atttributes" do
|
8
|
-
item = GEPUB::Item.new('theid', 'foo/bar.bar', 'application/xhtml+xml')
|
9
|
-
expect(item.itemid).to eq('theid')
|
10
|
-
expect(item.href).to eq('foo/bar.bar')
|
11
|
-
expect(item.mediatype).to eq('application/xhtml+xml')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should handle html" do
|
15
|
-
item = GEPUB::Item.new('id', 'text/foo.html')
|
16
|
-
expect(item.mediatype).to eq('application/xhtml+xml')
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should handle xhtml" do
|
20
|
-
item = GEPUB::Item.new('id', 'text/foo.xhtml')
|
21
|
-
expect(item.mediatype).to eq('application/xhtml+xml')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should handle JPG" do
|
25
|
-
item = GEPUB::Item.new('id', 'img/foo.JPG')
|
26
|
-
expect(item.mediatype).to eq('image/jpeg')
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should handle css" do
|
30
|
-
item = GEPUB::Item.new('id', 'img/foo.css')
|
31
|
-
expect(item.mediatype).to eq('text/css')
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should handle javascript" do
|
35
|
-
item = GEPUB::Item.new('id', 'js/jQuery.js')
|
36
|
-
expect(item.mediatype).to eq('text/javascript')
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
describe GEPUB::Book do
|
42
|
-
before do
|
43
|
-
@book = GEPUB::Book.new('OEPBS/package.opf')
|
44
|
-
@book.title = 'thetitle'
|
45
|
-
@book.creator = "theauthor"
|
46
|
-
@book.contributor = "contributors contributors!"
|
47
|
-
@book.publisher = "thepublisher"
|
48
|
-
@book.date = "2010-05-05"
|
49
|
-
@book.identifier = "http://example.jp/foobar/"
|
50
|
-
@book.language = 'ja'
|
51
|
-
item1 = @book.add_item('text/foobar.xhtml',nil, id: 'c1', content: StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>'))
|
52
|
-
@book.spine.push(item1)
|
53
|
-
|
54
|
-
item2 = @book.add_ordered_item('text/barbar.xhtml',
|
55
|
-
content: StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>second page, whith is test chapter.</p></body></html>'),
|
56
|
-
id: 'c2',
|
57
|
-
toc_text: 'test chapter')
|
58
|
-
|
59
|
-
item3 = @book.add_item('text/handler.xhtml',
|
60
|
-
content: StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title><script>alert("foo");</script></head><body><p>this is scripted item</p></body></html>')
|
61
|
-
)
|
62
|
-
item3.add_property('scripted')
|
63
|
-
item3.is_handler_of('application/x-some-media-type')
|
64
|
-
@item3_id = item3.id
|
65
|
-
|
66
|
-
nav_string = <<EOF
|
67
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
68
|
-
<head></head>
|
69
|
-
<body>
|
70
|
-
<nav epub:type="toc" id="toc">
|
71
|
-
<h1>Table of contents</h1>
|
72
|
-
<ol>
|
73
|
-
<li><a href="foobar.xhtml">Chapter 1</a> </li>
|
74
|
-
<li> <a href="barbar.xhtml">Chapter 2</a></li>
|
75
|
-
</ol>
|
76
|
-
</nav>
|
77
|
-
</body>
|
78
|
-
</html>
|
79
|
-
EOF
|
80
|
-
item3 = @book.add_ordered_item('text/nav.xhtml', content: StringIO.new(nav_string), id: 'nav').add_property('nav')
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should have title" do
|
84
|
-
expect(@book.title.to_s).to eq('thetitle')
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should generate correct ncx" do
|
88
|
-
ncx = Nokogiri::XML.parse(@book.ncx_xml).root
|
89
|
-
expect(ncx.name).to eq('ncx')
|
90
|
-
expect(ncx.attributes['version'].value).to eq('2005-1')
|
91
|
-
ncx.namespaces['xmlns'] == 'http://www.daisy.org/z3986/2005/ncx/'
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should have correct head in ncx" do
|
95
|
-
head = Nokogiri::XML.parse(@book.ncx_xml).at_xpath('/xmlns:ncx/xmlns:head')
|
96
|
-
expect(head).not_to be_nil
|
97
|
-
expect(head.at_xpath("xmlns:meta[@name='dtb:uid']")['content']).to eq("http://example.jp/foobar/")
|
98
|
-
expect(head.xpath("xmlns:meta[@name='dtb:depth']").size).to be > 0
|
99
|
-
expect(head.xpath("xmlns:meta[@name='dtb:totalPageCount']").size).to be > 0
|
100
|
-
expect(head.xpath("xmlns:meta[@name='dtb:maxPageNumber']").size).to be > 0
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should have correct ncx doctitle" do
|
104
|
-
doctitle = Nokogiri::XML.parse(@book.ncx_xml).root
|
105
|
-
|
106
|
-
expect(doctitle.xpath('xmlns:docTitle').size).to be > 0
|
107
|
-
expect(doctitle.at_xpath('xmlns:docTitle/xmlns:text').text).to eq('thetitle')
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should correct ncx navmap" do
|
111
|
-
ncx = Nokogiri::XML::parse(@book.ncx_xml).root
|
112
|
-
|
113
|
-
expect(ncx.xpath('xmlns:navMap').size).to be > 0
|
114
|
-
nav_point = ncx.at_xpath('xmlns:navMap/xmlns:navPoint')
|
115
|
-
expect(nav_point['id']).to eq('c2_')
|
116
|
-
expect(nav_point['playOrder']).to eq('1')
|
117
|
-
|
118
|
-
expect(nav_point.at_xpath('xmlns:navLabel/xmlns:text').content).to eq('test chapter')
|
119
|
-
nav_point.at_xpath('xmlns:content')['src'] == 'foobar2.html'
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should create correct opf" do
|
124
|
-
opf = Nokogiri::XML.parse(@book.opf_xml).root
|
125
|
-
expect(opf.name).to eq('package')
|
126
|
-
expect(opf.namespaces['xmlns']).to eq('http://www.idpf.org/2007/opf')
|
127
|
-
expect(opf['version']).to eq('3.0')
|
128
|
-
expect(opf['unique-identifier']).to eq('BookId')
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should have correct metadata in opf" do
|
132
|
-
opf = Nokogiri::XML.parse(@book.opf_xml).root
|
133
|
-
metadata = opf.xpath('xmlns:metadata').first
|
134
|
-
expect(metadata.at_xpath('dc:language', metadata.namespaces).content).to eq('ja')
|
135
|
-
#TODO: check metadata
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should have correct manifest and spine in opf" do
|
139
|
-
opf = Nokogiri::XML.parse(@book.opf_xml).root
|
140
|
-
|
141
|
-
manifest = opf.at_xpath('xmlns:manifest')
|
142
|
-
expect(manifest.at_xpath('xmlns:item[@id="c1"]')['href']).to eq('text/foobar.xhtml')
|
143
|
-
expect(manifest.at_xpath('xmlns:item[@id="c1"]')['media-type']).to eq('application/xhtml+xml')
|
144
|
-
|
145
|
-
spine = opf.at_xpath('xmlns:spine')
|
146
|
-
expect(spine['toc']).to eq('ncx')
|
147
|
-
expect(spine.at_xpath('xmlns:itemref')['idref']).to eq('c1')
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should have correct bindings in opf" do
|
151
|
-
opf = Nokogiri::XML.parse(@book.opf_xml).root
|
152
|
-
bindings = opf.at_xpath('xmlns:bindings')
|
153
|
-
expect(bindings.at_xpath('xmlns:mediaType')['handler']).to eq(@item3_id)
|
154
|
-
expect(bindings.at_xpath('xmlns:mediaType')['media-type']).to eq('application/x-some-media-type')
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should have correct cover image id" do
|
158
|
-
item = @book.add_item("img/img.jpg").cover_image
|
159
|
-
|
160
|
-
opf = Nokogiri::XML.parse(@book.opf_xml).root
|
161
|
-
|
162
|
-
metadata = opf.at_xpath('xmlns:metadata')
|
163
|
-
meta = metadata.at_xpath("xmlns:meta[@name='cover']")
|
164
|
-
expect(meta['content']).to eq(item.itemid)
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should generate correct epub" do
|
168
|
-
epubname = File.join(File.dirname(__FILE__), 'testepub.epub')
|
169
|
-
@book.generate_epub(epubname)
|
170
|
-
epubcheck(epubname)
|
171
|
-
end
|
172
|
-
it "should generate correct epub with buffer" do
|
173
|
-
epubname = File.join(File.dirname(__FILE__), 'testepub_buf.epub')
|
174
|
-
File.open(epubname, 'wb') {
|
175
|
-
|io|
|
176
|
-
io.write @book.generate_epub_stream.string
|
177
|
-
}
|
178
|
-
epubcheck(epubname)
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should generate correct epub2.0" do
|
182
|
-
epubname = File.join(File.dirname(__FILE__), 'testepub2.epub')
|
183
|
-
@book = GEPUB::Book.new('OEPBS/package.opf', { 'version' => '2.0'} )
|
184
|
-
@book.title = 'thetitle'
|
185
|
-
@book.creator = "theauthor"
|
186
|
-
@book.contributor = "contributors contributors!"
|
187
|
-
@book.publisher = "thepublisher"
|
188
|
-
@book.date = "2010-05-05"
|
189
|
-
@book.identifier = "http://example.jp/foobar/"
|
190
|
-
@book.language = 'ja'
|
191
|
-
item1 = @book.add_item('text/foobar.xhtml',id: 'c1')
|
192
|
-
item1.add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>'))
|
193
|
-
@book.spine.push(item1)
|
194
|
-
item2 = @book.add_ordered_item('text/barbar.xhtml',
|
195
|
-
content: StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>second page, whith is test chapter.</p></body></html>'),
|
196
|
-
id: 'c2')
|
197
|
-
item2.toc_text 'test chapter'
|
198
|
-
@book.generate_epub(epubname)
|
199
|
-
epubcheck(epubname)
|
200
|
-
end
|
201
|
-
it 'should generate epub with extra file' do
|
202
|
-
epubname = File.join(File.dirname(__FILE__), 'testepub3.epub')
|
203
|
-
@book.add_optional_file('META-INF/foobar.xml', StringIO.new('<foo></foo>'))
|
204
|
-
@book.generate_epub(epubname)
|
205
|
-
epubcheck(epubname)
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'should generate valid EPUB when @toc is empty' do
|
209
|
-
epubname = File.join(File.dirname(__FILE__), 'testepub4.epub')
|
210
|
-
@book = GEPUB::Book.new('OEPBS/package.opf', { 'version' => '3.0'} )
|
211
|
-
@book.title = 'thetitle'
|
212
|
-
@book.creator = "theauthor"
|
213
|
-
@book.contributor = "contributors contributors!"
|
214
|
-
@book.publisher = "thepublisher"
|
215
|
-
@book.date = "2015-05-05"
|
216
|
-
@book.identifier = "http://example.jp/foobar/"
|
217
|
-
@book.language = 'ja'
|
218
|
-
item1 = @book.add_item('text/foobar.xhtml',id: 'c1')
|
219
|
-
item1.add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>'))
|
220
|
-
@book.spine.push(item1)
|
221
|
-
item2 = @book.add_ordered_item('text/barbar.xhtml',
|
222
|
-
content: StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>second page, whith is test chapter.</p></body></html>'),
|
223
|
-
id: 'c2')
|
224
|
-
@book.spine.push(item2)
|
225
|
-
@book.generate_epub(epubname)
|
226
|
-
epubcheck(epubname)
|
227
|
-
|
228
|
-
end
|
229
|
-
end
|
data/spec/manifest_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
describe GEPUB::Manifest do
|
7
|
-
context 'parse existing opf' do
|
8
|
-
before do
|
9
|
-
@manifest = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf').instance_eval{ @manifest }
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should be parsed' do
|
13
|
-
expect(@manifest.item_list.size).to eq(9)
|
14
|
-
expect(@manifest.item_list['ncx'].href).to eq('toc.ncx')
|
15
|
-
expect(@manifest.item_list['ncx'].media_type).to eq('application/x-dtbncx+xml')
|
16
|
-
expect(@manifest.item_list['cover'].href).to eq('cover/cover.xhtml')
|
17
|
-
expect(@manifest.item_list['cover'].media_type).to eq('application/xhtml+xml')
|
18
|
-
expect(@manifest.item_list['cover-image'].href).to eq('img/cover.jpg')
|
19
|
-
expect(@manifest.item_list['cover-image'].media_type).to eq('image/jpeg')
|
20
|
-
expect(@manifest.item_list['cover-image'].properties[0]).to eq('cover-image')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
context 'generate new opf' do
|
24
|
-
it 'should generate xml' do
|
25
|
-
manifest = GEPUB::Manifest.new
|
26
|
-
manifest.add_item('ncx', 'toc.ncx', 'application/x-dtbncx+xml')
|
27
|
-
builder = Nokogiri::XML::Builder.new { |xml|
|
28
|
-
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
29
|
-
manifest.to_xml(xml)
|
30
|
-
}
|
31
|
-
}
|
32
|
-
xml = Nokogiri::XML::Document.parse(builder.to_xml)
|
33
|
-
expect(xml.xpath("//xmlns:item[@id='ncx' and @href='toc.ncx' and @media-type='application/x-dtbncx+xml']").size).to eq(1)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/metadata_spec.rb
DELETED
@@ -1,219 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
describe GEPUB::Metadata do
|
7
|
-
it 'should be initialized' do
|
8
|
-
metadata = GEPUB::Metadata.new
|
9
|
-
expect(metadata.ns_prefix(GEPUB::XMLUtil::DC_NS)).to eq('dc')
|
10
|
-
expect(metadata.ns_prefix(GEPUB::XMLUtil::OPF_NS)).to be_nil
|
11
|
-
end
|
12
|
-
it 'should be initialized with version 2.0' do
|
13
|
-
metadata = GEPUB::Metadata.new('2.0')
|
14
|
-
expect(metadata.ns_prefix(GEPUB::XMLUtil::DC_NS)).to eq('dc')
|
15
|
-
expect(metadata.ns_prefix(GEPUB::XMLUtil::OPF_NS)).to eq('opf')
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'Parse Existing OPF' do
|
19
|
-
before do
|
20
|
-
@metadata = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf').instance_eval{ @metadata }
|
21
|
-
end
|
22
|
-
it 'should parse title' do
|
23
|
-
expect(@metadata.main_title).to eq('TheTitle')
|
24
|
-
expect(@metadata.title_list.size).to eq(2)
|
25
|
-
expect(@metadata.title.to_s).to eq('TheTitle')
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should parse main title with not first display-seq' do
|
29
|
-
metadata = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test2.opf'), '/package.opf').instance_eval{ @metadata }
|
30
|
-
expect(metadata.title.to_s).to eq('TheTitle')
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should parse title-type' do
|
34
|
-
expect(@metadata.title_list[0].refiner_list('title-type').size).to eq(1)
|
35
|
-
expect(@metadata.title_list[0].refiner_list('title-type')[0].content).to eq('main')
|
36
|
-
expect(@metadata.title_list[1].refiner_list('title-type').size).to eq(1)
|
37
|
-
expect(@metadata.title_list[1].refiner_list('title-type')[0].content).to eq('collection')
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should parse identifier' do
|
41
|
-
expect(@metadata.identifier_list.size).to eq(2)
|
42
|
-
expect(@metadata.identifier.to_s).to eq('urn:uuid:1234567890')
|
43
|
-
expect(@metadata.identifier_list[0].content).to eq('urn:uuid:1234567890')
|
44
|
-
expect(@metadata.identifier_list[0].refiner('identifier-type').to_s).to eq('uuid')
|
45
|
-
expect(@metadata.identifier_list[1].content).to eq('http://example.jp/epub/test/url')
|
46
|
-
expect(@metadata.identifier_list[1].refiner('identifier-type').to_s).to eq('uri')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should parse OPF2.0 meta node' do
|
50
|
-
expect(@metadata.oldstyle_meta.size).to eq(1)
|
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'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'Should parse OPF2.0' do
|
58
|
-
before do
|
59
|
-
@metadata = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/package_2_0.opf'), '/package.opf').instance_eval{ @metadata }
|
60
|
-
end
|
61
|
-
it 'should parse title' do
|
62
|
-
expect(@metadata.main_title).to eq('thetitle')
|
63
|
-
expect(@metadata.title_list.size).to eq(1)
|
64
|
-
end
|
65
|
-
it 'should parse OPF2.0 meta node' do
|
66
|
-
expect(@metadata.oldstyle_meta.size).to eq(1)
|
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'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'Generate New OPF' do
|
74
|
-
it 'should write and read identifier' do
|
75
|
-
metadata = GEPUB::Metadata.new
|
76
|
-
metadata.add_identifier 'the_set_identifier', 'pub-id'
|
77
|
-
expect(metadata.identifier.to_s).to eq('the_set_identifier')
|
78
|
-
expect(metadata.identifier_list[0]['id']).to eq('pub-id')
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should write and read identifier with identifier-type' do
|
82
|
-
metadata = GEPUB::Metadata.new
|
83
|
-
metadata.add_identifier 'http://example.jp/book/url', 'pub-id', 'uri'
|
84
|
-
expect(metadata.identifier.to_s).to eq('http://example.jp/book/url')
|
85
|
-
expect(metadata.identifier_list[0]['id']).to eq('pub-id')
|
86
|
-
expect(metadata.identifier_list[0].identifier_type.to_s).to eq('uri')
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should write and read title' do
|
90
|
-
metadata = GEPUB::Metadata.new
|
91
|
-
metadata.add_title('The Main Title')
|
92
|
-
expect(metadata.title.to_s).to eq('The Main Title')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should write and read title with type' do
|
96
|
-
metadata = GEPUB::Metadata.new
|
97
|
-
metadata.add_title('The Main Title', id: 'maintitle', title_type: GEPUB::TITLE_TYPE::MAIN)
|
98
|
-
expect(metadata.title.to_s).to eq('The Main Title')
|
99
|
-
expect(metadata.title.title_type.to_s).to eq('main')
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should write and read multipletitle with type' do
|
103
|
-
metadata = GEPUB::Metadata.new
|
104
|
-
metadata.add_title('The Main Title', id: 'maintitle', title_type: GEPUB::TITLE_TYPE::MAIN)
|
105
|
-
metadata.add_title('The Book Series', id: 'series', title_type: GEPUB::TITLE_TYPE::COLLECTION).group_position(1)
|
106
|
-
expect(metadata.title.to_s).to eq('The Main Title')
|
107
|
-
expect(metadata.title.title_type.to_s).to eq('main')
|
108
|
-
|
109
|
-
expect(metadata.title_list[1].to_s).to eq('The Book Series')
|
110
|
-
expect(metadata.title_list[1].title_type.to_s).to eq('collection')
|
111
|
-
expect(metadata.title_list[1].group_position.to_s).to eq('1')
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'should handle alternate-script metadata of creator, not using method chain' do
|
115
|
-
metadata = GEPUB::Metadata.new
|
116
|
-
metadata.add_creator('TheCreator', id: 'author', role: 'aut').display_seq(1).file_as('Creator, The').add_alternates({ 'ja-JP' => '作成者' })
|
117
|
-
expect(metadata.creator.to_s).to eq('TheCreator')
|
118
|
-
expect(metadata.creator.to_s('ja')).to eq('作成者')
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should handle alternate-script metadata of creator, not using method chain' do
|
122
|
-
metadata = GEPUB::Metadata.new
|
123
|
-
m = metadata.add_creator('TheCreator', id: 'author', role: 'aut')
|
124
|
-
m.display_seq = 1
|
125
|
-
m.file_as = 'Creator, The'
|
126
|
-
m.add_alternates({ 'ja-JP' => '作成者' })
|
127
|
-
|
128
|
-
expect(metadata.creator.to_s).to eq('TheCreator')
|
129
|
-
expect(metadata.creator.to_s('ja')).to eq('作成者')
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should detect duplicate id' do
|
133
|
-
metadata = GEPUB::Metadata.new
|
134
|
-
metadata.add_creator('TheCreator', id: 'id', role: 'aut')
|
135
|
-
expect { metadata.add_title('TheTitle', 'id') }.to raise_error(RuntimeError, "id 'id' is already in use.")
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should generate empty metadata xml' do
|
139
|
-
metadata = GEPUB::Metadata.new
|
140
|
-
builder = Nokogiri::XML::Builder.new { |xml|
|
141
|
-
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
142
|
-
metadata.to_xml(xml)
|
143
|
-
}
|
144
|
-
}
|
145
|
-
xml = Nokogiri::XML::Document.parse(builder.to_xml).at_xpath('//xmlns:metadata', { 'xmlns' => GEPUB::XMLUtil::OPF_NS})
|
146
|
-
expect(xml.namespaces['xmlns:dc']).to eq(GEPUB::XMLUtil::DC_NS)
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'should handle date with Time object' do
|
150
|
-
metadata = GEPUB::Metadata.new
|
151
|
-
a = Time.parse '2012-02-27 20:00:00 UTC'
|
152
|
-
metadata.add_date(a, 'date')
|
153
|
-
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'should handle date with `date=` method and Time object' do
|
157
|
-
metadata = GEPUB::Metadata.new
|
158
|
-
a = Time.parse '2012-02-27 20:00:00 UTC'
|
159
|
-
metadata.date = a
|
160
|
-
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'should handle date with Time object by content = ' do
|
164
|
-
metadata = GEPUB::Metadata.new
|
165
|
-
a = Time.parse '2012-02-27 20:00:00 UTC'
|
166
|
-
metadata.add_date('2011-01-01', 'date')
|
167
|
-
metadata.date.content = a
|
168
|
-
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'should handle date with a not W3C-DTF string' do
|
172
|
-
metadata = GEPUB::Metadata.new
|
173
|
-
metadata.add_date('2012-02-28 05:00:00 +0900', 'date')
|
174
|
-
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
|
175
|
-
end
|
176
|
-
|
177
|
-
it 'should generate metadata with id xml' do
|
178
|
-
metadata = GEPUB::Metadata.new
|
179
|
-
metadata.add_identifier('the_uid', nil)
|
180
|
-
builder = Nokogiri::XML::Builder.new { |xml|
|
181
|
-
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
182
|
-
metadata.to_xml(xml)
|
183
|
-
}
|
184
|
-
}
|
185
|
-
expect(Nokogiri::XML::Document.parse(builder.to_xml).at_xpath('//dc:identifier', metadata.instance_eval {@namespaces}).content).to eq('the_uid')
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'should generate metadata with creator refiner' do
|
189
|
-
metadata = GEPUB::Metadata.new
|
190
|
-
metadata.add_creator('TheCreator', role: 'aut').display_seq(1).file_as('Creator, The').add_alternates({ 'ja-JP' => '作成者' })
|
191
|
-
builder = Nokogiri::XML::Builder.new { |xml|
|
192
|
-
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
193
|
-
metadata.to_xml(xml)
|
194
|
-
}
|
195
|
-
}
|
196
|
-
xml = Nokogiri::XML::Document.parse(builder.to_xml)
|
197
|
-
ns = metadata.instance_eval { @namespaces }
|
198
|
-
expect(xml.at_xpath('//dc:creator', ns).content).to eq('TheCreator')
|
199
|
-
id = xml.at_xpath('//dc:creator', ns)['id']
|
200
|
-
expect(xml.at_xpath("//xmlns:meta[@refines='##{id}' and @property='role']").content).to eq('aut')
|
201
|
-
expect(xml.at_xpath("//xmlns:meta[@refines='##{id}' and @property='display-seq']").content).to eq('1')
|
202
|
-
expect(xml.at_xpath("//xmlns:meta[@refines='##{id}' and @property='file-as']").content).to eq('Creator, The')
|
203
|
-
expect(xml.at_xpath("//xmlns:meta[@refines='##{id}' and @property='alternate-script' and @xml:lang='ja-JP']").content).to eq('作成者')
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'should generate metadata with old style meta tag' do
|
207
|
-
metadata = GEPUB::Metadata.new
|
208
|
-
metadata.add_creator('TheCreator', role: 'aut').display_seq(1).file_as('Creator, The').add_alternates({ 'ja-JP' => '作成者' })
|
209
|
-
metadata.add_oldstyle_meta(nil, { 'name' => 'cover', 'content' => 'cover.jpg' })
|
210
|
-
builder = Nokogiri::XML::Builder.new { |xml|
|
211
|
-
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
212
|
-
metadata.to_xml(xml)
|
213
|
-
}
|
214
|
-
}
|
215
|
-
xml = Nokogiri::XML::Document.parse(builder.to_xml)
|
216
|
-
expect(xml.xpath("//xmlns:meta[@name='cover' and @content='cover.jpg']").size).to eq(1)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|