Comments
Patch
@@ -625,9 +625,23 @@ class engine(object):
mapping contains added elements for use during expansion. Is a
generator.'''
return _flatten(runtemplate(self, mapping, self._load(t)))
-engines = {'default': engine}
+class jsonengine(engine):
+ '''Template engine used for rendering JSON.
+
+ When this engine is asked to process a template, it defaults to converting
+ all passed mappings into an object and returning the JSON representation of
+ that object. However, if a named entry for a template exists, it overrides
+ this default behavior.
+ '''
+ def process(self, t, mapping):
+ try:
+ return super(jsonengine, self).process(t, mapping)
+ except TemplateNotFound:
+ return _flatten(templatefilters.json(mapping))
+
+engines = {'default': engine, 'json': jsonengine}
def stylelist():
paths = templatepaths()
if not paths: