forked from cdleary/coffin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from akx/master
Non-callable globals, custom Django templatetag libraries, *.jinja loader
- Loading branch information
Showing
2 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
A Django template loader wrapper for Coffin that intercepts | ||
requests for "*.jinja" templates, rendering them with Coffin | ||
instead of Django templates. | ||
Usage: | ||
TEMPLATE_LOADERS = ( | ||
'coffin.contrib.loader.AppLoader', | ||
'coffin.contrib.loader.FileSystemLoader', | ||
) | ||
""" | ||
|
||
from coffin.common import env | ||
from django.conf import settings | ||
from django.template.loaders import app_directories, filesystem | ||
|
||
|
||
JINJA2_DEFAULT_TEMPLATE_EXTENSION = getattr(settings, | ||
'JINJA2_DEFAULT_TEMPLATE_EXTENSION', '.jinja') | ||
|
||
|
||
class LoaderMixin(object): | ||
is_usable = True | ||
|
||
def load_template(self, template_name, template_dirs=None): | ||
if not template_name.endswith(JINJA2_DEFAULT_TEMPLATE_EXTENSION): | ||
return super(LoaderMixin, self).load_template(template_name, | ||
template_dirs) | ||
template = env.get_template(template_name) | ||
return template, template.filename | ||
|
||
|
||
class FileSystemLoader(LoaderMixin, filesystem.Loader): | ||
pass | ||
|
||
|
||
class AppLoader(LoaderMixin, app_directories.Loader): | ||
pass |