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

Passing Rspec Tests and Rubyzip upgrade #34

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
EeePub
======

EeePub is a Ruby ePub generator.
EeePub is a Ruby ePub generator. This is a version of the eepub project from https://github.com/jugyo/eeepub, and had been modified to suit Inkshares' needs. Main enhancements include:

- Compatibility with Ruby 2.0
- Compatibility with the latest version of Rubyzip (required to bundle epub files)
- Support for the 'guide' ocf attribute, which allows an ebook maker to specify an HTML page for the book cover.
- Passing unit tests

Also of note, this project does not produce .mobi files for Kindle. But, we recommend a very excellent service called Ebook Glue, https://ebookglue.com/, which provides an affordable API to convert .epub into .mobi files.

Usage
-------
Expand Down Expand Up @@ -68,9 +75,9 @@ Links
-------

* Documentation: [http://yardoc.org/docs/jugyo-eeepub](http://yardoc.org/docs/jugyo-eeepub)
* Source code: [http://github.com/jugyo/eeepub](http://github.com/jugyo/eeepub)
* Source code: [http://github.com/inkshares/eeepub](http://github.com/inkshares/eeepub)

Copyright
-------

Copyright (c) 2010 jugyo. See LICENSE for details.
Copyright (c) 2014 Inkshares. See LICENSE for details.
2 changes: 2 additions & 0 deletions lib/eeepub/container_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def guess_media_type(filename)
'application/x-dtbncx+xml'
when /.*\.opf$/i
'application/oebps-package+xml'
when /.*\.otf$/i
'application/x-font-otf'
end
end

Expand Down
16 changes: 15 additions & 1 deletion lib/eeepub/ocf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def save(output_path)

create_epub do
mimetype = Zip::ZipOutputStream::open(output_path) do |os|
os.put_next_entry("mimetype", nil, nil, Zip::ZipEntry::STORED, Zlib::NO_COMPRESSION)
os.put_next_entry("mimetype")
os << "application/epub+zip"
end
zipfile = Zip::ZipFile.open(output_path)
Expand Down Expand Up @@ -123,9 +123,23 @@ def create_epub
FileUtils.mkdir_p(meta_inf)

container.save(File.join(meta_inf, 'container.xml'))
write_ibook_font_file(meta_inf)
yield
end
end

def write_ibook_font_file(meta_inf)
content = %Q|
<?xml version="1.0" encoding="UTF-8"?>
<display_options>
<platform name="*">
<option name="specified-fonts">true</option>
</platform>
</display_options>
|
File.open(File.join(meta_inf,'com.apple.ibooks.display-options.xml'),'w') do |file|
file.write(content.strip)
end
end
end
end
15 changes: 10 additions & 5 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'
guide 'xxx'
files ['foo.html', 'bar.html']
nav [
{:label => '1. foo', :content => 'foo.html'},
Expand Down Expand Up @@ -53,21 +54,23 @@
],
:uid=>{:value=>"http://example.com/book/foo", :scheme=>"URL", :id=>"http://example.com/book/foo"}
) { stub!.save }

mock(EeePub::OPF).new(
: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',
:relation => ['xxx'],
:manifest => ['foo.html', 'bar.html'],
: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.html', 'bar.html']
:guide => 'xxx'
) { stub!.save }
mock(EeePub::OCF).new(
:container => "content.opf",
Expand All @@ -89,6 +92,7 @@
description 'this is epub sample'
rights 'xxx'
relation 'xxx'
guide 'xxx'
identifier 'http://example.com/book/foo', :scheme => 'URL'
uid 'http://example.com/book/foo'
ncx_file 'toc.ncx'
Expand Down Expand Up @@ -117,6 +121,7 @@
:rights => ['xxx'],
:relation => ['xxx'],
:ncx => "toc.ncx",
:guide => 'xxx',
:cover => 'cover.jpg',
:publisher => ["jugyo.org"],
:unique_identifier=>"http://example.com/book/foo",
Expand Down