Class: Rpub::Epub

Inherits:
Object
  • Object
show all
Defined in:
lib/rpub/epub.rb,
lib/rpub/epub/toc.rb,
lib/rpub/epub/cover.rb,
lib/rpub/epub/content.rb,
lib/rpub/epub/html_toc.rb,
lib/rpub/epub/container.rb

Defined Under Namespace

Classes: Container, Content, Cover, HtmlToc, Toc

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Epub) initialize(book, styles)

A new instance of Epub



6
7
8
# File 'lib/rpub/epub.rb', line 6

def initialize(book, styles)
  @book, @styles = book, styles
end

Instance Attribute Details

- (Object) book (readonly)

Returns the value of attribute book



4
5
6
# File 'lib/rpub/epub.rb', line 4

def book
  @book
end

- (Object) styles (readonly)

Returns the value of attribute styles



4
5
6
# File 'lib/rpub/epub.rb', line 4

def styles
  @styles
end

Instance Method Details

- (Object) manifest_in(target)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rpub/epub.rb', line 10

def manifest_in(target)
  target.store_file 'mimetype', 'application/epub+zip'
  target.compress_file 'META-INF/container.xml', Container.new
  target.compress_file 'OEBPS/content.opf',      Content.new(book)
  target.compress_file 'OEBPS/toc.ncx',          Toc.new(book)
  target.compress_file 'OEBPS/styles.css',       styles
  if book.has_cover?
    target.compress_file 'OEBPS/cover.html', Cover.new(book)
    target.compress_file File.join('OEBPS', book.config.cover_image), read(book.config.cover_image)
  end
  if book.has_toc?
    target.compress_file 'OEBPS/toc.html', toc { HtmlToc.new(book).render }
  end
  if book.has_fonts?
    book.fonts.each do |font|
      target.compress_file File.join('OEBPS', font), read(font)
    end
  end
  book.each do |chapter|
    target.compress_file File.join('OEBPS', chapter.filename), chapter.to_html
  end
  book.images.each do |image|
    target.compress_file File.join('OEBPS', image), read(image)
  end
end