walterdavis-eeepub 0.6.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,265 @@
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:author', ''],
34
+ ['dc:publisher', ''],
35
+ ['dc:rights', ''],
36
+ ].each do |xpath, expect|
37
+ metadata.xpath(xpath,
38
+ 'xmlns:dc' => "http://purl.org/dc/elements/1.1/").inner_text.should == expect
39
+ end
40
+ identifier = metadata.xpath('dc:identifier', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")[0]
41
+ identifier.attribute('id').value.should == @opf.unique_identifier
42
+ identifier.attribute('scheme').value.should == @opf.identifier[0][:scheme]
43
+ identifier.inner_text.should == @opf.identifier[0][:value]
44
+
45
+ manifest = doc.at('manifest')
46
+ manifest.should_not be_nil
47
+ manifest = manifest.search('item')
48
+ manifest.size.should == 4
49
+ manifest[0..2].each_with_index do |item, index|
50
+ expect = @opf.manifest[index]
51
+ item.attribute('id').value.should == expect
52
+ item.attribute('href').value.should == expect
53
+ item.attribute('media-type').value.should == @opf.send(:guess_media_type, expect)
54
+ end
55
+ manifest[3].attribute('id').value.should == 'ncx'
56
+ manifest[3].attribute('href').value.should == @opf.ncx
57
+ manifest[3].attribute('media-type').value.should == @opf.send(:guess_media_type, @opf.ncx)
58
+
59
+ spine = doc.at('spine')
60
+ spine.should_not be_nil
61
+ spine = spine.search('itemref')
62
+ spine.size.should == 2
63
+ spine[0].attribute('idref').value.should == 'foo.html'
64
+ spine[1].attribute('idref').value.should == 'bar.html'
65
+
66
+ doc.at('guide').should be_nil
67
+ end
68
+
69
+ describe 'spec of identifier' do
70
+ context 'specify as Array' do
71
+ before { @opf.identifier = [{:scheme => 'ISBN', :value => '978-4-00-310101-8'}] }
72
+ it 'should return value' do
73
+ @opf.identifier.should == [{:scheme => 'ISBN', :value => '978-4-00-310101-8'}]
74
+ end
75
+ end
76
+
77
+ context 'specify as Hash' do
78
+ before { @opf.identifier = {:scheme => 'ISBN', :value => '978-4-00-310101-8'} }
79
+ it 'should return value' do
80
+ @opf.identifier.should == [{:scheme => 'ISBN', :value => '978-4-00-310101-8', :id => @opf.unique_identifier}]
81
+ end
82
+ end
83
+
84
+ context 'specify as String' do
85
+ before { @opf.identifier = '978-4-00-310101-8' }
86
+ it 'should return value' do
87
+ @opf.identifier.should == [{:value => '978-4-00-310101-8', :id => @opf.unique_identifier}]
88
+ end
89
+ end
90
+ end
91
+
92
+ describe 'spec of create_unique_item_id' do
93
+ it 'should return unique item id' do
94
+ id_cache = {}
95
+ @opf.create_unique_item_id('foo/bar/test.html', id_cache).should == 'test.html'
96
+ @opf.create_unique_item_id('foo/bar/test.html', id_cache).should == 'test.html-1'
97
+ @opf.create_unique_item_id('foo/bar/TEST.html', id_cache).should == 'TEST.html'
98
+ @opf.create_unique_item_id('foo/bar/test.html.1', id_cache).should == 'test.html.1'
99
+ end
100
+ end
101
+
102
+ context 'ncx is nil' do
103
+ before do
104
+ @opf.ncx = nil
105
+ end
106
+
107
+ it 'should not set ncx to manifest' do
108
+ doc = Nokogiri::XML(@opf.to_xml)
109
+ doc.search('manifest/item[id=ncx]').should be_empty
110
+ end
111
+ end
112
+
113
+ context 'set all metadata' do
114
+ before do
115
+ @opf.set_values(
116
+ :date => Date.today,
117
+ :subject => 'subject',
118
+ :description => 'description',
119
+ :relation => 'relation',
120
+ :creator => 'creator',
121
+ :author => 'author',
122
+ :publisher => 'publisher',
123
+ :rights => 'rights'
124
+ )
125
+ end
126
+
127
+ it 'should export as xml' do
128
+ doc = Nokogiri::XML(@opf.to_xml)
129
+ metadata = doc.at('metadata')
130
+ metadata.should_not be_nil
131
+ [
132
+ ['dc:title', @opf.title],
133
+ ['dc:language', @opf.language],
134
+ ['dc:date', @opf.date.to_s],
135
+ ['dc:subject', 'subject'],
136
+ ['dc:description', 'description'],
137
+ ['dc:relation', 'relation'],
138
+ ['dc:creator', 'creator'],
139
+ ['dc:author', 'author'],
140
+ ['dc:publisher', 'publisher'],
141
+ ['dc:rights', 'rights'],
142
+ ].each do |xpath, expect|
143
+ metadata.xpath(xpath,
144
+ 'xmlns:dc' => "http://purl.org/dc/elements/1.1/").inner_text.should == expect
145
+ end
146
+ identifier = metadata.xpath('dc:identifier', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")[0]
147
+ identifier.attribute('id').value.should == @opf.unique_identifier
148
+ identifier.attribute('scheme').value.should == @opf.identifier[0][:scheme]
149
+ identifier.inner_text.should == @opf.identifier[0][:value]
150
+ end
151
+ end
152
+
153
+ context 'plural identifiers' do
154
+ before do
155
+ @opf.identifier = [
156
+ {:id => 'BookId', :scheme => 'ISBN', :value => '978-4-00-310101-8'},
157
+ {:id => 'BookURL', :scheme => 'URL', :value => 'http://example.com/books/foo'}
158
+ ]
159
+ end
160
+
161
+ it 'should export as xml' do
162
+ doc = Nokogiri::XML(@opf.to_xml)
163
+ elements = doc.xpath('//dc:identifier', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")
164
+ elements.size.should == 2
165
+ elements.each_with_index do |element, index|
166
+ expect = @opf.identifier[index]
167
+ element.attribute('id').value.should == expect[:id]
168
+ element.attribute('scheme').value.should == expect[:scheme]
169
+ element.inner_text.should == expect[:value]
170
+ end
171
+ end
172
+ end
173
+
174
+ context 'plural languages' do
175
+ before do
176
+ @opf.language = ['ja', 'en']
177
+ end
178
+
179
+ it 'should export as xml' do
180
+ doc = Nokogiri::XML(@opf.to_xml)
181
+ elements = doc.xpath('//dc:language', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")
182
+ elements.size.should == 2
183
+ elements.each_with_index do |element, index|
184
+ element.inner_text.should == @opf.language[index]
185
+ end
186
+ end
187
+ end
188
+
189
+ context 'specify spine' do
190
+ before do
191
+ @opf.spine = ['a', 'b']
192
+ end
193
+
194
+ it 'should export as xml' do
195
+ doc = Nokogiri::XML(@opf.to_xml)
196
+ spine = doc.at('spine')
197
+ spine.should_not be_nil
198
+ spine = spine.search('itemref')
199
+ spine.size.should == 2
200
+ spine[0].attribute('idref').value.should == 'a'
201
+ spine[1].attribute('idref').value.should == 'b'
202
+ end
203
+ end
204
+
205
+ context 'specify manifest as Hash' do
206
+ before do
207
+ @opf.manifest = [
208
+ {:id => 'foo', :href => 'foo.html', :media_type => 'application/xhtml+xml'},
209
+ {:id => 'bar', :href => 'bar.html', :media_type => 'application/xhtml+xml'},
210
+ {:id => 'picture', :href => 'picture.png', :media_type => 'image/png'}
211
+ ]
212
+ end
213
+
214
+ it 'should export as xml' do
215
+ doc = Nokogiri::XML(@opf.to_xml)
216
+ manifest = doc.at('manifest')
217
+ manifest.should_not be_nil
218
+ manifest = manifest.search('item')
219
+ manifest.size.should == 4
220
+ manifest[0..2].each_with_index do |item, index|
221
+ expect = @opf.manifest[index]
222
+ item.attribute('id').value.should == expect[:id]
223
+ item.attribute('href').value.should == expect[:href]
224
+ item.attribute('media-type').value.should == expect[:media_type]
225
+ end
226
+ manifest[3].attribute('id').value.should == 'ncx'
227
+ manifest[3].attribute('href').value.should == @opf.ncx
228
+ manifest[3].attribute('media-type').value.should == @opf.send(:guess_media_type, @opf.ncx)
229
+ end
230
+ end
231
+
232
+ context 'specify dc:date[event]' do
233
+ before do
234
+ @opf.date = {:value => Date.today, :event => 'publication'}
235
+ end
236
+
237
+ it 'should export as xml' do
238
+ doc = Nokogiri::XML(@opf.to_xml)
239
+ metadata = doc.at('metadata')
240
+ date = metadata.xpath('dc:date', 'xmlns:dc' => "http://purl.org/dc/elements/1.1/")
241
+ date.inner_text.should == @opf.date[:value].to_s
242
+ date.attribute('event').value.should == @opf.date[:event]
243
+ end
244
+ end
245
+
246
+ context 'set guide' do
247
+ before do
248
+ @opf.guide = [
249
+ {:type => 'toc', :title => 'Table of Contents', :href => 'toc.html'},
250
+ {:type => 'loi', :title => 'List Of Illustrations', :href => 'toc.html#figures'},
251
+ ]
252
+ end
253
+
254
+ it 'should export as xml' do
255
+ doc = Nokogiri::XML(@opf.to_xml)
256
+ guide = doc.at('guide')
257
+ guide.should_not be_nil
258
+ references = guide.search('reference')
259
+ references.size.should == 2
260
+ [references, @opf.guide].transpose do |element, expect|
261
+ element.attributes.should == expect
262
+ end
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Epubr" do
4
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'eeepub'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require 'nokogiri'
8
+ require 'rr'
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :rr
12
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: walterdavis-eeepub
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 2
10
+ version: 0.6.2
11
+ platform: ruby
12
+ authors:
13
+ - jugyo
14
+ - walterdavis
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-03-28 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: builder
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rr
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ description: EeePub is a Ruby ePub generator. This version is forked from the original https://github.com/jugyo/eeepub
65
+ email: waltd@wdstudio.com
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files:
71
+ - LICENSE
72
+ - README.md
73
+ files:
74
+ - LICENSE
75
+ - README.md
76
+ - Rakefile
77
+ - VERSION
78
+ - examples/files/bar.html
79
+ - examples/files/foo.html
80
+ - examples/simple_epub.rb
81
+ - lib/eeepub.rb
82
+ - lib/eeepub/container_item.rb
83
+ - lib/eeepub/easy.rb
84
+ - lib/eeepub/maker.rb
85
+ - lib/eeepub/ncx.rb
86
+ - lib/eeepub/ocf.rb
87
+ - lib/eeepub/opf.rb
88
+ - spec/eeepub/easy_spec.rb
89
+ - spec/eeepub/maker_spec.rb
90
+ - spec/eeepub/ncx_spec.rb
91
+ - spec/eeepub/ocf_spec.rb
92
+ - spec/eeepub/opf_spec.rb
93
+ - spec/eeepub_spec.rb
94
+ - spec/spec_helper.rb
95
+ has_rdoc: true
96
+ homepage: http://github.com/walterdavis/eeepub
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options: []
101
+
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.6.2
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: ePub generator
129
+ test_files:
130
+ - examples/simple_epub.rb
131
+ - spec/eeepub/easy_spec.rb
132
+ - spec/eeepub/maker_spec.rb
133
+ - spec/eeepub/ncx_spec.rb
134
+ - spec/eeepub/ocf_spec.rb
135
+ - spec/eeepub/opf_spec.rb
136
+ - spec/eeepub_spec.rb
137
+ - spec/spec_helper.rb