lib/softcover/builders/epub.rb in softcover-1.1.4 vs lib/softcover/builders/epub.rb in softcover-1.1.6
- old
+ new
@@ -34,10 +34,17 @@
end
# Returns a content.opf file based on a valid template.
def content_opf_template(title, copyright, author, uuid, cover_id,
toc_chapters, manifest_chapters, images)
+ if cover_id
+ cover_meta = %(<meta name="cover" content="#{cover_id}"/>)
+ cover_html = '<item id="cover" href="cover.html" media-type="application/xhtml+xml"/>'
+ cover_ref = '<itemref idref="cover" linear="no" />'
+ else
+ cover_meta = cover_html = cover_ref = ''
+ end
%(<?xml version="1.0" encoding="UTF-8"?>
<package unique-identifier="BookID" version="3.0" xmlns="http://www.idpf.org/2007/opf">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>#{escape(title)}</dc:title>
@@ -45,27 +52,27 @@
<dc:rights>Copyright (c) #{copyright} #{escape(author)}</dc:rights>
<dc:creator>#{author}</dc:creator>
<dc:publisher>Softcover</dc:publisher>
<dc:identifier id="BookID">urn:uuid:#{uuid}</dc:identifier>
<meta property="dcterms:modified">#{Time.now.strftime('%Y-%m-%dT%H:%M:%S')}Z</meta>
- <meta name="cover" content="#{cover_id}"/>
+ #{cover_meta}
</metadata>
<manifest>
<item href="nav.html" id="nav" media-type="application/xhtml+xml" properties="nav"/>
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
<item id="page-template.xpgt" href="styles/page-template.xpgt" media-type="application/vnd.adobe-page-template+xml"/>
<item id="pygments.css" href="styles/pygments.css" media-type="text/css"/>
<item id="softcover.css" href="styles/softcover.css" media-type="text/css"/>
<item id="epub.css" href="styles/epub.css" media-type="text/css"/>
<item id="custom.css" href="styles/custom.css" media-type="text/css"/>
<item id="custom_epub.css" href="styles/custom_epub.css" media-type="text/css"/>
- <item id="cover" href="cover.html" media-type="application/xhtml+xml"/>
+ #{cover_html}
#{manifest_chapters.join("\n")}
#{images.join("\n")}
</manifest>
<spine toc="ncx">
- <itemref idref="cover" linear="no" />
+ #{cover_ref}
#{toc_chapters.join("\n")}
</spine>
</package>
)
end
@@ -498,10 +505,10 @@
</html>
)
end
def cover_id
- "img-#{cover_img.sub('.', '-')}"
+ cover? ? "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