Class: EeePub::Maker

Inherits:
Object
  • Object
show all
Defined in:
lib/eeepub/maker.rb

Overview

The class to make ePub easily

Note on unique identifiers:

At least one 'identifier' must be the unique identifer represented by the name
given to 'uid' and set via the hash option :id => {name}.  The default name for
uid is 'BookId' and doesn't need to be specified explicitly.  If no identifier is
marked as the unique identifier, the first one give will be chosen.

Examples:

epub = EeePub.make do
  title       'sample'
  creator     'jugyo'
  publisher   'jugyo.org'
  date        '2010-05-06'
  uid         'BookId'
  identifier  'http://example.com/book/foo', :scheme => 'URL', :id => 'BookId'

  files ['/path/to/foo.html', '/path/to/bar.html']
  nav [
    {:label => '1. foo', :content => 'foo.html', :nav => [
      {:label => '1.1 foo-1', :content => 'foo.html#foo-1'}
    ]},
    {:label => '1. bar', :content => 'bar.html'}
  ]
end
epub.save('sample.epub')

Direct Known Subclasses

Easy

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Maker


72
73
74
75
76
77
78
79
# File 'lib/eeepub/maker.rb', line 72

def initialize(&block)
  @files ||= []
  @nav ||= []
  @ncx_file ||= 'toc.ncx'
  @opf_file ||= 'content.opf'

  instance_eval(&block) if block_given?
end

Instance Method Details

#identifier(id, options) ⇒ Object


66
67
68
69
# File 'lib/eeepub/maker.rb', line 66

def identifier(id, options)
  @identifiers ||= []
  @identifiers << {:value => id, :scheme => options[:scheme], :id => options[:id]}
end

#renderObject

instead of saving to file, output the file contents. important for serving on-the-fly doc creation from web interface where we don't want to allow file system writes (Heroku, et al.)


92
93
94
# File 'lib/eeepub/maker.rb', line 92

def render
  create_epub.render
end

#save(filename) ⇒ Object

Save as ePub file


84
85
86
# File 'lib/eeepub/maker.rb', line 84

def save(filename)
  create_epub.save(filename)
end