#includes dont work in render_cheetah
t.shutdown() reduces cheetah memory usage
Please review my class newrender_cheetah in the vein that we may improve
cheetah api in webpy
thanks

from web.utils import re_compile, memoize, dictadd
import re
r_include = re_compile(r'(?!\\)#include \"(.*?)\"', re.M)
class newrender_cheetah:
    """Rendering interface to Cheetah Templates.

    Example:

        render = render_cheetah('templates')
        render.hello(name="cheetah")
    """
    def __init__(self, path):
        # give error if Chetah is not installed
        from Cheetah.Template import Template
        self.path = path

    def __getattr__(self, name):
        from Cheetah.Template import Template
        try:path = os.path.join(self.path, name + ".html")
        except:path = os.path.join(self.path, name + ".tmpl")
        text = open(path).read()
        # implement #include at compile-time
        def do_include(match):
            text = open('templates/'+match.groups()[0]).read()
            return text
        while r_include.findall(text):
            text = r_include.sub(do_include, text)
        def template(**kw):
            t = Template(text, searchList=[kw])
            data = t.respond()
            t.shutdown()
            return data

        return template

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" 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/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to