Class: Ebookie::Rendering::Epub
- Inherits:
-
Base
- Object
- Base
- Ebookie::Rendering::Epub
show all
- Defined in:
- lib/ebookie/rendering/epub.rb
Constant Summary
Constants inherited
from Base
Base::IMAGE_SRC_REGEX
Instance Attribute Summary
Attributes inherited from Base
#document
Instance Method Summary
collapse
Methods inherited from Base
#clean_images, #format, format, inherited, #initialize, #output_path, #render, #render_erb_to_file, #sanitize_html, set, #template_dir, #template_file, #tmp_dir
Instance Method Details
#copy_cover ⇒ Object
12
13
14
15
16
17
18
|
# 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! ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# 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) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# 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
|