On Wed, 2011-04-13 at 06:30 -0700, Dmitry Vakhrushev wrote:
> Hi All.
> 
> I develop CMS using pyramid.  CMS consist of core and some plugins.
> Application which use CMS looks like:
> 
> from pyramid.config import Configurator
> def main(global, **settings):
>     config = Configurator(settings=settings)
>     config.include('mycms.core')
>     config.include('mycms.plugin')
> 
> 
> I use Mako as renderer.  Global templates (such as layouts) are stored
> in application package and local (plugin) templates are stored in
> plugin packages.  To use global templates (for inheritance) in local
> ones I specified in application ini-files the line:
> 
> mako.directories = application:templates
> 
> 
> Plugin includeme function looks like:
> 
> def includeme(config):
>     config.add_view('.views.someview', context='.resource.Resource',
> renderer=':templates/someview.mak')
> 
> 
> When I specified renderer name as full asset spec
> 'mycms.plugin:templates/someview.mak' it works fine.  But in relative
> form (like in example of code) I got ValueError: Empty module name.

Unlike the Chameleon template renderer, the Mako template renderer does
not respect relative asset specifications (e.g. "foo/bar.mak") only
absolute ones (e.g. "mypackage:foo/bar.mak").  

The built-in Mako renderer is willing to resolve templates from a global
location (using the "mako.directories" setting).  Due to this, it's not
possible for the built-in Mako renderer to distinguish names that should
be looked up from the global loader path from relative asset
specifications, so it requires absolute asset specifications.

The Chameleon renderer, which has no global "directories" location and
essentially treats every path that isn't absolute as a relative asset
specification.

> 
> So, after update __init__ method of pyramid.renderers.RendererHelper
> both forms are operational:
> 
> class RendererHelper(object):
>     implements(IRendererInfo)
>     def __init__(self, name=None, package=None, registry=None):
>         if name and '.' in name:
>             rtype = os.path.splitext(name)[1]
>         else:
>             rtype = name
> 
>         # Begin of my additional code *******************************
>         if (name.startswith('.') or name.startswith(':')) and package:
>             if isinstance(package, basestring):
>                 name = package + name
>             else:
>                 name = package.__name__ + name
>         # End of my additional code *********************************
> 
>         if registry is None:
>             registry = get_current_registry()
> 
>         self.name = name
>         self.package = package
>         self.type = rtype
>         self.registry = registry
> 
> 
> So, is it bug of pyramid.renderers.RendererHelper and what can be
> broken after my fix?  I'm not sure, that this is appropriate place to
> fix it.

It's not a bug, although you might desire the feature.  If you want it,
it's possible to create an alternate Mako renderer that always treats
relative paths as relative asset specifications and which does not use a
global lookup path location.  See
http://docs.pylonsproject.org/projects/pyramid/1.0/narr/renderers.html#adding-and-changing-renderers
 .

- C



-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to