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.save('sample.epub')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Maker

#identifier, #render

Constructor Details

#initialize(&block) ⇒ Easy

Returns a new instance of Easy.

Parameters:

  • block (Proc)

    the block for initialize


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

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

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets


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

def assets
  @assets
end

#sectionsObject (readonly)

Returns the value of attribute sections


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

def sections
  @sections
end

Instance Method Details

#save(filename) ⇒ Object

Save as ePub file

Parameters:

  • filename (String)

    the ePub file name to save


46
47
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
# File 'lib/eeepub/easy.rb', line 46

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