eeepub-with-cover-support 0.8.6

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