Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added source to epub #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/eeepub/maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def #{name}(value)
:files,
:nav,
:cover,
:source,
:ncx_file,
:opf_file,
:guide
Expand Down Expand Up @@ -133,6 +134,7 @@ def create_epub
:description => @descriptions,
:rights => @rightss,
:cover => @cover,
:source => @source,
:relation => @relations,
:manifest => @files.map{|file|
case file
Expand Down
3 changes: 2 additions & 1 deletion lib/eeepub/opf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class OPF < ContainerItem
:spine,
:guide,
:cover,
:source,
:ncx,
:toc

Expand Down Expand Up @@ -71,7 +72,7 @@ def build_metadata(builder)
builder.dc :identifier, i[:value], attrs
end

[:title, :language, :subject, :description, :relation, :creator, :publisher, :date, :rights].each do |i|
[:title, :language, :subject, :description, :relation, :creator, :publisher, :date, :rights, :source].each do |i|
value = self.send(i)
next unless value

Expand Down
61 changes: 34 additions & 27 deletions spec/eeepub/maker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ncx_file 'toc.ncx'
opf_file 'content.opf'
cover 'cover.jpg'
source 'http://example.com/book/foo'
files ['foo.html', 'bar.html']
nav [
{:label => '1. foo', :content => 'foo.html'},
Expand All @@ -34,6 +35,7 @@
it { @maker.instance_variable_get(:@ncx_file).should == 'toc.ncx' }
it { @maker.instance_variable_get(:@opf_file).should == 'content.opf' }
it { @maker.instance_variable_get(:@cover).should == 'cover.jpg' }
it { @maker.instance_variable_get(:@source).should == 'http://example.com/book/foo' }
it { @maker.instance_variable_get(:@files).should == ['foo.html', 'bar.html'] }
it {
@maker.instance_variable_get(:@nav).should == [
Expand All @@ -54,20 +56,22 @@
:uid=>{:value=>"http://example.com/book/foo", :scheme=>"URL", :id=>"http://example.com/book/foo"}
) { stub!.save }
mock(EeePub::OPF).new(
:title => ["sample"],
:creator => ["jugyo"],
:date => ["2010-05-06"],
:language => ['en'],
:subject => ['epub sample'],
:description => ['this is epub sample'],
:rights => ['xxx'],
:relation => ['xxx'],
:ncx => "toc.ncx",
:cover => 'cover.jpg',
:publisher => ["jugyo.org"],
:title=>["sample"],
:unique_identifier=>"http://example.com/book/foo",
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id => "http://example.com/book/foo"}],
:manifest => ['foo.html', 'bar.html']
:identifier=>[{:value=>"http://example.com/book/foo",:scheme=>"URL", :id=>"http://example.com/book/foo"}],
:creator=>["jugyo"],
:publisher=>["jugyo.org"],
:date=>["2010-05-06"],
:language=>["en"],
:subject=>["epub sample"],
:description=>["this is epub sample"],
:rights=>["xxx"],
:cover=>"cover.jpg",
:source=>"http://example.com/book/foo",
:relation=>["xxx"],
:manifest=>["foo.html", "bar.html"],
:ncx=>"toc.ncx",
:guide=>nil
) { stub!.save }
mock(EeePub::OCF).new(
:container => "content.opf",
Expand All @@ -94,6 +98,7 @@
ncx_file 'toc.ncx'
opf_file 'content.opf'
cover 'cover.jpg'
source 'http://example.com/book/foo'
files [{'foo.html' => 'foo/bar'}, {'bar.html' => 'foo/bar/baz'}]
nav [
{:label => '1. foo', :content => 'foo.html'},
Expand All @@ -108,20 +113,22 @@
mock(Dir).mktmpdir { '/tmp' }
mock(EeePub::NCX).new.with_any_args { stub!.save }
mock(EeePub::OPF).new(
:title => ["sample"],
:creator => ["jugyo"],
:date => ["2010-05-06"],
:language => ['en'],
:subject => ['epub sample'],
:description => ['this is epub sample'],
:rights => ['xxx'],
:relation => ['xxx'],
:ncx => "toc.ncx",
:cover => 'cover.jpg',
:publisher => ["jugyo.org"],
:unique_identifier=>"http://example.com/book/foo",
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id=>"http://example.com/book/foo"}],
:manifest => ["foo/bar/foo.html", "foo/bar/baz/bar.html"]
:title=>["sample"],
:unique_identifier=>"http://example.com/book/foo",
:identifier=>[{:value=>"http://example.com/book/foo", :scheme=>"URL", :id=>"http://example.com/book/foo"}],
:creator=>["jugyo"],
:publisher=>["jugyo.org"],
:date=>["2010-05-06"],
:language=>["en"],
:subject=>["epub sample"],
:description=>["this is epub sample"],
:rights=>["xxx"],
:cover=>"cover.jpg",
:source=>"http://example.com/book/foo",
:relation=>["xxx"],
:manifest=>["foo/bar/foo.html", "foo/bar/baz/bar.html"],
:ncx=>"toc.ncx",
:guide=>nil
) { stub!.save }
mock(EeePub::OCF).new.with_any_args { stub!.save }

Expand Down
4 changes: 3 additions & 1 deletion spec/eeepub/opf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
:creator => 'creator',
:publisher => 'publisher',
:rights => 'rights',
:cover => 'cover.jpg'
:cover => 'cover.jpg',
:source => 'source'
)
end

Expand All @@ -136,6 +137,7 @@
['dc:relation', 'relation'],
['dc:creator', 'creator'],
['dc:publisher', 'publisher'],
['dc:source', 'source'],
['dc:rights', 'rights'],
].each do |xpath, expect|
metadata.xpath(xpath,
Expand Down