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

Returns a new instance of Maker.

Parameters:

  • block (Proc) —

    the block for initialize



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

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



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

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

#render ⇒ Object

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



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

def render
  create_epub.render
end

#save(filename) ⇒ Object

Save as ePub file

Parameters:

  • filename (String) —

    the ePub file name to save



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

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