[Htmltmpl] making htmltmpl more like HTML::Template
Brought to you by:
jakubvrana,
tripiecz
|
From: anders p. <an...@co...> - 2003-05-06 22:13:28
|
i've been programming in Perl for years and have recently been doing more and more work in python. as a Perl programmer, i'm totally hooked on HTML::Template. so when i started coding more and more python, i considered just writing a python copy of the module. first, i decided to do a quick google search on the off chance that someone else out there was of a similar mind. obviously i wasn't alone! Tomas Styblo has saved me quite a bit of time. thank you. anyway, i have a lot of existing applications that were built with Perl and HTML::Template that i would like to integrate with or totally replace with python. i'd rather not have to spend much time re-writing template files (and documentation that uses the perl syntax), so i'm very interested in getting htmltmpl.py to accept *exactly* the same syntax as the perl version. specifically:=20 - case insensitivity. i find it much easier to type lowercase so all of my template files are written like <tmpl_var name=3D"foo"> rather than <TMPL_VAR NAME=3D"foo">.=20 - allow lowercase names for loop variables. eg, <tmpl_loop name=3D"foo">=20 should be legal.=20 - allow linebreaks inside tags. <tmpl_var name=3D"foo"> should be parsed the same as <tmpl_var name=3D"foo"> i did a bit of quick hacking and wrote a patch that handles the first two. i'll probably start on the third sometime next week, but it's not as high priority for me. the patch is available at:=20 http://thraxil.org/htmltmpl/html-tmpl-2003-05-06_01.patch.gz in addition to case insensitivity and allowing lowercase names for loop variables, it also adds a very simple set_dict() method to TemplateProcessor and eliminates the exception that is raised if save_precompiled() can't write to the template directory, instead just silently returning (essentially making precompile just automatically turn off instead of raising errors). set_dict() lets you do something like:=20 tproc.set_dict(some_function_that_returns_a_dict()) instead of=20 dict =3D some_function_that_returns_a_dict() for key in dict: tproc.set(key,dict[key]) now some questions:=20 1) is htmltmpl.py even being maintained? on the sourceforge page i don't see any changes since 2001. 2) what was the reasoning behind making loop names start with a capital letter?=20 3) is anyone else doing similar work on making htmltmpl.py more compatible with HTML::Template templates? again, thanks for writing htmltmpl, Tomas.=20 --=20 anders pearson : http://www.columbia.edu/~anders/ C C N M T L : http://www.ccnmtl.columbia.edu/ weblog : http://thraxil.org/ |