Created
January 20, 2012 11:45
-
-
Save alxf/1646995 to your computer and use it in GitHub Desktop.
A rewrite of render_mako class from web.contrib.template (Web.py)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#webpy with mako | |
class render_mako(object): | |
"""Rendering interface to Mako Templates. | |
Example: | |
render = render_mako( | |
directories=['templates'], | |
input_encoding='utf-8', | |
output_encoding='utf-8', | |
extension='.mako' | |
) | |
render.hello() | |
The rendered template will be in this example: templates/hello.mako | |
""" | |
def __init__(self, *a, **kwargs): | |
#store custom extension | |
if kwargs.has_key('extension'): | |
self._ext = kwargs['extension'] | |
del kwargs['extension'] | |
#otherwise set it to .html | |
else: | |
self._ext = '.html' | |
#proceed to normal execution | |
from mako.lookup import TemplateLookup | |
self._lookup = TemplateLookup(*a, **kwargs) | |
def __getattr__(self, name): | |
path = name + self._ext | |
t = self._lookup.get_template(path) | |
return t.render |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment