From ccf0fe0599c3b60bcf875c1ebdb80270bd718ff4 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Fri, 21 Aug 2009 16:43:29 +1200 Subject: [PATCH] add end_matter generation and share with inside_cover code --- config.py | 1 + fmbook.py | 71 ++++++++++++++++++++++++++---------- objavi2.py | 1 - templates/end_matter.en.html | 18 +++++++++ templates/inside-front-cover.en.html | 6 +-- 5 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 templates/end_matter.en.html diff --git a/config.py b/config.py index aaae53a..5c00a22 100644 --- a/config.py +++ b/config.py @@ -182,6 +182,7 @@ ENGINES = { } INSIDE_FRONT_COVER_TEMPLATE = 'templates/inside-front-cover.%s.html' +END_MATTER_TEMPLATE = 'templates/end_matter.%s.html' FONT_LIST_INCLUDE = 'cache/font-list.inc' FONT_LIST_URL = '/font-list.cgi.pdf' diff --git a/fmbook.py b/fmbook.py index 97a7f69..b525877 100644 --- a/fmbook.py +++ b/fmbook.py @@ -381,6 +381,9 @@ class Book(object): self.body_index_file = self.filepath('body.txt') self.preamble_html_file = self.filepath('preamble.html') self.preamble_pdf_file = self.filepath('preamble.pdf') + self.tail_html_file = self.filepath('tail.html') + self.tail_pdf_file = self.filepath('tail.pdf') + self.isbn_pdf_file = None self.pdf_file = self.filepath('final.pdf') self.publish_name = bookname @@ -474,6 +477,7 @@ class Book(object): def make_preamble_pdf(self): contents = self.make_contents() + inside_cover_html = self.compose_inside_cover() html = ('\n' '\n' '\n' @@ -483,7 +487,7 @@ class Book(object): '
%s
\n' '
.' '
' - ) % (self.dir, self.css_url, self.title, self.inside_cover_html, + ) % (self.dir, self.css_url, self.title, inside_cover_html, contents, self.title) self.save_data(self.preamble_html_file, html) @@ -504,7 +508,12 @@ class Book(object): self.wait_for_xvfb() self.make_body_pdf() self.make_preamble_pdf() - concat_pdfs(self.pdf_file, self.preamble_pdf_file, self.body_pdf_file) + self.make_end_matter_pdf() + + concat_pdfs(self.pdf_file, self.preamble_pdf_file, + self.body_pdf_file, self.tail_pdf_file, + self.isbn_pdf_file) + self.notify_watcher('concatenated_pdfs') #and move it into place (what place?) @@ -737,32 +746,54 @@ class Book(object): self.title = 'A Manual About ' + self.book return self.title - def compose_inside_cover(self, license=config.DEFAULT_LICENSE, isbn=None): - """create the markup for the preamble inside cover, storing it - in self.inside_cover_html.""" - #XXX this should go in make_preamble_pdf, but that needs to be extracted from make_pdf - - if isbn: - isbn_text = 'ISBN : %s
' % isbn - #XXX make a barcode - else: - isbn_text = '' - - for lang in (self.lang, 'en'): + def _read_localised_template(self, template, fallbacks=['en']): + """Try to get the template in the approriate language, otherwise in english.""" + for lang in [self.lang] + fallbacks: try: - fn = INSIDE_FRONT_COVER_TEMPLATE % (lang) + fn = template % (lang) f = open(fn) + break except IOError, e: log("couldn't open inside front cover for lang %s (filename %s)" % (lang, fn)) log(e) - template = f.read() f.close() + return template + + def compose_inside_cover(self): + """create the markup for the preamble inside cover.""" + template = self._read_localised_template(config.INSIDE_FRONT_COVER_TEMPLATE) + + if self.isbn: + isbn_text = 'ISBN : %s
' % self.isbn + else: + isbn_text = '' + + return template % {'date': time.strftime('%Y-%m-%d'), + 'isbn': isbn_text, + 'license': self.license, + } + + + def compose_end_matter(self): + """create the markup for the end_matter inside cover. If + self.isbn is not set, the html will result in a pdf that + spills onto two pages. + """ + template = self._read_localised_template(config.END_MATTER_TEMPLATE) + + d = {'css_url': self.css_url, + 'title': self.title + } + + if self.isbn: + d['inside_cover_style'] = '' + else: + d['inside_cover_style'] = 'page-break-after: always' + + return template % d + - self.inside_cover_html = template % {'date': time.strftime('%Y-%m-%d'), - 'isbn': isbn_text, - 'license': license, - } def spawn_x(self): diff --git a/objavi2.py b/objavi2.py index 34ac7f4..44b0f56 100755 --- a/objavi2.py +++ b/objavi2.py @@ -351,7 +351,6 @@ def mode_book(args): book.set_title(args.get('title')) book.add_css(args.get('css')) - book.compose_inside_cover(args.get('license'), args.get('isbn')) book.add_section_titles() book.make_pdf() diff --git a/templates/end_matter.en.html b/templates/end_matter.en.html new file mode 100644 index 0000000..9241cef --- /dev/null +++ b/templates/end_matter.en.html @@ -0,0 +1,18 @@ + + + + + Inside back cover. + + + + +
+

Thanks for reading!

+

Visit http://flossmanuals.net to make corrections or to find more manuals.

+ +
+
+ + diff --git a/templates/inside-front-cover.en.html b/templates/inside-front-cover.en.html index 0f4f4c2..ca24715 100644 --- a/templates/inside-front-cover.en.html +++ b/templates/inside-front-cover.en.html @@ -1,9 +1,9 @@
-- 2.11.4.GIT