--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -15,14 +15,16 @@
import logging
import pkg_resources
+import tg
+import jinja2
from tg.configuration import AppConfig, config
-from paste.deploy.converters import asbool
from routes import Mapper
from webhelpers.html import literal
import ew
import allura
+# needed for tg.configuration to work
from allura.lib import app_globals
log = logging.getLogger(__name__)
@@ -53,35 +55,16 @@
config['routes.map'] = map
def setup_jinja_renderer(self):
- from jinja2 import ChoiceLoader, Environment, PackageLoader
- from tg.render import render_jinja
-
- loaders = {'allura': PackageLoader('allura', 'templates')}
- for ep in pkg_resources.iter_entry_points('allura'):
- if not ep.module_name in loaders:
- log.info('Registering templates for application %s', ep.module_name)
- try:
- loaders[ep.module_name] = PackageLoader(ep.module_name, 'templates')
- except ImportError:
- log.warning('Cannot import entry point %s', ep)
- continue
-
- config['pylons.app_globals'].jinja2_env = Environment(
- loader=ChoiceLoader(loaders.values()),
+ config['pylons.app_globals'].jinja2_env = jinja2.Environment(
+ loader=PackagePathLoader(),
auto_reload=self.auto_reload_templates,
autoescape=True,
extensions=['jinja2.ext.do'])
# Jinja's unable to request c's attributes without strict_c
config['pylons.strict_c'] = True
-
- self.render_functions.jinja = render_jinja
+ self.render_functions.jinja = tg.render.render_jinja
class JinjaEngine(ew.TemplateEngine):
-
- def __init__(self, entry_point, config):
- import jinja2
- self.jinja2 = jinja2
- super(JinjaEngine, self).__init__(entry_point, config)
@property
def _environ(self):
@@ -90,7 +73,7 @@
def load(self, template_name):
try:
return self._environ.get_template(template_name)
- except self.jinja2.TemplateNotFound:
+ except jinja2.TemplateNotFound:
raise ew.errors.TemplateNotFound, '%s not found' % template_name
def parse(self, template_text, filepath=None):
@@ -102,4 +85,15 @@
text = template.render(**context)
return literal(text)
+class PackagePathLoader(jinja2.BaseLoader):
+
+ def __init__(self):
+ self.fs_loader = jinja2.FileSystemLoader(['/'])
+
+ def get_source(self, environment, template):
+ package, path = template.split(':')
+ filename = pkg_resources.resource_filename(package, path)
+ return self.fs_loader.get_source(environment, filename)
+
+
base_config = ForgeConfig()