- zip.writestr('META-INF/container.xml', '<?xml version="1.0" ?><container version="1.0" ' \
- 'xmlns="urn:oasis:names:tc:opendocument:xmlns:container">' \
- '<rootfiles><rootfile full-path="OPS/content.opf" ' \
- 'media-type="application/oebps-package+xml" />' \
- '</rootfiles></container>')
- zip.write(get_resource('epub/style.css'), os.path.join('OPS', 'style.css'))
- zip.write(get_resource('res/wl-logo-small.png'), os.path.join('OPS', 'logo_wolnelektury.png'))
-
- opf = xslt(metadata, get_resource('epub/xsltContent.xsl'))
- manifest = opf.find('.//' + OPFNS('manifest'))
- spine = opf.find('.//' + OPFNS('spine'))
+ zip.writestr(
+ 'META-INF/container.xml',
+ '<?xml version="1.0" ?>'
+ '<container version="1.0" '
+ 'xmlns="urn:oasis:names:tc:opendocument:xmlns:container">'
+ '<rootfiles><rootfile full-path="OPS/content.opf" '
+ 'media-type="application/oebps-package+xml" />'
+ '</rootfiles></container>'
+ )
+ zip.write(get_resource('res/wl-logo-small.png'),
+ os.path.join('OPS', 'logo_wolnelektury.png'))
+ zip.write(get_resource('res/jedenprocent.png'),
+ os.path.join('OPS', 'jedenprocent.png'))
+ if not style:
+ style = get_resource('epub/style.css')
+ zip.write(style, os.path.join('OPS', 'style.css'))
+
+ if cover:
+ if cover is True:
+ cover = DefaultEbookCover
+
+ cover_file = StringIO()
+ bound_cover = cover(document.book_info)
+ bound_cover.save(cover_file)
+ cover_name = 'cover.%s' % bound_cover.ext()
+ zip.writestr(os.path.join('OPS', cover_name), cover_file.getvalue())
+ del cover_file
+
+ cover_tree = etree.parse(get_resource('epub/cover.html'))
+ cover_tree.find('//' + XHTMLNS('img')).set('src', cover_name)
+ zip.writestr('OPS/cover.html', etree.tostring(
+ cover_tree, pretty_print=True, xml_declaration=True,
+ encoding="utf-8",
+ doctype='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" ' +
+ '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
+ ))
+
+ if bound_cover.uses_dc_cover:
+ if document.book_info.cover_by:
+ document.edoc.getroot().set('data-cover-by', document.book_info.cover_by)
+ if document.book_info.cover_source:
+ document.edoc.getroot().set('data-cover-source', document.book_info.cover_source)