I've been working on a method to optimize whitespace with Mako
templates -- instead of collapsing insignificant whitespace after
Pyramid renders the view_callable, it's stripped when Mako first
compiles the template.
I'm trying to figure out the best way to integrate this with Pyramid.
At first I was going to pass in a single config argument, but then I
realized that this needed to have some sort of conditional control on
this -- for those cases when rendering plaintext email or other types
of files where all whitespace is significant.
When I started going through the `pyramid/mako_templating.py` file , i
saw that the lookup ( line 154 ) was tied down to a subset of the
kwargs allowed by mako.lookup.TemplateLookup.__init__ ( line 147 ).
Only about half of the arguments are allows.
I was thinking about different ways to enable a passthrough of all
mako arguments, and this came to mind:
add to pyramid/config/settings.py :
class SettingsSection(Settings):
def __init__(self, settings=None, section_prefix=None, **kw):
if settings is None:
settings = {}
section_prefix_len = len(section_prefix)
section = dict([ (k[section_prefix_len:],v) for k,v in
settings.items() if k[:section_prefix_len] == section_prefix ])
for (k,v) in kw.items():
if k not in section:
section[k] = v
dict.__init__(self, **section)
then grabbing the entire mako section , with defaults , would be
something like:
mako_defaults = {\
'directories' : [],
'module_directory' : None,
'input_encoding':'utf-8' ,
'error_handler':None,
...
}
mako_settings = SettingsSection( settings , 'mako.' ,
**mako_defaults )
i mocked up a gist here: https://gist.github.com/jvanasco/5257232
it's not a perfect solution , as a handful of current settings need to
have pyramid operate on them ( such as the dotted name resolver. )
But something like this could allow for more mako arguments to be
passed it, without requiring a user to completely reimplement the
mako_templating infrastructure.
The only other idea I had, was to allow a user-defined mako lookup
routine to be configured. That seemed more extensible, but messier.
Thoughts ?
--
You received this message because you are subscribed to the Google Groups
"pylons-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.