Jacob Smullyan avatar Jacob Smullyan committed c29a921

cleanup

Comments (0)

Files changed (7)

 .*\.pyc
-
+build
+dist
-README.rst
+README.txt
 setup.py
 ./djmako/__init__.py
 ./djmako/loader.py
+./djmako/cache_plugin.py

README.rst

-.. -*- 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
-define settings.MAKO_TEMPLATE_DIRS (a tuple of directories in which to
-look for mako templates -- required) and ``settings.MAKO_TEMPLATE_OPTS``
-(a dictionary of other parameters to pass to Mako's ``TemplateLookup``
-class -- optional).
-
-For instance, in ``settings.py`` you might have::
-
-  TEMPLATE_LOADERS = (
-     'djmako.MakoLoader',
-     'django.template.loaders.filesystem.Loader',
-     'django.template.loaders.app_directories.Loader',
-  )
-
-  MAKO_TEMPLATE_DIRS=(os.path.join(PROJECT_ROOT, 'templates', 'mako'),)
-
-  MAKO_TEMPLATE_OPTS=dict(input_encoding='utf-8',
-                          module_directory=os.path.join(
-      tempfile.gettempdir(),
-      os.environ.get('LOGNAME', 'someuser'),
-      'mysite',
-      PROJECT_ROOT.split('/')[-2]))
-
-Note that in the above configuration, the mako loader is checked
-first, and django templates afterwards.
-
-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.
-
+.. -*- 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
+define settings.MAKO_TEMPLATE_DIRS (a tuple of directories in which to
+look for mako templates -- required) and ``settings.MAKO_TEMPLATE_OPTS``
+(a dictionary of other parameters to pass to Mako's ``TemplateLookup``
+class -- optional).
+
+For instance, in ``settings.py`` you might have::
+
+  TEMPLATE_LOADERS = (
+     'djmako.MakoLoader',
+     'django.template.loaders.filesystem.Loader',
+     'django.template.loaders.app_directories.Loader',
+  )
+
+  MAKO_TEMPLATE_DIRS=(os.path.join(PROJECT_ROOT, 'templates', 'mako'),)
+
+  MAKO_TEMPLATE_OPTS=dict(input_encoding='utf-8',
+                          cache_impl='djmakocache', 
+                          module_directory=os.path.join(
+      tempfile.gettempdir(),
+      os.environ.get('LOGNAME', 'someuser'),
+      'mysite',
+      PROJECT_ROOT.split('/')[-2]))
+
+Note that in the above configuration, the mako loader is checked
+first, and django templates afterwards.
+
+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.
+

djmako/__init__.py

 """
 
 from .loader import MakoLoader
+
+try:
+    import djmako.cache_plugin
+except ImportError:
+    print "cannot import cache plugin"
+    pass

djmako/cache_plugin.py

+"""
+A cache plugin for mako that uses the django cache.
+"""
+from mako.cache import CacheImpl, register_plugin
+
+_djcache = None
+
+class DjangoCacheImpl(CacheImpl):
+    """
+    A mako cache plugin that calls the django cache.
+    """
+    
+    def __init__(self, cache):
+        super(DjangoCacheImpl, self).__init__(cache)
+        global _djcache
+        if _djcache is None:
+            from django.core.cache import cache as _djcache
+        self._djcache = _djcache
+    
+    def get_or_create(self, key, creation_function, **kw):
+        djkey = 'djmako-' + key
+        value = self._djcache.get(djkey)
+        if value is None:
+            value = creation_function()
+            self._djcache.set(djkey, value)
+        return value
+
+    def set(self, key, value, **kwargs):
+        self._djcache.set('djmako-' + key, value)
+
+    def get(self, key, **kwargs):
+        return self._djcache.get('djmako-' + key)
+
+    def invalidate(self, key, **kwargs):
+        self._djcache.remove('djmako-' + key)
+
+
+register_plugin('djmakocache', __name__, 'DjangoCacheImpl')
 from distutils.core import setup
 from os import path 
 
-description="mako template support for Django 1.2"
+description="mako template support for Django >=1.2"
 
-fp = open(path.join(path.dirname(path.realpath(__file__)), 'README.rst'))
+fp = open(path.join(path.dirname(path.realpath(__file__)), 'README.txt'))
 long_description = fp.read()
 
-VERSION='0.3'
+VERSION='0.4'
 
 setup(author="Jacob Smullyan",
       author_email='smulloni@smullyan.org',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.