• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

an ePub generation library in Ruby

Rpub -- an ePub generator in Ruby Build Status Coverage Status

Introduction

Rpub is a command-line tool that generates a collection of plain text input files into an eBook in ePub format. It provides several related functions to make working with ePub files a little easier:

  • Generation of table of contents
  • Packaging your eBook in an archive with additional README file
  • Embedding fonts
  • Easy previewing as you write
  • .mobi compatibility

Installation

Rpub is distributed as a Ruby gem, which should be installed on most Macs and Linux systems. Once you have ensured you have a working installation of Ruby and Ruby gems, install the gem as follows from the command line:

$ gem install rpub

You can verify the gem has installed correctly by checking its version number:

$ rpub -v

If this generates an error, something has gone wrong. You should see something along the lines of rpub 1.0.0.

Usage

Basics

ePubs are basically collections of HTML files, combined in a single archive according to a set of predefined rules. Rpub generates these files for you from simple text files written in Markdown, a very readable markup language created by John Gruber. This very README file is an example of a Markdown document.

The idea is you write several Markdown files using your favourite text editor, and save them as plain text in your project directory. Usually you would write one file per chapter. By invoking the rpub program you convert those files to HTML and combine them in an ePub archive:

$ rpub compile
Generating my-new-book-0.1.0.epub... Done!

After you have run the rpub compile command, you will find a new .epub file in your project directory. The name of this file depends on the title of your book, and its version number. You can set these values, as well as a few others, in a special configuration file called config.yml:

---
author: Your Name
title: My new book
version: 0.1.0

This file is written in YAML and sets basic properties of your book project.

Since regenerating your ePub file and opening it in a suitable reader application is cumbersome, Rpub can generate a simple preview document for you:

$ rpub preview

This will generate a new HTML file in your project directory with a name similar to your ePub file. This is the entire text of your book as a single web page for easy viewing in any browser.

Generating a .mobi file

Since the ePub and Mobipocket file formats are very (very) similar it is quite easy to create a .mobi version of your book, suitable for reading on Amazon's Kindle. To do so, you will need to install the kindlegen program Amazon provides.

Here's how it works:

  1. Install kindlegen (download it here)
  2. Compile your book as usual using rpub compile
  3. Compile my-book.epub to my-book.mobi: kindlegen my-book.epub.

Optionally, include your my-book.mobi in your package by adding it to your list of packaged files (see "Packaging for distribution").

Advanced features

Packaging for distribution

Often you want to distribute your ebook over the internet, along with some extra files. You'll probably want to include a README file, a license or references to extra online resources. A package task is defined to generate a single compressed archive file from your generated ebook along with such additional files.

You list the files to include with your ebook in your config.yml file, along with the resulting packaged file name:

---
package_file: mybook.zip
package:
  - README
  - license.txt
  - code-samples.rb

All the filenames listed under package are looked up in the root of your project directory. These files will be combined with the ebook in the mybook.zip file in your project directory.

Automatic table of contents

Rpub automatically generates a table of contents for you, if you want it to. It does this by scanning all your markdown files for headings and listing them on a single page in the ebook. Each entry in the table of contents is linked to its appropriate heading in the chapter, and has various hooks for your stylesheet to determine its formatting.

To enable the automatic generation of a table of contents, add the following configuration to your config.yml file:

toc: true

Note that this only affects the human-readable table of contents, represented as a page in your book. Rpub will alway generate the .epub table of contents for you, which contains the machine-readable references to your chapters. It will, by default, reference all chapter titles and subheadings for you, but you can customize the number of levels that will be included using the following in your config.yml file:

max_level: 3

Custom layout and styles

When you compile a set of Markdown files to an ePub file, rpub uses a default HTML layout and set of styles to determine the look and feel of the book. These will do fine for most cases, but you can provide your own, if you are so inclined.

Simply define a layout.html and/or styles.css in your project directory. Your HTML file will be parsed with Erb, an so you can include your writing using the @body instance variable:

<html>
<body>
  <%= @body %>
</body>
</html>

Note 1: this feature is actually provided by the Kramdown gem, so have a look at the standard Kramdown document template to see some nifty tricks.

Note 2: despite the name 'html' and .html extension, your file actually has to be XHTML-compliant.

You can also provide custom layouts or styles to use when invoking the compile or preview commands, using the -l or -s options:

$ rpub compile -l /tmp/my-layout.html

If you like the default layout or styles, but want to adapt them, you can copy those files into your project using the generate subcommand:

$ rpub generate

Command reference

rpub compile : generate .epub file

rpub package : create zip file with compiled book and other listed files

rpub preview : generate preview HTML file

rpub generate : copy default layout.html, styles.css and config.yml

rpub help : get help on subcommands

rpub clean : remove generated files

Configuration reference

title : the book title (string)

descrption : one-line summary of the book (string)

creator : author name (string)

publisher : publisher name (string)

subject : book subject/category (string)

language : language code of the book contents, e.g. 'en' (string)

rights : copyright line (string)

version : version number of the book to include in the .epub filename (string)

toc : whether to generate a table of contents as book page (boolean, default false)

max_level : the maximum depth of the .epub table of contents (number, default 2)

ignore : list of files not to include in the epub, that otherwise would (array)

package : list of files to be included in the archive created by the package task (array)

Examples

See the examples directory for two example projects.

Documentation

See the inline API docs for more information.

Other

