Skip to content

Commit

Permalink
More precisely identify Django loaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
miracle2k committed Feb 8, 2012
1 parent cb417a8 commit 3edda75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions coffin/template/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def jinja_loader_from_django_loader(django_loader):
:return: The similarly-behaving Jinja loader, or None if a similar loader
could not be found.
"""
if not django_loader.startswith('django.'):
return None
for substr, func in _JINJA_LOADER_BY_DJANGO_SUBSTR.iteritems():
if substr in django_loader:
return func()
Expand Down
14 changes: 14 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@
def test_i18n():
with override_settings(USE_I18N=True):
assert get_env().from_string('{{ _("test") }}').render() == 'test'


def test_django_loader_replace():
from coffin.template.loaders import jinja_loader_from_django_loader
from jinja2 import loaders

# Test replacement of filesystem loader
l = jinja_loader_from_django_loader('django.template.loaders.filesystem.Loader')
assert isinstance(l, loaders.FileSystemLoader)

# Since we don't do exact matches for the loader string, make sure we
# are not replacing loaders that are outside the Django namespace.
l = jinja_loader_from_django_loader('djangoaddon.template.loaders.filesystem.Loader')
assert not isinstance(l, loaders.FileSystemLoader)

0 comments on commit 3edda75

Please sign in to comment.