changeset 8:02d2e4d8b0c1

Make renderers responsible for formatting the title page.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 04 Jan 2017 02:55:20 -0800
parents e3d52edde00b
children a5488b474c6b
files fontaine/console.py fontaine/renderer.py
diffstat 2 files changed, 23 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/fontaine/console.py	Wed Jan 04 01:21:55 2017 -0800
+++ b/fontaine/console.py	Wed Jan 04 02:55:20 2017 -0800
@@ -20,15 +20,25 @@
         self.width = width
         colorama.init()
 
-    def write_title_heading(self, text, out):
+    def write_title_page(self, values, out):
+        known = ['title', 'credit', 'author', 'source']
+        center_values = [values.get(i) for i in known
+                         if i is not None]
+
         print("", file=out)
-        for line in text.split('\n'):
-            print(line.center(self.width), file=out)
+        for val in center_values:
+            for l in val.split('\n'):
+                print(l.center(self.width), file=out)
+            print("", file=out)
         print("", file=out)
         print("", file=out)
 
-    def write_title_footer(self, text, out):
-        _w(out, colorama.Style.DIM, text)
+        ddate = values.get('date') or values.get('draft date')
+        contact = values.get('contact')
+        bottom_lines = [i for i in [ddate, contact]
+                        if i is not None]
+
+        _w(out, colorama.Style.DIM, '\n\n'.join(bottom_lines))
         print("", file=out)
         _w(out, colorama.Style.DIM, 80 * '=')
 
--- a/fontaine/renderer.py	Wed Jan 04 01:21:55 2017 -0800
+++ b/fontaine/renderer.py	Wed Jan 04 02:55:20 2017 -0800
@@ -32,22 +32,13 @@
         self.write_footer(doc, out)
 
     def render_title_page(self, values, out):
-        # Render known metadata.
-        title = values.get('title')
-        credit = values.get('credit')
-        author = values.get('author') or values.get('authors')
-        source = values.get('source')
-        center_text = '\n\n'.join([
-            i for i in [title, credit, author, source]
-            if i is not None])
-        self.write_title_heading(self._tr(center_text), out)
-
-        ddate = values.get('date') or values.get('draft date')
-        contact = values.get('contact')
-        bottom_text = '\n\n'.join([
-            i for i in [ddate, contact]
-            if i is not None])
-        self.write_title_footer(self._tr(bottom_text), out)
+        clean_values = values.copy()
+        clean_values.setdefault('title', 'Untitled Screenplay')
+        clean_values.setdefault('credit', 'Written by')
+        clean_values.setdefault('author', 'Unknown')
+        for k in clean_values:
+            clean_values[k] = self._tr(clean_values[k])
+        self.write_title_page(clean_values, out)
 
     def render_scene(self, scene, out):
         if scene.header is not None:
@@ -65,10 +56,7 @@
     def write_footer(self, doc, out):
         pass
 
-    def write_title_heading(self, text, out):
-        raise NotImplementedError()
-
-    def write_title_footer(self, text, out):
+    def write_title_page(self, values, out):
         raise NotImplementedError()
 
     def write_scene_heading(self, text, out):