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'
  toc_page    '/path/to/toc.html', :title => 'Contents'
  cover_page  '/path/to/cover.jpg', :title => 'Cover Image'

  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

Returns a new instance of Maker.

Parameters:

  • block (Proc)

    the block for initialize



75
76
77
78
79
80
81
82
# File 'lib/eeepub/maker.rb', line 75

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



69
70
71
72
# File 'lib/eeepub/maker.rb', line 69

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})



95
96
97
# File 'lib/eeepub/maker.rb', line 95

def render
  create_epub.render
end

#save(filename) ⇒ Object

Save as ePub file

Parameters:

  • filename (String)

    the ePub file name to save



87
88
89
# File 'lib/eeepub/maker.rb', line 87

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