Permalink
Browse files

Add support for *inclusion* patterns.

  • Loading branch information...
1 parent f44931d commit 4cac571de3365fcf9c970ffb619ce49a5b9469b1 @nvie nvie committed Jan 8, 2013
Showing with 20 additions and 0 deletions.
  1. +7 −0 docs/index.rst
  2. +13 −0 jingo/__init__.py
View
@@ -60,6 +60,13 @@ In ``settings.py``::
This will let you use ``django.shortcuts.render`` or
``django.shortcuts.render_to_response``.
+You can optionally specify which filename patterns to consider Jinja2 templates::
+
+ JINGO_INCLUDE_PATTERN = r'\.jinja2' # use any regular expression here
+
+This will consider every template file that contains the substring `.jinja2` to
+be a Jinja2 file (unless it's in a module explicitly excluded, see below).
+
And finally you may have apps that do not use Jinja2, these must be excluded
from the loader::
View
@@ -3,6 +3,7 @@
import imp
import logging
import warnings
+import re
from django import http
from django.conf import settings
@@ -196,7 +197,19 @@ class Loader(BaseLoader):
is_usable = True
env.template_class = Template
+ def __init__(self):
+ super(Loader, self).__init__()
+ include_pattern = getattr(settings, 'JINGO_INCLUDE_PATTERN', None)
+ if include_pattern:
+ self.include_re = re.compile(include_pattern)
+ else:
+ self.include_re = None
+
def load_template(self, template_name, template_dirs=None):
+ if self.include_re:
+ if not self.include_re.search(template_name):
+ raise TemplateDoesNotExist(template_name)
+
if hasattr(template_name, 'rsplit'):
app = template_name.rsplit('/')[0]
if app in getattr(settings, 'JINGO_EXCLUDE_APPS', EXCLUDE_APPS):

0 comments on commit 4cac571

Please sign in to comment.