Anand
as you can see from Cheetah's author, #include doesnt look in the templates
directory
and hence in the cheetah.py aaron wrote he used these lines to ensure
#includes work with webpy
 *       # 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)*


so we just need to add these 5 lines to render_cheetah for it work
This is not too much of a problem since this is how cheetah functions it
needs to have the files in the directory where it is being called from
and to circumvent i we just need these 5 lines
I really think we should add this to make sure render_cheetah is not just a
stub that is never used
and we can ensure cheetah works from webpy

Cheetah is an amazing templating language.
Thanks

so they function becomes

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")
            text = open(path).read()
        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)
        text = '#encoding UTF-8\n'+text
        def template(**kw):
            t = Template(text, searchList=[kw])
            data = t.respond()
            t.shutdown()
            return data
        return template
*Mike Orr*
That's one of Cheetah's problems; there's no include path.  Relative
paths are resolved from the current directory, which in many web
frameworks is the top-level application directory.

I personally used mainly precompiled templates and inheritance, and
rarely used #include except for some chunk of text that changed more
frequently tan the surrounding text or was maintained by somebody
else.  I think inheritance is better than #include overall, because
#include leads to disorganized PHP-like spaghetti code, especially
since you're sharing variables between the templates.


On Sat, Mar 28, 2009 at 2:51 PM,   > thanks mike
> but what about #include
>
> for eg., webpy app
> is
>
> serverapp/
>    app.py
>    templates/index.html
>    templates/test.html
>
> so if i do
> #include test.html
> in index.html
> it doesnt work as it is looks for test.html in serverapp directory instead
> of serverapp/templates 

On Sat, Mar 28, 2009 at 2:17 PM, R. Tyler Ballance <[email protected]> wrote:

> Please CC me on the thread instead of forwarding these along so I can
> play too :)
>
>
> On Sat, Mar 28, 2009 at 02:13:42PM -0700, paul jobs wrote:
>  >    ---------- Forwarded message ----------
> >    From: Anand Chitipothu <[email protected]>
> >    Date: Sat, Mar 28, 2009 at 12:57 PM
> >    Subject: [webpy] Re: fix for #include and shutdown
> >    To: [email protected]
> >
> >    > if you look at cheetah it has no single release since 2007
> >    > Where as webpy is improved continously
> >
> >    Then you should look for alternatives to Cheetah.
> >    > also i found an obvious bug and a also gave you the patch for fixing
> >    > render_cheetah
> >
> >    It is not a bug and it is not obvious.
> >    Why should #include support be added only to cheetah? why not for all
> >    the other templating engines out there?
> >
> >    I think, web.contrib.template module provides render.foo interface to
> >    various templating engines. It doesn't try to alter the behavior or
> >    add additional functionality.
> >    > Why do you not want to include this in git?
> >
> >    Because of the above mentioned reasons.
> >    > >
> >    --
>  >    BidEgg - Worlds best low price Auction site
> >    http://bidegg.com
> >
> >    BidEgg - Worlds best low price Auction site
>
> --
> -R. Tyler Ballance
> Slide, Inc.
>



-- 
BidEgg - Worlds best low price Auction site
http://bidegg.com

BidEgg - Worlds best low price Auction site

--~--~---------~--~----~------------~-------~--~----~
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