Class: Peregrin::Epub

Inherits:
Object
  • Object
show all
Defined in:
lib/formats/epub.rb

Defined Under Namespace

Classes: FailureLoadingNCX, FailureLoadingOCF, FailureLoadingOPF, FileNotFound, NotAZipArchive, ValidationError

Constant Summary

FORMAT =
"EPUB"
NAMESPACES =
{
  :ocf => { 'ocf' => 'urn:oasis:names:tc:opendocument:xmlns:container' },
  :opf => { 'opf' => 'http://www.idpf.org/2007/opf' },
  :dc => { 'dc' => 'http://purl.org/dc/elements/1.1/' },
  :ncx => { 'ncx' => 'http://www.daisy.org/z3986/2005/ncx/' },
  :svg => { 'svg' => 'http://www.w3.org/2000/svg' }
}
OCF_PATH =
"META-INF/container.xml"
HTML5_TAGNAMES =

FIXME: Which to divify? Which to leave as-is?

%w[section nav article aside hgroup header footer figure figcaption]
MIMETYPE_MAP =
{
  '.xhtml' => 'application/xhtml+xml',
  '.odt' => 'application/x-dtbook+xml',
  '.odt' => 'application/x-dtbook+xml',
  '.ncx' => 'application/x-dtbncx+xml',
  '.epub' => 'application/epub+zip'
}
OEBPS =
"OEBPS"
NCX =
'content'
OPF =
'content'

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Epub) initialize(book, epub_path = nil)



52
53
54
55
56
57
# File 'lib/formats/epub.rb', line 52

def initialize(book, epub_path = nil)
  @book = book
  if epub_path
    load_from_path(epub_path)
  end
end

Class Method Details

+ (Object) read(path)



46
47
48
49
# File 'lib/formats/epub.rb', line 46

def self.read(path)
  book = Peregrin::Book.new
  new(book, path)
end

+ (Object) validate(path)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/formats/epub.rb', line 26

def self.validate(path)
  raise FileNotFound.new(path)  unless File.file?(path)
  begin
    zf = Zip::Archive.open(path)
  rescue => e
    raise NotAZipArchive.new(path)
  end

  begin
    book = Peregrin::Book.new
    epub = new(book)
    epub.send(:load_config_documents, zf)
  rescue => e
    raise e.class.new(path)
  end
ensure
  zf.close  if zf
end

Instance Method Details

- (Object) to_book(options = {})



71
72
73
# File 'lib/formats/epub.rb', line 71

def to_book(options = {})
  bk = @book.deep_clone
end

- (Object) write(path)



60
61
62
63
64
65
66
67
68
# File 'lib/formats/epub.rb', line 60

def write(path)
  with_working_dir(path) {
    build_ocf
    build_ncx
    write_components
    build_opf
    zip_it_up(File.basename(path))
  }
end