Re: Cheetah's #include base directory

Tavis Rudd <[email protected]> Tue, 16 Mar 2010 17:03:39 -0700 (PDT)
Newsgroups gmane.comp.python.cheetah
Message-ID <alpine.LNX.2.00.1003161701420.519@o3>
Wouldn't template inheritance with dynamic compilation just require 
installing the Cheetah import hook?

On Tue, 16 Mar 2010, Aahz wrote:

> On Thu, Jan 28, 2010, R. Tyler Ballance wrote:
>> On Thu, 28 Jan 2010, Aahz wrote:
>>> On Tue, Jan 26, 2010, R. Tyler Ballance wrote:
>>>> On Tue, 26 Jan 2010, Aahz wrote:
>>>>>
>>>>> All right, how do you do create global template elements such as page
>>>>> footers?  I want to write them in Cheetah rather than Python because
>>>>> they're primarily HTML.
>>>>
>>>> I use inheritance between pre-compiled templates (since it's tricky
>>>> to do with dynamic compilation), here's an example:
>>>>
>>>> base.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/base.tmpl
>>>> index.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/index.tmpl
>>>
>>> Ah-ha.  Well, since I *do* want dynamic compilation for development, I
>>> guess I'm going to need to put in some skill sweat to figure out how to
>>> make that work.
>>
>> Indeed; I think adding the ability to use inheritance with dynamic
>> compilation would be a good feature to add to Cheetah but I'm
>> uncertain on what the API would look like?
>
> We already have code we use to deal with dynamic vs pre-compiled, which
> I guess I'll just extend a bit to deal with "including" templates:
>
> def getTemplate(name):
>    return os.path.join(os.path.realpath(os.path.join("..","..", "resource","html","templates")), name) + ".tmpl"
>
> def run_template(tmpl_name, searchList, development=None):
>    if development is None:
>        development = "-d" in sys.argv or "--DEVELOPMENT" in sys.argv
>    if development:
>        logging.debug("Getting dev template: %s", tmpl_name)
>        t = Template(file=getTemplate(tmpl_name), searchList=searchList)
>    else:
>        logging.debug("Getting compiled template: %s", tmpl_name)
>        t = getattr(templates, tmpl_name)(searchList=searchList)
>    return t.respond()
>
> Obviously, getTemplate() relies on knowledge of our environment and would
> need updating to work in the general case.  Similarly, the "templates"
> package is also an artifact of our environment, and our build system
> auto-generates the __init__.py of the package to hoist the template
> classes into the root package namespace.
>
> Hopefully this gives you ideas for something that can work in Cheetah.
>
> But at least soon I will tell our developers to just use e.g.
> $run_template('footer')
> which isn't quite as nice as template inheritance but is straightforward
> and will still be considerably better than what we currently have.
> -- 
> Aahz ([email protected])           <*>         http://www.pythoncraft.com/
>
> "Many customs in this life persist because they ease friction and promote
> productivity as a result of universal agreement, and whether they are
> precisely the optimal choices is much less important." --Henry Spencer
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev