.. -*- rst -*- Mako templates for django >= 1.2. Portions of this code are taken from django-smorgasbord's mako support. Smorgasbord provided a monkeypatch to facilitate the use of other templating languages within django 1.1; with django 1.2, this monkeypatch is no longer necessary, and there is no longer any particular reason to conjoin template loaders for different languages in one project. To use, add ``'djmako.MakoLoader'`` to ``settings.TEMPLATE_LOADERS``, and optionally define ``settings.MAKO_TEMPLATE_DIRS`` (a tuple of directories in which to look for mako templates) and ``settings.MAKO_TEMPLATE_OPTS`` (a dictionary of other parameters to pass to Mako's ``TemplateLookup`` class). If values are not defined, defaults similar to Django's defaults will be used. For instance, in ```` you might have:: TEMPLATE_LOADERS = ( 'djmako.MakoLoader', 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) # If MAKO_TEMPLATE_DIRS are not provided, ``TEMPLATE_DIRS + # app_template_dirs`` will be used. Note taht ``app_template_dirs`` is a # tuple of all the app template directories, used by # ``django.templates.loaders.app_directories.Loader``. from djmako import app_template_dirs MAKO_TEMPLATE_DIRS = TEMPLATE_DIRS + app_template_dirs + ( os.path.join(PROJECT_ROOT, "templates", "mako"), ) # If MAKO_TEMPLATE_OPTS are not provided, the defaults below will be used: MAKO_TEMPLATE_OPTS={ # Default values: 'input_encoding': 'utf-8', 'default_filters': ['h'], 'enable_loop': True, # Other values to consider: 'cache_impl': 'djmakocache', 'imports': [ 'from myapp.templatetags import some_tag', ], 'module_directory': os.path.join( tempfile.gettempdir(), os.environ.get('LOGNAME', 'someuser'), 'mysite', PROJECT_ROOT.split('/')[-2] ), } # By default, djmako will apply a few monkeypatches which will make Mako # play more nicely with Django. Currently: # - Django's SafeData will have an ``__html__`` method injected so it will # also be considered safe by ``markupsafe``. DJMAKO_MONKEYPATCH = True Note that in the above configuration, the mako loader is checked first, and django templates afterwards. Because of this, the ``MakoLoader`` requires Mako template files to have a ``.mako`` extension, so it doesn't try to load Django template files. Cache Plugin ~~~~~~~~~~~~ As of version 0.4, djmako contains a cache plugin for Mako that connects the Mako cache to the Django cache system. To enable, set ``"cache_impl"`` to ``"djmakocache"`` in ``settings.MAKO_TEMPLATE_OPTS``. License ======= Copyright (c) 2010 Jacob Smullyan. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.