class Ebookie::Rendering::Epub

Public Instance Methods

copy_cover() click to toggle source
# File lib/ebookie/rendering/epub.rb, line 12
def copy_cover
  if File.extname(document.cover) != '.png'
    raise "Cover file is not a valid png"
  end

  borrow document.cover.to_s, to: tmp_dir.join("OEBPS/images/cover.png")
end
process!() click to toggle source
# File lib/ebookie/rendering/epub.rb, line 20
def process!
  copy_cover if document.cover

  document.chapters.each do |chapter|
    render_erb_to_file template_file("OEBPS/chapter.erb"), tmp_dir.join("OEBPS/#{chapter.slug}.html"), chapter: chapter
  end

  unless Ebookie.logger.debug?
    Epzip.class_variable_set("@@zip_cmd_path", "zip -q")
  end

  zip = Epzip.zip( tmp_dir, output_path )

  validation = EpubValidator.check( output_path )
  if validation.valid?
    Ebookie.logger.info "Successfully compiled #{document.title} to epub"
  else
    Ebookie.logger.warn "Errors when compiling #{document.title} to epub"
    validation.messages.each do |m|
      Ebookie.logger.warn "~> #{m}"
    end
  end
end
sanitize(html) click to toggle source
# File lib/ebookie/rendering/epub.rb, line 44
def sanitize(html)
  html = html.dup
  {
    "<figure>"      => "<span class=\"figure\">",
    "</figure>"     => "</span>",
    "<figcaption>"  => "<span class=\"figcaption\">",
    "</figcaption>" => "</span>"
  }.each do |k,v|
    html.gsub! k, v
  end

  sanitize_html clean_images(html, Pathname.new("images"))
end