Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving our Jinja2 filter to ``flask_assets``.

And having it override the build-in ``jinja2`` template, so that we get the
included Flask contexts by default.
  • Loading branch information...
commit 3e3477f1eb8d452e1cb81ddfd8c0ff36b19e028c 1 parent c6fe73a
Randall Degges authored
Showing with 21 additions and 27 deletions.
  1. +0 −26 src/filter.py
  2. +21 −1 src/flask_assets.py
View
26 src/filter.py
@@ -1,26 +0,0 @@
-"""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)
View
22 src/flask_assets.py
@@ -1,8 +1,10 @@
from __future__ import with_statement
from os import path
from flask import _request_ctx_stack, url_for
+from flask.templating import render_template_string
from webassets.env import (\
BaseEnvironment, ConfigStorage, env_options, Resolver, url_prefix_join)
+from webassets.filter import Filter, register_filter
from webassets.loaders import PythonLoader, YAMLLoader
@@ -15,7 +17,25 @@
# We want to expose this here.
from webassets import Bundle
-from filter import Jinja2TemplateFilter
+
+
+class Jinja2Filter(Filter):
+ """Will compile all source files as Jinja2 temlates using the standard
+ Flask contexts.
+ """
+ name = 'jinja2'
+
+ def __init__(self, context=None):
+ super(Jinja2Filter, 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))
+
+# Override the built-in ``jinja2`` filter that ships with ``webassets``. This
+# custom filter uses Flask's ``render_template_string`` function to provide all
+# the standard Flask template context variables.
+register_filter(Jinja2Filter)
class FlaskConfigStorage(ConfigStorage):
Please sign in to comment.
Something went wrong with that request. Please try again.