Note on Patches/Pull Requests

  1. Fork the project.
  2. Make your feature addition or bug fix.
  3. Add tests for it. This is important so I don't break it in a future version unintentionally.
  4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  5. Send me a pull request. Bonus points for topic branches.

Issues

Please report any issues, defects or suggestions in the Github issue tracker.

What has changed?

See the HISTORY file for a detailed changelog.

Credits

Created by: Arjan van der Gaag
URL: http://arjanvandergaag.nl
Project homepage: http://avdgaag.github.com/rpub
Date: april 2012
License: MIT-license (same as Ruby)

More Repositories

1

nanoc-template

A simple template project for websites built with Nanoc
Ruby
81
star
2

typogruby

Improves web typography like Django's Typogrify
Ruby
51
star
3

vim-phoenix

Vim plugin for working with the Phoenix framework
Vim Script
30
star
4

rspec-caching-test-plugin

Simplifies testing your Rails app’s caching with Rspec
Ruby
25
star
5

dotfiles

Various configuration files to set up a shell env how I like it.
Vim Script
18
star
6

nanoc-cachebuster

Adds cache-busting capabilities to Nanoc
Ruby
17
star
7

stationed

Rails application generator and scaffold templates
Ruby
11
star
8

bol

A simple Ruby wrapper around the bol.com developer API
Ruby
10
star
9

vim-lotus

Vim plugin for working with Lotus projects
Vim Script
9
star
10

projectile-hanami

Projectile Hanami is an Emacs minor mode, based on Projectile, for navigating Hanami projects.
Emacs Lisp
9
star
11

heroku-api

Node.js wrapper around the Heroku API
JavaScript
8
star
12

wally

Status wall application in Elixir, Phoenix and React
Elixir
7
star
13

arjanvandergaag.nl

My personal blog, generated using nanoc
JavaScript
7
star
14

acts_as_publishable

Rails plugin for working with model publication dates
Ruby
6
star
15

rocks

This is a tiny library of mixins and styles for developing large-ish stylesheets with Sass
Ruby
6
star
16

a

My personal toolbelt based on 37signal's sub
Shell
6
star
17

phoenix-todo-list

Demo of React and Flux over websockets with Elixir and Phoenix backend
Elixir
5
star
18

gleam_ag_html

A Gleam library for building HTML strings usings functions.
Gleam
4
star
19

has_comments

A Ruby on Rails plugin that provides commenting on ActiveRecord models.
Ruby
4
star
20

example_json_parser

Example project about leex and yecc in Elixir
Elixir
4
star
21

vim-rbfactor

Functions to refactor Ruby programs with Vim
Vim Script
4
star
22

agw-toolbox

Tools, patterns and settings I frequently use in Rails projects packed into one plugin.
Ruby
3
star
23

laze

A simple static site generator
Ruby
3
star
24

perch-tmbundle

A bundle of handy snippets for working with Perch
2
star
25

oo

A few simple helper methods for writing Object-Oriented javascript
JavaScript
2
star
26

phabric

A very simple PHP micro-framework
PHP
2
star
27

redmine-api

A simple Redmine command line API client
Ruby
2
star
28

observatory

A simple implementation of the observer pattern for Ruby programs.
Ruby
2
star
29

tagger

Hacky sinatra app to tag URLs with Google Analytics variables (WiP)
Ruby
2
star
30

yard-minitest

Include Minitest test case descriptions in your class documentation.
Ruby
2
star
31

storyteller

A web app for collaboratively writing user stories, and then exporting them to Pivotal Tracker or Cucumber feature files. A work-in-progress.
Ruby
2
star
32

shortener

A tiny, personal URL shortener, powered by Sinatra and a JSON file as storage.
Ruby
2
star
33

miniflux

Toy implentation of Facebooks Flux SPA architecture
JavaScript
1
star
34

contact

A simple contact form callback app (WiP)
Ruby
1
star
35

tailwindcss-prefers-color-scheme

A Tailwind CSS plugin for adding variants using the prefers-color-scheme media feature.
JavaScript
1
star
36

rupt

A command-line client for the Pivotal Tracker API
Ruby
1
star
37

mutil

A tiny javascript utility belt
JavaScript
1
star
38

avdgaag.github.com

Github user page
CSS
1
star
39

bare-theme

An empty WordPress theme for kick-starting WP-powered websites
PHP
1
star
40

subcheat

Cheat Subversion with some extra commands for common use cases.
Ruby
1
star
41

rails-sql-mode

Quickly launch database prompt in Emacs for Rails projects
Emacs Lisp
1
star
42

cordova-backbone-boilerplate

A project template for Cordova applications with Backbone.js
JavaScript
1
star
43

i18n.js

Simple i18n for client-side javascript
CoffeeScript
1
star
44

website-template

Kickstart a web design project with these folders, files and styles β€” ready to customize.
1
star
45

calgen

A simple library for generating monthly calendars in PHP.
PHP
1
star
46

testy

An excercise in creating a simple Rspec-like testing framework in Coffee script
CoffeeScript
1
star
47

subtrigger

Create post-commit triggers for Subversion commit messages
Ruby
1
star
48

formatter

Simple Sinatra app to apply text filters
Ruby
1
star
49

lotus-demo

Example blog application with Lotus
Ruby
1
star
50

Typography-tmbundle

A TextMate bundle to help improve web typography
1
star
51

ardown

Toy Markdown implementation in Ruby.
Ruby
1
star