Permalink
Browse files

Adding a custom 'jinja2template' filter.

This allows us to run static assets through Jinja2's templateing engine (using
Flask's standard template contexts).
  • Loading branch information...
1 parent 20add2c commit b1a34b46a628e111bafc060d4a53562370cc5a42 Randall Degges committed Jul 13, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 src/filter.py
View
26 src/filter.py
@@ -0,0 +1,26 @@
+"""Flask specific filters.
+
+For those to be registered automatically, make sure the main flask-assets
+namespace imports this file.
+"""
+
+
+from flask.templating import render_template_string
+from webassets.filter import Filter, register_filter
+
+
+class Jinja2TemplateFilter(Filter):
+ """Will compile all source files as Jinja2 temlates using the standard
+ Flask contexts.
+ """
+ name = 'jinja2template'
+
+ def __init__(self, context=None):
+ super(Jinja2TemplateFilter, self).__init__()
+ self.context = context or {}
+
+ def input(self, _in, out, source_path, output_path, **kw):
+ out.write(render_template_string(_in.read(), **self.context))
+
+
+register_filter(Jinja2TemplateFilter)

0 comments on commit b1a34b4

Please sign in to comment.