Skip to content

adjusted uri used by inheriting templates, caused lookup error. #607

Closed
wants to merge 3 commits into from
View
7 pyramid/mako_templating.py
@@ -28,6 +28,10 @@ class IMakoLookup(Interface):
pass
class PkgResourceTemplateLookup(TemplateLookup):
+ def __init__(self, *args, **kwargs):
+ super(PkgResourceTemplateLookup, self).__init__(*args, **kwargs)
+ self._adjusted_dict = {}
+
"""TemplateLookup subclass that handles asset specification URIs"""
def adjust_uri(self, uri, relativeto):
"""Called from within a Mako template, avoids adjusting the
@@ -36,6 +40,8 @@ def adjust_uri(self, uri, relativeto):
isabs = os.path.isabs(uri)
if (not isabs) and (':' in uri):
return uri
+ if relativeto in self._adjusted_dict:
+ return TemplateLookup.adjust_uri(self, uri, self._adjusted_dict[relativeto])
return TemplateLookup.adjust_uri(self, uri, relativeto)
def get_template(self, uri):
@@ -54,6 +60,7 @@ def get_template(self, uri):
# store the generated python code in the mako module_directory or
# in the temporary location of mako's modules
adjusted = uri.replace(':', '$')
+ self._adjusted_dict[adjusted] = uri
try:
if self.filesystem_checks:
return self._check(adjusted, self._collection[adjusted])
View
5 pyramid/tests/test_mako_templating.py
@@ -397,6 +397,11 @@ def test_render_inheritance(self):
result = render('helloinherit.mak', {}).replace('\r','')
self.assertEqual(result, text_('Layout\nHello World!\n'))
+ def test_render_inheritance_from_pkg_spec(self):
+ from pyramid.renderers import render
+ result = render('pyramid.tests:fixtures/helloinherit.mak', {}).replace('\r','')
+ self.assertEqual(result, text_('Layout\nHello World!\n'))
+
def test_render_inheritance_pkg_spec(self):
from pyramid.renderers import render
result = render('hello_inherit_pkg.mak', {}).replace('\r','')
Something went wrong with that request. Please try again.