eeepub_ext 0.8.2

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.
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "EeePub::ContainerItem" do
4
+
5
+ context 'guess media type' do
6
+
7
+ before :each do
8
+ @container_item = EeePub::ContainerItem.new []
9
+ end
10
+
11
+ it 'should be application/xhtml+xml' do
12
+ media_type = 'application/xhtml+xml'
13
+ ['test.htm', 'test.html', 'test.xhtm', 'test.xhtml'].each do |file_name|
14
+ @container_item.send(:guess_media_type, file_name).should == media_type
15
+ end
16
+ @container_item.send(:guess_media_type, "test.xml").should_not == media_type
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,71 @@
1
+ # TODO: for debugging only
2
+ require 'pry'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe "EeePub::Easy" do
6
+ before do
7
+ @easy = EeePub::Easy.new do
8
+ title 'sample'
9
+ creator 'jugyo'
10
+ identifier 'http://example.com/book/foo', :scheme => 'URL'
11
+ uid 'http://example.com/book/foo'
12
+ end
13
+
14
+ @easy.sections << ['1. foo', <<HTML]
15
+ <?xml version="1.0" encoding="UTF-8"?>
16
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
17
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
18
+ <head>
19
+ <title>foo</title>
20
+ </head>
21
+ <body>
22
+ <p>
23
+ foo foo foo foo foo foo
24
+ </p>
25
+ </body>
26
+ </html>
27
+ HTML
28
+
29
+ @easy.sections << ['2. bar', <<HTML]
30
+ <?xml version="1.0" encoding="UTF-8"?>
31
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
32
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
33
+ <head>
34
+ <title>bar</title>
35
+ </head>
36
+ <body>
37
+ <p>
38
+ bar bar bar bar bar bar
39
+ </p>
40
+ </body>
41
+ </html>
42
+ HTML
43
+
44
+ @easy.assets << 'image.png'
45
+ end
46
+
47
+ it 'spec for prepare' do
48
+ pending "TODO: this result in error, disable for now"
49
+ Dir.mktmpdir do |dir|
50
+ mock(FileUtils).cp('image.png', dir)
51
+
52
+ @easy.send(:prepare, dir)
53
+
54
+ file1 = File.join(dir, 'section_0.html')
55
+ file2 = File.join(dir, 'section_1.html')
56
+
57
+ File.exists?(file1).should be_true
58
+ File.exists?(file2).should be_true
59
+
60
+ File.read(file1).should == @easy.sections[0][1]
61
+ File.read(file2).should == @easy.sections[1][1]
62
+
63
+ @easy.instance_variable_get(:@nav).should == [
64
+ {:label => '1. foo', :content => 'section_0.html'},
65
+ {:label => '2. bar', :content => 'section_1.html'}
66
+ ]
67
+
68
+ @easy.instance_variable_get(:@files).should == [file1, file2, 'image.png']
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,132 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "EeePub::Maker" do
4
+ before do
5
+ @maker = EeePub::Maker.new do
6
+ title 'sample'
7
+ creator 'jugyo'
8
+ publisher 'jugyo.org'
9
+ date "2010-05-06"
10
+ language 'en'
11
+ subject 'epub sample'
12
+ description 'this is epub sample'
13
+ rights 'xxx'
14
+ relation 'xxx'
15
+ identifier 'http://example.com/book/foo', :scheme => 'URL'
16
+ uid 'http://example.com/book/foo'
17
+ ncx_file 'toc.ncx'
18
+ opf_file 'content.opf'
19
+ cover 'cover.jpg'
20
+ files ['foo.html', 'bar.html']
21
+ nav [
22
+ {:label => '1. foo', :content => 'foo.html'},
23
+ {:label => '1. bar', :content => 'bar.html'}
24
+ ]
25
+ end
26
+ end
27
+
28
+ it { @maker.instance_variable_get(:@titles).should == ['sample'] }
29
+ it { @maker.instance_variable_get(:@creators).should == ['jugyo'] }
30
+ it { @maker.instance_variable_get(:@publishers).should == ['jugyo.org'] }
31
+ it { @maker.instance_variable_get(:@dates).should == ["2010-05-06"] }
32
+ it { @maker.instance_variable_get(:@identifiers).should == [{:value => 'http://example.com/book/foo', :scheme => 'URL', :id => nil}] }
33
+ it { @maker.instance_variable_get(:@uid).should == 'http://example.com/book/foo' }
34
+ it { @maker.instance_variable_get(:@ncx_file).should == 'toc.ncx' }
35
+ it { @maker.instance_variable_get(:@opf_file).should == 'content.opf' }
36
+ it { @maker.instance_variable_get(:@cover).should == 'cover.jpg' }
37
+ it { @maker.instance_variable_get(:@files).should == ['foo.html', 'bar.html'] }
38
+ it {
39
+ @maker.instance_variable_get(:@nav).should == [
40
+ {:label => '1. foo', :content => 'foo.html'},
41
+ {:label => '1. bar', :content => 'bar.html'}
42
+ ]
43
+ }
44
+
45
+ it 'should save' do
46
+ pending "TODO: this result in error, disable for now"
47
+ stub(FileUtils).cp.with_any_args
48
+ mock(Dir).mktmpdir { '/tmp' }
49
+ mock(EeePub::NCX).new(
50
+ :title => "sample",
51
+ :nav => [
52
+ {:label => '1. foo', :content => 'foo.html'},
53
+ {:label => '1. bar', :content => 'bar.html'}
54
+ ],
55
+ :uid=>{:value=>"http://example.com/book/foo", :scheme=>"URL", :id=>"http://example.com/book/foo"}
56
+ ) { stub!.save }
57
+ mock(EeePub::OPF).new(
58
+ :title => ["sample"],
59
+ :creator => ["jugyo"],
60
+ :date => ["2010-05-06"],
61
+ :language => ['en'],
62
+ :subject => ['epub sample'],
63
+ :description => ['this is epub sample'],
64
+ :rights => ['xxx'],
65
+ :relation => ['xxx'],
66
+ :ncx => "toc.ncx",
67
+ :cover => 'cover.jpg',
68
+ :publisher => ["jugyo.org"],
69
+ :unique_identifier=>"http://example.com/book/foo",
70
+ :identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id => "http://example.com/book/foo"}],
71
+ :manifest => ['foo.html', 'bar.html']
72
+ ) { stub!.save }
73
+ mock(EeePub::OCF).new(
74
+ :container => "content.opf",
75
+ :dir => '/tmp'
76
+ ) { stub!.save }
77
+
78
+ @maker.save('test.epub')
79
+ end
80
+
81
+ describe "files as hash" do
82
+ before do
83
+ @maker = EeePub::Maker.new do
84
+ title 'sample'
85
+ creator 'jugyo'
86
+ publisher 'jugyo.org'
87
+ date "2010-05-06"
88
+ language 'en'
89
+ subject 'epub sample'
90
+ description 'this is epub sample'
91
+ rights 'xxx'
92
+ relation 'xxx'
93
+ identifier 'http://example.com/book/foo', :scheme => 'URL'
94
+ uid 'http://example.com/book/foo'
95
+ ncx_file 'toc.ncx'
96
+ opf_file 'content.opf'
97
+ cover 'cover.jpg'
98
+ files [{'foo.html' => 'foo/bar'}, {'bar.html' => 'foo/bar/baz'}]
99
+ nav [
100
+ {:label => '1. foo', :content => 'foo.html'},
101
+ {:label => '1. bar', :content => 'bar.html'}
102
+ ]
103
+ end
104
+ end
105
+
106
+ it 'should save' do
107
+ pending "TODO: this result in error, disable for now"
108
+ stub(FileUtils).cp.with_any_args
109
+ stub(FileUtils).mkdir_p.with_any_args
110
+ mock(Dir).mktmpdir { '/tmp' }
111
+ mock(EeePub::NCX).new.with_any_args { stub!.save }
112
+ mock(EeePub::OPF).new(
113
+ :title => ["sample"],
114
+ :creator => ["jugyo"],
115
+ :date => ["2010-05-06"],
116
+ :language => ['en'],
117
+ :subject => ['epub sample'],
118
+ :description => ['this is epub sample'],
119
+ :rights => ['xxx'],
120
+ :relation => ['xxx'],
121
+ :ncx => "toc.ncx",
122
+ :cover => 'cover.jpg',
123
+ :publisher => ["jugyo.org"],
124
+ :unique_identifier=>"http://example.com/book/foo",
125
+ :identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id=>"http://example.com/book/foo"}],
126
+ :manifest => ["foo/bar/foo.html", "foo/bar/baz/bar.html"]
127
+ ) { stub!.save }
128
+ mock(EeePub::OCF).new.with_any_args { stub!.save }
129
+ @maker.save('test.epub')
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,80 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ describe "EeePub::NCX" do
7
+ before do
8
+ @ncx = EeePub::NCX.new(
9
+ :uid => 'uid',
10
+ :nav_map => [
11
+ {:label => 'foo', :content => 'foo.html'},
12
+ {:label => 'bar', :content => 'bar.html'}
13
+ ]
14
+ )
15
+ end
16
+
17
+ it 'should set default values' do
18
+ @ncx.depth.should == 1
19
+ @ncx.total_page_count.should == 0
20
+ @ncx.max_page_number.should == 0
21
+ @ncx.doc_title.should == 'Untitled'
22
+ end
23
+
24
+ it 'should make xml' do
25
+ doc = Nokogiri::XML(@ncx.to_xml)
26
+ head = doc.at('head')
27
+ head.should_not be_nil
28
+
29
+ head.at("//xmlns:meta[@name='dtb:uid']")['content'].should == @ncx.uid
30
+ head.at("//xmlns:meta[@name='dtb:depth']")['content'].should == @ncx.depth.to_s
31
+ head.at("//xmlns:meta[@name='dtb:totalPageCount']")['content'].should == @ncx.total_page_count.to_s
32
+ head.at("//xmlns:meta[@name='dtb:maxPageNumber']")['content'].should == @ncx.max_page_number.to_s
33
+ head.at("//xmlns:docTitle/xmlns:text").inner_text.should == @ncx.doc_title
34
+
35
+ nav_map = doc.at('navMap')
36
+ nav_map.should_not be_nil
37
+ nav_map.search('navPoint').each_with_index do |nav_point, index|
38
+ expect = @ncx.nav_map[index]
39
+ nav_point.attribute('id').value.should == "navPoint-#{index + 1}"
40
+ nav_point.attribute('playOrder').value.should == (index + 1).to_s
41
+ nav_point.at('navLabel').at('text').inner_text.should == expect[:label]
42
+ nav_point.at('content').attribute('src').value.should == expect[:content]
43
+ end
44
+ end
45
+
46
+ context 'nested nav_map' do
47
+ before do
48
+ @ncx.nav = [
49
+ {:label => 'foo', :content => 'foo.html',
50
+ :nav => [
51
+ {:label => 'foo-1', :content => 'foo-1.html'},
52
+ {:label => 'foo-2', :content => 'foo-2.html'}
53
+ ],
54
+ },
55
+ {:label => 'bar', :content => 'bar.html'}
56
+ ]
57
+ end
58
+
59
+ it 'should make xml' do
60
+ doc = Nokogiri::XML(@ncx.to_xml)
61
+ nav_map = doc.at('navMap')
62
+
63
+ nav_map.search('navMap/navPoint').each_with_index do |nav_point, index|
64
+ expect = @ncx.nav_map[index]
65
+ nav_point.attribute('id').value.should == "navPoint-#{index + 1}"
66
+ nav_point.attribute('playOrder').value.should == (index + 1).to_s
67
+ nav_point.at('navLabel').at('text').inner_text.should == expect[:label]
68
+ nav_point.at('content').attribute('src').value.should == expect[:content]
69
+ end
70
+
71
+ nav_map.search('navPoint/navPoint').each_with_index do |nav_point, index|
72
+ expect = @ncx.nav[0][:nav][index]
73
+ nav_point.attribute('id').value.should == "navPoint-#{index + 2}"
74
+ nav_point.attribute('playOrder').value.should == (index + 2).to_s
75
+ nav_point.at('navLabel').at('text').inner_text.should == expect[:label]
76
+ nav_point.at('content').attribute('src').value.should == expect[:content]
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ describe "EeePub::OCF" do
7
+ before do
8
+ @tmpdir = File.join(Dir.tmpdir, 'eeepub_test')
9
+ FileUtils.mkdir_p(@tmpdir)
10
+ @container = EeePub::OCF::Container.new('foo.opf')
11
+ @ocf = EeePub::OCF.new(:dir => @tmpdir, :container => @container)
12
+ end
13
+
14
+ after do
15
+ FileUtils.rm_rf(@tmpdir)
16
+ end
17
+
18
+ it 'should return rootfiles' do
19
+ @container.rootfiles.should == [{:full_path => 'foo.opf', :media_type => 'application/oebps-package+xml'}]
20
+ end
21
+
22
+ it 'should specify container as String' do
23
+ ocf = EeePub::OCF.new(:dir => @tmpdir, :container => 'foo.opf')
24
+ ocf.container.rootfiles == [{:full_path => 'foo.opf', :media_type => 'application/oebps-package+xml'}]
25
+ end
26
+
27
+ it 'should make xml' do
28
+ doc = Nokogiri::XML(@container.to_xml)
29
+ rootfiles = doc.at('rootfiles')
30
+ rootfiles.should_not be_nil
31
+ rootfiles.search('rootfile').each_with_index do |rootfile, index|
32
+ expect = @container.rootfiles[index]
33
+ rootfile.attribute('full-path').value.should == expect[:full_path]
34
+ rootfile.attribute('media-type').value.should == expect[:media_type]
35
+ end
36
+ end
37
+
38
+ it 'should make epub' do
39
+ output_path = File.join('eeepub_test.epub')
40
+ @ocf.save(output_path)
41
+ File.exists?(output_path)
42
+ end
43
+
44
+ it 'should stream epub' do
45
+ pending "TODO: this result in error, disable for now"
46
+ output = @ocf.render
47
+ output.size.should == 134
48
+ output.is_binary_data?.should be_true
49
+ end
50
+ end
@@ -0,0 +1,267 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'date'
3
+
4
+ describe "EeePub::OPF" do
5
+ before do
6
+ @opf = EeePub::OPF.new(
7
+ :identifier => {:value => '978-4-00-310101-8', :scheme => 'ISBN'},
8
+ :files => ['foo.html', 'bar.html', 'picture.png'],
9
+ :ncx => 'toc.ncx'
10
+ )
11
+ end
12
+
13
+ it 'should set default value' do
14
+ @opf.toc.should == 'ncx'
15
+ @opf.unique_identifier.should == 'BookId'
16
+ @opf.title.should == 'Untitled'
17
+ @opf.language.should == 'en'
18
+ end
19
+
20
+ it 'should export as xml' do
21
+ doc = Nokogiri::XML(@opf.to_xml)
22
+ doc.at('package').attribute('unique-identifier').value.should == @opf.unique_identifier
23
+ metadata = doc.at('metadata')
24
+ metadata.should_not be_nil
25
+ [
26
+ ['dc:title', @opf.title],
27
+ ['dc:language', @opf.language],
28
+ ['dc:date', ''],
29
+ ['dc:subject', ''],
30
+ ['dc:description', ''],
31
+ ['dc:relation', ''],
32
+ ['dc:creator', ''],
33
+ ['dc:publisher', ''],
34
+ ['dc:rights', ''],
35
+ ].each do |xpath, expect|
36
+ metadata.xpath(xpath,
37
+ 'xmlns:dc' => "http://purl.org/dc/elements/1.1/").inner_text.should == expect
38
+ end
39
+ identifier = metadata.xpath('dc:identifier', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")[0]
40
+ identifier.attribute('id').value.should == @opf.unique_identifier
41
+ identifier.attribute('scheme').value.should == @opf.identifier[0][:scheme]
42
+ identifier.inner_text.should == @opf.identifier[0][:value]
43
+
44
+ manifest = doc.at('manifest')
45
+ manifest.should_not be_nil
46
+ manifest = manifest.search('item')
47
+ manifest.size.should == 4
48
+ manifest[0..2].each_with_index do |item, index|
49
+ expect = @opf.manifest[index]
50
+ item.attribute('id').value.should == expect
51
+ item.attribute('href').value.should == expect
52
+ item.attribute('media-type').value.should == @opf.send(:guess_media_type, expect)
53
+ end
54
+ manifest[3].attribute('id').value.should == 'ncx'
55
+ manifest[3].attribute('href').value.should == @opf.ncx
56
+ manifest[3].attribute('media-type').value.should == @opf.send(:guess_media_type, @opf.ncx)
57
+
58
+ spine = doc.at('spine')
59
+ spine.should_not be_nil
60
+ spine = spine.search('itemref')
61
+ spine.size.should == 2
62
+ spine[0].attribute('idref').value.should == 'foo.html'
63
+ spine[1].attribute('idref').value.should == 'bar.html'
64
+
65
+ doc.at('guide').should be_nil
66
+ end
67
+
68
+ describe 'spec of identifier' do
69
+ context 'specify as Array' do
70
+ before { @opf.identifier = [{:scheme => 'ISBN', :value => '978-4-00-310101-8'}] }
71
+ it 'should return value' do
72
+ @opf.identifier.should == [{:scheme => 'ISBN', :value => '978-4-00-310101-8'}]
73
+ end
74
+ end
75
+
76
+ context 'specify as Hash' do
77
+ before { @opf.identifier = {:scheme => 'ISBN', :value => '978-4-00-310101-8'} }
78
+ it 'should return value' do
79
+ @opf.identifier.should == [{:scheme => 'ISBN', :value => '978-4-00-310101-8', :id => @opf.unique_identifier}]
80
+ end
81
+ end
82
+
83
+ context 'specify as String' do
84
+ before { @opf.identifier = '978-4-00-310101-8' }
85
+ it 'should return value' do
86
+ @opf.identifier.should == [{:value => '978-4-00-310101-8', :id => @opf.unique_identifier}]
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'spec of create_unique_item_id' do
92
+ it 'should return unique item id' do
93
+ id_cache = {}
94
+ @opf.create_unique_item_id('foo/bar/test.html', id_cache).should == 'test.html'
95
+ @opf.create_unique_item_id('foo/bar/test.html', id_cache).should == 'test.html-1'
96
+ @opf.create_unique_item_id('foo/bar/TEST.html', id_cache).should == 'TEST.html'
97
+ @opf.create_unique_item_id('foo/bar/test.html.1', id_cache).should == 'test.html.1'
98
+ end
99
+ end
100
+
101
+ context 'ncx is nil' do
102
+ before do
103
+ @opf.ncx = nil
104
+ end
105
+
106
+ it 'should not set ncx to manifest' do
107
+ doc = Nokogiri::XML(@opf.to_xml)
108
+ doc.search('manifest/item[id=ncx]').should be_empty
109
+ end
110
+ end
111
+
112
+ context 'set all metadata' do
113
+ before do
114
+ @opf.set_values(
115
+ :date => Date.today,
116
+ :subject => 'subject',
117
+ :description => 'description',
118
+ :relation => 'relation',
119
+ :creator => 'creator',
120
+ :publisher => 'publisher',
121
+ :rights => 'rights',
122
+ :cover => 'cover.jpg'
123
+ )
124
+ end
125
+
126
+ it 'should export as xml' do
127
+ doc = Nokogiri::XML(@opf.to_xml)
128
+ metadata = doc.at('metadata')
129
+ metadata.should_not be_nil
130
+ [
131
+ ['dc:title', @opf.title],
132
+ ['dc:language', @opf.language],
133
+ ['dc:date', @opf.date.to_s],
134
+ ['dc:subject', 'subject'],
135
+ ['dc:description', 'description'],
136
+ ['dc:relation', 'relation'],
137
+ ['dc:creator', 'creator'],
138
+ ['dc:publisher', 'publisher'],
139
+ ['dc:rights', 'rights'],
140
+ ].each do |xpath, expect|
141
+ metadata.xpath(xpath,
142
+ 'xmlns:dc' => "http://purl.org/dc/elements/1.1/").inner_text.should == expect
143
+ end
144
+ identifier = metadata.xpath('dc:identifier', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")[0]
145
+ identifier.attribute('id').value.should == @opf.unique_identifier
146
+ identifier.attribute('scheme').value.should == @opf.identifier[0][:scheme]
147
+ identifier.inner_text.should == @opf.identifier[0][:value]
148
+
149
+ identifier = metadata.at('meta')
150
+ identifier.attribute('name').value.should == 'cover'
151
+ identifier.attribute('content').value.should == 'cover.jpg'
152
+ end
153
+ end
154
+
155
+ context 'plural identifiers' do
156
+ before do
157
+ @opf.identifier = [
158
+ {:id => 'BookId', :scheme => 'ISBN', :value => '978-4-00-310101-8'},
159
+ {:id => 'BookURL', :scheme => 'URL', :value => 'http://example.com/books/foo'}
160
+ ]
161
+ end
162
+
163
+ it 'should export as xml' do
164
+ doc = Nokogiri::XML(@opf.to_xml)
165
+ elements = doc.xpath('//dc:identifier', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")
166
+ elements.size.should == 2
167
+ elements.each_with_index do |element, index|
168
+ expect = @opf.identifier[index]
169
+ element.attribute('id').value.should == expect[:id]
170
+ element.attribute('scheme').value.should == expect[:scheme]
171
+ element.inner_text.should == expect[:value]
172
+ end
173
+ end
174
+ end
175
+
176
+ context 'plural languages' do
177
+ before do
178
+ @opf.language = ['ja', 'en']
179
+ end
180
+
181
+ it 'should export as xml' do
182
+ doc = Nokogiri::XML(@opf.to_xml)
183
+ elements = doc.xpath('//dc:language', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")
184
+ elements.size.should == 2
185
+ elements.each_with_index do |element, index|
186
+ element.inner_text.should == @opf.language[index]
187
+ end
188
+ end
189
+ end
190
+
191
+ context 'specify spine' do
192
+ before do
193
+ @opf.spine = ['a', 'b']
194
+ end
195
+
196
+ it 'should export as xml' do
197
+ doc = Nokogiri::XML(@opf.to_xml)
198
+ spine = doc.at('spine')
199
+ spine.should_not be_nil
200
+ spine = spine.search('itemref')
201
+ spine.size.should == 2
202
+ spine[0].attribute('idref').value.should == 'a'
203
+ spine[1].attribute('idref').value.should == 'b'
204
+ end
205
+ end
206
+
207
+ context 'specify manifest as Hash' do
208
+ before do
209
+ @opf.manifest = [
210
+ {:id => 'foo', :href => 'foo.html', :media_type => 'application/xhtml+xml'},
211
+ {:id => 'bar', :href => 'bar.html', :media_type => 'application/xhtml+xml'},
212
+ {:id => 'picture', :href => 'picture.png', :media_type => 'image/png'}
213
+ ]
214
+ end
215
+
216
+ it 'should export as xml' do
217
+ doc = Nokogiri::XML(@opf.to_xml)
218
+ manifest = doc.at('manifest')
219
+ manifest.should_not be_nil
220
+ manifest = manifest.search('item')
221
+ manifest.size.should == 4
222
+ manifest[0..2].each_with_index do |item, index|
223
+ expect = @opf.manifest[index]
224
+ item.attribute('id').value.should == expect[:id]
225
+ item.attribute('href').value.should == expect[:href]
226
+ item.attribute('media-type').value.should == expect[:media_type]
227
+ end
228
+ manifest[3].attribute('id').value.should == 'ncx'
229
+ manifest[3].attribute('href').value.should == @opf.ncx
230
+ manifest[3].attribute('media-type').value.should == @opf.send(:guess_media_type, @opf.ncx)
231
+ end
232
+ end
233
+
234
+ context 'specify dc:date[event]' do
235
+ before do
236
+ @opf.date = {:value => Date.today, :event => 'publication'}
237
+ end
238
+
239
+ it 'should export as xml' do
240
+ doc = Nokogiri::XML(@opf.to_xml)
241
+ metadata = doc.at('metadata')
242
+ date = metadata.xpath('dc:date', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")
243
+ date.inner_text.should == @opf.date[:value].to_s
244
+ date.attribute('event').value.should == @opf.date[:event]
245
+ end
246
+ end
247
+
248
+ context 'set guide' do
249
+ before do
250
+ @opf.guide = [
251
+ {:type => 'toc', :title => 'Table of Contents', :href => 'toc.html'},
252
+ {:type => 'loi', :title => 'List Of Illustrations', :href => 'toc.html#figures'},
253
+ ]
254
+ end
255
+
256
+ it 'should export as xml' do
257
+ doc = Nokogiri::XML(@opf.to_xml)
258
+ guide = doc.at('guide')
259
+ guide.should_not be_nil
260
+ references = guide.search('reference')
261
+ references.size.should == 2
262
+ [references, @opf.guide].transpose do |element, expect|
263
+ element.attributes.should == expect
264
+ end
265
+ end
266
+ end
267
+ end