# -*- coding: utf-8 -*-\r
+# -*- coding: utf-8 -*-\r
"""\r
jinja.contrib._djangosupport\r
~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
`django.contrib.jinja`. See the docstring of `jinja.contrib.djangosupport`\r
for more details.\r
\r
- :copyright: 2007 by Armin Ronacher, Bryan McLemore.\r
+ :copyright: 2007-2008 by Armin Ronacher, Bryan McLemore, David Cramer.\r
:license: BSD, see LICENSE for more details.\r
"""\r
import sys\r
+import warnings\r
import new\r
from django.conf import settings\r
from django.template.context import get_standard_processors\r
\r
\r
#: default filters\r
-DEFAULT_FILTERS = [\r
+DEFAULT_FILTERS = (\r
'django.template.defaultfilters.date',\r
'django.template.defaultfilters.timesince',\r
'django.template.defaultfilters.linebreaks',\r
'django.contrib.humanize.templatetags.humanize.intcomma'\r
-]\r
-\r
+)\r
\r
def configure(convert_filters=DEFAULT_FILTERS, loader=None, **options):\r
"""\r
"""\r
global env\r
\r
- if env is not None:\r
- raise RuntimeError('jinja already configured')\r
+ if env:\r
+ warnings.warn("Jinja already initialized.")\r
+ return\r
\r
# setup environment\r
if loader is None:\r
- loaders = [FileSystemLoader(l) for l in settings.TEMPLATE_DIRS]\r
+ loaders = tuple(FileSystemLoader(l) for l in settings.TEMPLATE_DIRS)\r
if not loaders:\r
loader = None\r
elif len(loaders) == 1:\r
new.module('django.contrib.jinja')\r
module.env = env\r
module.__doc__ = djangosupport.__doc__\r
- module.register = Library()\r
+ module.register = Library\r
public_names = module.__all__ = ['register', 'env']\r
get_name = globals().get\r
for name in exported:\r
def wrapped(env, ctx, value):\r
return f(value, *args)\r
return wrapped\r
- try:\r
- filter_factory.__name__ = f.__name__\r
- filter_factory.__doc__ = f.__doc__\r
- except:\r
- pass\r
+ filter_factory.__name__ = f.__name__\r
+ filter_factory.__doc__ = getattr(f, '__doc__', None)\r
return filter_factory\r
\r
\r
\r
For more details see the docstring of the `django.contrib.jinja` module.\r
"""\r
- __slots__ = ()\r
-\r
- def object(obj, name=None):\r
+ @staticmethod\r
+ def object(func, name=None):\r
"""Register a new global."""\r
if name is None:\r
- name = getattr(obj, '__name__')\r
- env.globals[name] = obj\r
+ name = getattr(func, '__name__')\r
+ env.globals[name] = func\r
return func\r
\r
+ @staticmethod\r
def filter(func, name=None):\r
"""Register a new filter function."""\r
if name is None:\r
env.filters[name] = func\r
return func\r
\r
+ @staticmethod\r
def test(func, name):\r
"""Register a new test function."""\r
if name is None:\r
env.tests[name] = func\r
return func\r
\r
+ @staticmethod\r
def context_inclusion(func, template, name=None):\r
"""\r
Similar to the inclusion tag from django this one expects func to be a\r
pass\r
env.globals[name] = wrapper\r
\r
+ @staticmethod\r
def clean_inclusion(func, template, name=None, run_processors=False):\r
"""\r
Similar to above however it won't pass the context into func().\r