Browse files

Merge pull request #31 from nvie/master

Add support for explicit inclusion
  • Loading branch information...
2 parents f44931d + eb6f8b3 commit 1cc3c1e97e1f0b2b8e715c03589beaea275cbca2 James Socol committed Jan 8, 2013
Showing with 27 additions and 0 deletions.
  1. +7 −0 README.rst
  2. +7 −0 docs/index.rst
  3. +13 −0 jingo/__init__.py
View
7 README.rst
@@ -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
7 docs/index.rst
@@ -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
13 jingo/__init__.py
@@ -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 1cc3c1e

Please sign in to comment.