Bookbinder

With Bookbinder you can convert content to common ebook formats.

Basic use

Out of the box, Bookbinder supports only its native format: Openbook. Openbook is a simple JSON-based format that acts as a superset of all the information in other formats.

So, you should install some more formats, by adding other gems to your Gemfile:

gem 'bookbinder'
gem 'bb-epub'
gem 'bb-pdf'

Now do this:

$ bundle console

>> puts Bookbinder::Operations.map('test.epub')

This displays the contents of the test EPUB as a JSON "map". (Supply your own test EPUB file.)

Convert an EPUB to an Openbook directory (the directory need not exist yet):

>> Bookbinder::Operations.convert('test.epub', 'test-output')

Convert an EPUB to an Openbook archive:

>> Bookbinder::Operations.convert('test.epub', 'test.openbook')

Convert an Openbook to an EPUB (...is not yet fully implemented!)

Convert a PDF to an Openbook archive:

>> Bookbinder::Operations.convert('test.pdf', 'test.openbook')

Convert an openbook to a PDF (..is not yet fully implemented!)

Improving Bookbinder

Inside Bookbinder, a "book" is simply a nested hash of properties and values. This hash is called "the map". Properties of the map that are transferrable between ebook package formats should follow the Openbook convention, which is currently maintained here:

https://gist.github.com/joseph/7303930

The key to Bookbinder is this: for every feature of an ebook format, we create a "transform" class that does two things:

  • parses the raw config from the package into standard Openbook properties on the map; and
  • generates raw config into the package from those same standard Openbook properties on the map

Basically, for every feature, the transform class describes how to read it, and how to write it.

The nice thing about this set-up is that if multiple package formats support the same feature, their transform classes work on the same map. Say you are converting from EPUB3 to Openbook - the book's title is parsed out of the EPUB file into the map using the 'Title' transform in the bb-epub gem. Then the map is handed over to the Openbook package, and the transform in the Bookbinder package writes it out to the new package file.

You can of course convert a package to its own format: in this case the same transform class does both the reading and the writing out -- the effect of this is to "tidy" the package.

To add a package format to Bookbinder, you can borrow the simple structure of the bb-epub and bb-pdf gems.

Planned format support

  • Openbook
  • EPUB3
  • EPUB2
  • PDF
  • MP3 audiobooks
  • hPub

Attribution and licensing

Bookbinder was originally developed at OverDrive, Inc. Released under the MIT License. See MIT-LICENSE in this directory.