Class: EeePub::Easy

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

Overview

The class to make ePub more easily

Examples:

epub = EeePub::Easy.new do
  title 'sample'
  creator 'jugyo'
  identifier 'http://example.com/book/foo', :scheme => 'URL'
  uid 'http://example.com/book/foo'
end

epub.sections << ['1. foo', <<HTML]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
  <head>
    <title>foo</title>
  </head>
  <body>
    <p>
    foo foo foo foo foo foo
    </p>
  </body>
</html>
HTML

epub.assets << 'image.png'
epub.urls << ["http://path/to/image.png", "image.png"]

epub.save('sample.epub')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Maker

#identifier

Constructor Details

#initialize(&block) ⇒ Easy

Returns a new instance of Easy.

Parameters:

  • block (Proc)

    the block for initialize



38
39
40
41
42
43
# File 'lib/eeepub/easy.rb', line 38

def initialize(&block)
  @sections = []
  @assets = []
  @urls = []
  super
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



35
36
37
# File 'lib/eeepub/easy.rb', line 35

def assets
  @assets
end

#sectionsObject (readonly)

Returns the value of attribute sections.



35
36
37
# File 'lib/eeepub/easy.rb', line 35

def sections
  @sections
end

#urlsObject (readonly)

Returns the value of attribute urls.



35
36
37
# File 'lib/eeepub/easy.rb', line 35

def urls
  @urls
end

Instance Method Details

#save(filename) ⇒ Object

Save as ePub file

Parameters:

  • filename (String)

    the ePub file name to save



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/eeepub/easy.rb', line 48

def save(filename)
  Dir.mktmpdir do |dir|
    prepare(dir)

    NCX.new(
      :uid => @uid,
      :title => @titles[0],
      :nav => @nav
    ).save(File.join(dir, @ncx_file))

    OPF.new(
      :title => @titles,
      :identifier => @identifiers,
      :creator => @creators,
      :publisher => @publishers,
      :date => @dates,
      :language => @languages,
      :subject => @subjects,
      :description => @descriptions,
      :rights => @rightss,
      :relation => @relations,
      :manifest => @files.map{|i| File.basename(i)},
      :ncx => @ncx_file
    ).save(File.join(dir, @opf_file))

    OCF.new(
      :dir => dir,
      :container => @opf_file
    ).save(filename)
  end
end