lib/softcover/builders/epub.rb in softcover-1.1.6 vs lib/softcover/builders/epub.rb in softcover-1.1.7
- old
+ new
@@ -1,7 +1,6 @@
module Softcover
-
module EpubUtils
# Returns the name of the cover file.
# We support (in order) JPG/JPEG, PNG, and TIFF.
def cover_img
@@ -15,12 +14,17 @@
end
end
return false
end
- def cover?
- cover_img
+ # Returns true when producing a cover.
+ # We include a cover when not producing an Amazon-specific book
+ # as long as there's a cover image. (When uploading a book to
+ # Amazon KDP, the cover gets uploaded separately, so the MOBI file itself
+ # should have not have a cover.)
+ def cover?(options={})
+ !options[:amazon] && cover_img
end
def cover_img_path
path("#{images_dir}/#{cover_img}")
end
@@ -139,11 +143,11 @@
write_ibooks_xml
write_toc
write_nav
copy_image_files
write_html(options)
- write_contents
+ write_contents(options)
create_style_files(options)
make_epub(options)
move_epub
end
@@ -192,12 +196,12 @@
File.write(path("epub/META-INF/#{xml_filename}"), ibooks_xml)
end
# Writes the content.opf file.
# This is required by the EPUB standard.
- def write_contents
- File.write(path('epub/OEBPS/content.opf'), content_opf)
+ def write_contents(options={})
+ File.write(path('epub/OEBPS/content.opf'), content_opf(options))
end
# Returns the chapters to write.
def chapters
preview? ? manifest.preview_chapters : manifest.chapters
@@ -209,11 +213,11 @@
def write_html(options={})
texmath_dir = File.join(images_dir, 'texmath')
mkdir images_dir
mkdir texmath_dir
- File.write(path('epub/OEBPS/cover.html'), cover_page) if cover?
+ File.write(path('epub/OEBPS/cover.html'), cover_page) if cover?(options)
pngs = []
chapters.each_with_index do |chapter, i|
target_filename = path("epub/OEBPS/#{chapter.fragment_name}")
File.open(target_filename, 'w') do |f|
@@ -462,11 +466,11 @@
</platform>
</display_options>)
end
# Returns the content configuration file.
- def content_opf
+ def content_opf(options={})
man_ch = chapters.map do |chapter|
%(<item id="#{chapter.slug}" href="#{chapter.fragment_name}" media-type="application/xhtml+xml"/>)
end
toc_ch = chapters.map do |chapter|
%(<itemref idref="#{chapter.slug}"/>)
@@ -484,11 +488,11 @@
label = File.basename(image).gsub('.', '-')
id = "img-#{label}"
%(<item id="#{id}" href="#{href}" media-type="image/#{ext}"/>)
end
content_opf_template(manifest.title, manifest.copyright,
- manifest.author, manifest.uuid, cover_id,
+ manifest.author, manifest.uuid, cover_id(options),
toc_ch, man_ch, images)
end
def cover_page
%(<?xml version="1.0" encoding="utf-8"?>
@@ -504,11 +508,11 @@
</body>
</html>
)
end
- def cover_id
- cover? ? "img-#{cover_img.sub('.', '-')}" : nil
+ def cover_id(options)
+ cover?(options) ? "img-#{cover_img.sub('.', '-')}" : nil
end
# Returns the Table of Contents for the spine.
def toc_ncx
chapter_nav = []
\ No newline at end of file