eeepub3 0.0.1

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,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,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
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Epubr" do
4
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'eeepub'
4
+ require 'rspec'
5
+ require 'nokogiri'
6
+ require 'rr'
7
+ require 'simplecov'
8
+
9
+ RSpec.configure do |config|
10
+ config.mock_with :rr
11
+ end
12
+
13
+ SimpleCov.start
14
+
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eeepub3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - bubaz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: EeePub is a Ruby ePub generator.
98
+ email:
99
+ - s.bubovich@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - Gemfile
105
+ - LICENSE
106
+ - README.md
107
+ - Rakefile
108
+ - eeepub3.gemspec
109
+ - lib/eeepub.rb
110
+ - lib/eeepub/container_item.rb
111
+ - lib/eeepub/easy.rb
112
+ - lib/eeepub/maker.rb
113
+ - lib/eeepub/ncx.rb
114
+ - lib/eeepub/ocf.rb
115
+ - lib/eeepub/opf.rb
116
+ - spec/eeepub/container_item_spec.rb
117
+ - spec/eeepub/easy_spec.rb
118
+ - spec/eeepub/maker_spec.rb
119
+ - spec/eeepub/ncx_spec.rb
120
+ - spec/eeepub/ocf_spec.rb
121
+ - spec/eeepub/opf_spec.rb
122
+ - spec/eeepub_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: http://github.com/bubaz/eeepub3
125
+ licenses: []
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.0.0.rc.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: ePub generator
147
+ test_files: []