Mercurial > piecrust2
comparison piecrust/rendering.py @ 153:1c3d229158ba
Make a nice error message when a layout hasn't been found.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Thu, 04 Dec 2014 12:49:53 -0800 |
| parents | 28444014ce7d |
| children | 1187739e5a19 |
comparison
equal
deleted
inserted
replaced
| 152:8d956bd94ad2 | 153:1c3d229158ba |
|---|---|
| 2 import os.path | 2 import os.path |
| 3 import logging | 3 import logging |
| 4 from piecrust.data.builder import (DataBuildingContext, build_page_data, | 4 from piecrust.data.builder import (DataBuildingContext, build_page_data, |
| 5 build_layout_data) | 5 build_layout_data) |
| 6 from piecrust.sources.base import PageSource | 6 from piecrust.sources.base import PageSource |
| 7 from piecrust.templating.base import TemplatingError | 7 from piecrust.templating.base import TemplateNotFoundError, TemplatingError |
| 8 from piecrust.uriutil import get_slug | 8 from piecrust.uriutil import get_slug |
| 9 | 9 |
| 10 | 10 |
| 11 logger = logging.getLogger(__name__) | 11 logger = logging.getLogger(__name__) |
| 12 | 12 |
| 203 _, engine_name = os.path.splitext(full_names[0]) | 203 _, engine_name = os.path.splitext(full_names[0]) |
| 204 engine_name = engine_name.lstrip('.') | 204 engine_name = engine_name.lstrip('.') |
| 205 engine = get_template_engine(page.app, engine_name) | 205 engine = get_template_engine(page.app, engine_name) |
| 206 if engine is None: | 206 if engine is None: |
| 207 raise PageRenderingError("No such template engine: %s" % engine_name) | 207 raise PageRenderingError("No such template engine: %s" % engine_name) |
| 208 output = engine.renderFile(full_names, layout_data) | 208 try: |
| 209 output = engine.renderFile(full_names, layout_data) | |
| 210 except TemplateNotFoundError as ex: | |
| 211 msg = "Can't find template for page: %s\n" % page.path | |
| 212 msg += "Looked for: %s" % ', '.join(full_names) | |
| 213 raise Exception(msg) from ex | |
| 209 return output | 214 return output |
| 210 | 215 |
| 211 | 216 |
| 212 def get_template_engine(app, engine_name): | 217 def get_template_engine(app, engine_name): |
| 213 if engine_name == 'html': | 218 if engine_name == 'html': |
