diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2010-05-03 18:21:53 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2010-05-03 18:21:53 +0200 |
commit | f0012811f8af8b1334b46781861a6dd3777ee392 (patch) | |
tree | e59c3e5d141ecff244584ba786ce191497a9e311 /renderer.py | |
download | kosten-f0012811f8af8b1334b46781861a6dd3777ee392.tar.gz kosten-f0012811f8af8b1334b46781861a6dd3777ee392.tar.bz2 kosten-f0012811f8af8b1334b46781861a6dd3777ee392.zip |
First import from portato proj
Diffstat (limited to '')
-rw-r--r-- | renderer.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/renderer.py b/renderer.py new file mode 100644 index 0000000..b8ce716 --- /dev/null +++ b/renderer.py @@ -0,0 +1,40 @@ +import os +import web +import mako +from mako.lookup import TemplateLookup + +import helper + +class Renderer: + """ + Renderer loading the correct Mako Templates + """ + def __init__ (self): + self.lookup = TemplateLookup( + directories=[helper.appdir('templates')], + module_directory = "/tmp/webpy/kosten/", + input_encoding='utf-8', + output_encoding='utf-8', + format_exceptions = True) + + def render (self, tpl, level = "pages" , **kwargs): + try: + t = self.get_tpl(tpl, level) + except mako.exceptions.TopLevelLookupException, e: + raise web.ctx.app_stack[-1].notfound(tpl) + + return t.render(h = helper, url = helper.url, w = web, _hl = highlighting, **kwargs) + + __call__ = render + + def get_tpl (self, tpl, level): + return self.lookup.get_template(self.get_tpl_name(tpl, level)) + + def get_tpl_name (self, tpl, level): + if not tpl.endswith(".mako"): + tpl = tpl+".mako" + + return os.path.join(level, tpl) + +# the one and only instance :) +render = Renderer() |