comparison piecrust/templating/pystacheengine.py @ 428:f4b7c8f183a4

templating: Fix Pystache template engine.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 26 Jun 2015 23:19:55 -0700
parents 139179dc7abd
children ca5a3c970263
comparison
equal deleted inserted replaced
427:3b658190c02b 428:f4b7c8f183a4
1 import logging 1 import logging
2 import pystache 2 import pystache
3 import pystache.common
3 from piecrust.templating.base import ( 4 from piecrust.templating.base import (
4 TemplateEngine, TemplateNotFoundError, TemplatingError) 5 TemplateEngine, TemplateNotFoundError, TemplatingError)
5 6
6 7
7 logger = logging.getLogger(__name__) 8 logger = logging.getLogger(__name__)
16 17
17 def renderString(self, txt, data, filename=None): 18 def renderString(self, txt, data, filename=None):
18 self._ensureLoaded() 19 self._ensureLoaded()
19 try: 20 try:
20 return self.renderer.render(txt, data) 21 return self.renderer.render(txt, data)
21 except pystache.TemplateNotFoundError as ex: 22 except pystache.common.TemplateNotFoundError as ex:
22 raise TemplateNotFoundError() from ex 23 raise TemplateNotFoundError() from ex
23 except pystache.PystacheError as ex: 24 except pystache.common.PystacheError as ex:
24 raise TemplatingError(str(ex), filename) from ex 25 raise TemplatingError(str(ex), filename) from ex
25 26
26 def renderFile(self, paths, data): 27 def renderFile(self, paths, data):
27 self._ensureLoaded() 28 self._ensureLoaded()
28 tpl = None 29 tpl = None
43 if tpl is None: 44 if tpl is None:
44 raise TemplateNotFoundError() 45 raise TemplateNotFoundError()
45 46
46 try: 47 try:
47 return self.renderer.render(tpl, data) 48 return self.renderer.render(tpl, data)
48 except pystache.PystacheError as ex: 49 except pystache.common.PystacheError as ex:
49 raise TemplatingError(str(ex)) from ex 50 raise TemplatingError(str(ex)) from ex
50 51
51 def _ensureLoaded(self): 52 def _ensureLoaded(self):
52 if self.renderer: 53 if self.renderer:
53 return 54 return