Skip to content

Commit a80bb6b

Browse files
author
Drew Bowman
committed
added cover to epub
1 parent 662d9d7 commit a80bb6b

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

lib/eeepub/maker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def #{name}(value)
5353
:uid,
5454
:files,
5555
:nav,
56+
:cover,
5657
:ncx_file,
5758
:opf_file
5859
].each do |name|
@@ -130,6 +131,7 @@ def create_epub
130131
:subject => @subjects,
131132
:description => @descriptions,
132133
:rights => @rightss,
134+
:cover => @cover,
133135
:relation => @relations,
134136
:manifest => @files.map{|file|
135137
case file

lib/eeepub/opf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class OPF < ContainerItem
1414
:manifest,
1515
:spine,
1616
:guide,
17+
:cover,
1718
:ncx,
1819
:toc
1920

@@ -83,6 +84,7 @@ def build_metadata(builder)
8384
end
8485
end
8586
end
87+
builder.meta(:name => 'cover', :content => self.cover) if self.cover
8688
end
8789
end
8890

spec/eeepub/maker_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
uid 'http://example.com/book/foo'
1717
ncx_file 'toc.ncx'
1818
opf_file 'content.opf'
19+
cover 'cover.jpg'
1920
files ['foo.html', 'bar.html']
2021
nav [
2122
{:label => '1. foo', :content => 'foo.html'},
@@ -32,6 +33,7 @@
3233
it { @maker.instance_variable_get(:@uid).should == 'http://example.com/book/foo' }
3334
it { @maker.instance_variable_get(:@ncx_file).should == 'toc.ncx' }
3435
it { @maker.instance_variable_get(:@opf_file).should == 'content.opf' }
36+
it { @maker.instance_variable_get(:@cover).should == 'cover.jpg' }
3537
it { @maker.instance_variable_get(:@files).should == ['foo.html', 'bar.html'] }
3638
it {
3739
@maker.instance_variable_get(:@nav).should == [
@@ -61,6 +63,7 @@
6163
:rights => ['xxx'],
6264
:relation => ['xxx'],
6365
:ncx => "toc.ncx",
66+
:cover => 'cover.jpg',
6467
:publisher => ["jugyo.org"],
6568
:unique_identifier=>"http://example.com/book/foo",
6669
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id => "http://example.com/book/foo"}],
@@ -90,6 +93,7 @@
9093
uid 'http://example.com/book/foo'
9194
ncx_file 'toc.ncx'
9295
opf_file 'content.opf'
96+
cover 'cover.jpg'
9397
files [{'foo.html' => 'foo/bar'}, {'bar.html' => 'foo/bar/baz'}]
9498
nav [
9599
{:label => '1. foo', :content => 'foo.html'},
@@ -113,6 +117,7 @@
113117
:rights => ['xxx'],
114118
:relation => ['xxx'],
115119
:ncx => "toc.ncx",
120+
:cover => 'cover.jpg',
116121
:publisher => ["jugyo.org"],
117122
:unique_identifier=>"http://example.com/book/foo",
118123
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id=>"http://example.com/book/foo"}],

spec/eeepub/opf_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
:relation => 'relation',
119119
:creator => 'creator',
120120
:publisher => 'publisher',
121-
:rights => 'rights'
121+
:rights => 'rights',
122+
:cover => 'cover.jpg'
122123
)
123124
end
124125

@@ -144,6 +145,10 @@
144145
identifier.attribute('id').value.should == @opf.unique_identifier
145146
identifier.attribute('scheme').value.should == @opf.identifier[0][:scheme]
146147
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'
147152
end
148153
end
149154

0 commit comments

Comments
 (0)