comparison piecrust/templating/pystacheengine.py @ 429:ca5a3c970263

templating: Workaround for a bug with Pystache.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 27 Jun 2015 00:03:56 -0700
parents f4b7c8f183a4
children 32c7c2d219d2
comparison
equal deleted inserted replaced
428:f4b7c8f183a4 429:ca5a3c970263
51 51
52 def _ensureLoaded(self): 52 def _ensureLoaded(self):
53 if self.renderer: 53 if self.renderer:
54 return 54 return
55 55
56 self.renderer = pystache.Renderer( 56 self.renderer = _WorkaroundRenderer(
57 search_dirs=self.app.templates_dirs) 57 search_dirs=self.app.templates_dirs)
58 58
59
60 _knowns = ['PieCrustData', 'LazyPageConfigData', 'Paginator', 'Assetor',
61 'PageLinkerData']
62
63
64 class _WorkaroundRenderer(pystache.Renderer):
65 def _make_resolve_context(self):
66 mrc = super(_WorkaroundRenderer, self)._make_resolve_context()
67
68 def _workaround(stack, name):
69 # Pystache will treat anything that's not a string or a dict as
70 # a list. This is just plain wrong, but it will take a while before
71 # the project can get patches on Pypi.
72 res = mrc(stack, name)
73 if res is not None and res.__class__.__name__ in _knowns:
74 res = [res]
75 return res
76
77 return _workaround
78