X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/db91f942ce46e3af1420f3469a83257ef5aca4c2..28532fa3b437bb36b9d5c582851d3cdcf8d772ab:/src/librarian/builders/epub.py diff --git a/src/librarian/builders/epub.py b/src/librarian/builders/epub.py index 91405c3..902b460 100644 --- a/src/librarian/builders/epub.py +++ b/src/librarian/builders/epub.py @@ -9,7 +9,6 @@ from librarian.cover import make_cover from librarian.embeds.mathml import MathML import librarian.epub from librarian.fonts import strip_font -from librarian.fundraising import FUNDRAISING @@ -30,9 +29,11 @@ class Xhtml: class Builder: file_extension = None - def __init__(self, base_url=None): + def __init__(self, base_url=None, fundraising=None, cover=None): self._base_url = base_url or 'file:///home/rczajka/for/fnp/librarian/temp~/maly/img/' + self.fundraising = fundraising self.footnotes = etree.Element('div', id='footnotes') + self.make_cover = cover or make_cover self.cursors = { # None: None, @@ -78,6 +79,7 @@ class Builder: class EpubBuilder(Builder): file_extension = 'epub' + isbn_field = 'isbn_epub' def __init__(self, *args, **kwargs): self.chars = set() @@ -109,7 +111,6 @@ class EpubBuilder(Builder): self.set_metadata() - self.add_cover() self.add_title_page() @@ -140,21 +141,21 @@ class EpubBuilder(Builder): self.add_support_page() self.add_last_page() + if self.fundraising: + e = len(self.output.spine) - 3 - 3 + nfunds = len(self.fundraising) + if e > 4 * nfunds: + nfunds *= 2 - e = len(self.output.spine) - 3 - 3 - nfunds = len(FUNDRAISING) - if e > 16: - nfunds *= 2 - - # COUNTING CHARACTERS? - for f in range(nfunds): - spine_index = int(4 + (f / nfunds * e) + f) + # COUNTING CHARACTERS? + for f in range(nfunds): + spine_index = int(4 + (f / nfunds * e) + f) - h = Xhtml() - h.body.append( - etree.XML('
' + FUNDRAISING[f % len(FUNDRAISING)] + '
') - ) - self.add_html(h.element, file_name='fund%d.xhtml' % f, spine=spine_index) + h = Xhtml() + h.body.append( + etree.XML('
' + self.fundraising[f % len(self.fundraising)] + '
') + ) + self.add_html(h.element, file_name='fund%d.xhtml' % f, spine=spine_index) self.add_fonts() @@ -202,7 +203,7 @@ class EpubBuilder(Builder): def add_title_page(self): html = Xhtml() html.title.text = "Strona tytułowa" - bt = etree.SubElement(html.body, 'div', **{'class': 'book-text'}) + bt = etree.SubElement(html.body, 'div', **{'id': 'book-text'}) tp = etree.SubElement(bt, 'div', **{'class': 'title-page'}) # Tak jak jest teraz – czy może być jednocześnie @@ -212,10 +213,10 @@ class EpubBuilder(Builder): e = self.document.tree.find('//autor_utworu') if e is not None: - etree.SubElement(tp, 'h2', **{'class': 'author'}).text = e.raw_printable_text() + etree.SubElement(tp, 'h2', **{'class': 'author'}).text = e.raw_printable_text(self) e = self.document.tree.find('//nazwa_utworu') if e is not None: - etree.SubElement(tp, 'h1', **{'class': 'title'}).text = e.raw_printable_text() + etree.SubElement(tp, 'h1', **{'class': 'title'}).text = e.raw_printable_text(self) if not len(tp): for author in self.document.meta.authors: @@ -251,8 +252,8 @@ class EpubBuilder(Builder):

""")) - if self.document.meta.isbn_epub: - etree.SubElement(tp, 'p', **{"class": "info"}).text = self.document.meta.isbn_epub + if getattr(self.document.meta, self.isbn_field): + etree.SubElement(tp, 'p', **{"class": "info"}).text = getattr(self.document.meta, self.isbn_field) tp.append(etree.XML("""