Skip to content

Commit

Permalink
Improved kajiki loader to solve some issues with py:extends
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Apr 29, 2012
1 parent 9029927 commit 9d04797
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tg/configuration/app_config.py
Expand Up @@ -455,9 +455,11 @@ def template_loaded(template):

def setup_kajiki_renderer(self):
"""Setup a renderer and loader for the fastpt engine."""
from kajiki.loader import PackageLoader
from tg.dottednames.kajiki_lookup import KajikiTemplateLoader
from tg.render import render_kajiki
loader = PackageLoader()
loader = KajikiTemplateLoader(self.paths.templates[0],
force_mode='xml',
reload=self.auto_reload_templates)
config['pylons.app_globals'].kajiki_loader = loader
self.render_functions.kajiki = render_kajiki

Expand Down
24 changes: 24 additions & 0 deletions tg/dottednames/kajiki_lookup.py
@@ -0,0 +1,24 @@
"""Kajiki template loader that supports dotted names with relative paths."""

from kajiki.loader import FileLoader

from tg import config


class KajikiTemplateLoader(FileLoader):
"""Kaijik template loader supporting dotted filenames.
Solves also the issue of not supporting relative paths when using
py:extends in Kaijiki
"""

template_extension = '.xml'

def __init__(self, base, reload=True, force_mode=None):
super(KajikiTemplateLoader, self).__init__(base, reload, force_mode)

def _filename(self, filename):
if not filename.endswith(self.template_extension):
finder = config['pylons.app_globals'].dotted_filename_finder
filename = finder.get_dotted_filename(template_name=filename,
template_extension=self.template_extension)
return super(KajikiTemplateLoader, self)._filename(filename)

0 comments on commit 9d04797

Please sign in to comment.