Skip to content

Commit

Permalink
Moving our Jinja2 filter to flask_assets.
Browse files Browse the repository at this point in the history
And having it override the build-in ``jinja2`` template, so that we get the
included Flask contexts by default.
  • Loading branch information
randalldegges-okta-2 committed Jul 14, 2012
1 parent c6fe73a commit 3e3477f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
26 changes: 0 additions & 26 deletions src/filter.py

This file was deleted.

22 changes: 21 additions & 1 deletion src/flask_assets.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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):
Expand Down

0 comments on commit 3e3477f

Please sign in to comment.