diff piecrust/rendering.py @ 183:fff195335d0a

render: When a template engine can't be found, show the correct name in the error. Raise the exception related to a template engine not being found when we still have the actual name we were looking for.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 04 Jan 2015 14:57:37 -0800
parents e9a3d405e18f
children 27d623a241c6
line wrap: on
line diff
--- a/piecrust/rendering.py	Sun Jan 04 14:55:41 2015 -0800
+++ b/piecrust/rendering.py	Sun Jan 04 14:57:37 2015 -0800
@@ -19,6 +19,10 @@
     pass
 
 
+class TemplateEngineNotFound(Exception):
+    pass
+
+
 class RenderedPage(object):
     def __init__(self, page, uri, num=1):
         self.page = page
@@ -159,8 +163,6 @@
     format_name = page.config.get('format')
 
     engine = get_template_engine(app, engine_name)
-    if engine is None:
-        raise PageRenderingError("Can't find template engine '%s'." % engine_name)
 
     formatted_content = {}
     for seg_name, seg in page.raw_content.items():
@@ -192,7 +194,8 @@
 def render_layout(layout_name, page, layout_data):
     names = layout_name.split(',')
     default_template_engine = get_template_engine(page.app, None)
-    default_exts = ['.' + e.lstrip('.') for e in default_template_engine.EXTENSIONS]
+    default_exts = ['.' + e.lstrip('.')
+                    for e in default_template_engine.EXTENSIONS]
     full_names = []
     for name in names:
         if '.' not in name:
@@ -205,8 +208,7 @@
     _, engine_name = os.path.splitext(full_names[0])
     engine_name = engine_name.lstrip('.')
     engine = get_template_engine(page.app, engine_name)
-    if engine is None:
-        raise PageRenderingError("No such template engine: %s" % engine_name)
+
     try:
         output = engine.renderFile(full_names, layout_data)
     except TemplateNotFoundError as ex:
@@ -223,7 +225,8 @@
     for engine in app.plugin_loader.getTemplateEngines():
         if engine_name in engine.ENGINE_NAMES:
             return engine
-    return None
+    raise TemplateEngineNotFound("No such template engine: %s" % engine_name)
+
 
 def format_text(app, format_name, txt, exact_format=False):
     if exact_format and not format_name: