Weby Templates are used in production on websites that have garnered over 500,000 uniques a month. They are incredibly easy to work with. They are the "templates for lazy people". They have 3 main benefits:
* easier
* faster
* more flexible
* The main codebase is implemented in 100 source lines of code.
* Extensive libraries only add just a couple hundred other lines of code.
* It is simple.
* It ensures that all tags have closing tags.
* It is compiled and fast.
* It is unicode compliant and safe.
* You can be fully fluent within 5 minutes since it is just Python and a transparent library.
Re:Pure python html templating using with statements
by saurik on Sunday December 11, 2011 @11:20PM
(#3342239)
I am confused how these are "faster" than other templating languages, such as Mako. Don't all of the better templating languages "compile to bytecode"? It would seem that the large number of function calls that would be involved per tag would massively decrease the performance vs. something that was able to treat most of the content as opaque.
Re:Pure python html templating using with statements
by casbon on Sunday December 11, 2011 @01:24PM
(#3340608)
Thanks, I didn't find that when searching. Very similar idea, but a slightly more involved syntax. I see it uses string building rather than a lib like lxml which probably makes it faster.
Re:Pure python html templating using with statements
by nas on Sunday December 11, 2011 @01:05PM
(#3340547)
My view is probably warped because I helped design the PTL "language" for Python. However, it's been my experience if you write well factored code (i.e. Don't-Repeat-Yourself, helper functions/macros), then templates that use the HTML by default mode end up looking extremely ugly. Essentially you end up with mostly Python logic with a little HTML markup mixed in.
It's not friendly to UI designers who like to load it into something like Dreamweaver or translate their static design into the template. I haven't thought of any good solution for that though. Zope TAL seemed like a valiant attempt but I'm sure how successful it was.
Re:Pure python html templating using with statements
by dodothelast on Sunday December 11, 2011 @03:11PM
(#3340914)
i solved that by problem in my library https://github.com/dodo/node-dynamictemplate with the ui designers by masking their static html on my functions, which are only a subset of the part in the static html which you want to cover.
this way using a html mockup from a designer is like using an 3D from a 3D model artist, because you only load the data in, selecting what you want and putting a animatinon mesh / functionality into it.
Re:Pure python html templating using with statements
by trip42 on Sunday December 11, 2011 @10:14PM
(#3342086)
TAL is one of the most impressive things to come out of Zope, after using it for years I feel dirty using a templating system allows inline programming logic. Chameleon templates implement Zope's TAL for use outside of Zope: http://chameleon.repoze.org/
Re:Pure python html templating using with statements
by toyg on Sunday December 11, 2011 @03:35PM
(#3340993)
I'm pretty sure this has been done. I remember seeing something extremely similar while going through several of the umpteen python web frameworks and thinking "well, it's just html with parentheses rather than angled bracket and an additional leaky abstraction on top".
Re:Pure python html templating using with statements
by abecedarius on Monday December 12, 2011 @12:21AM
(#3342414)
Looks good. My own module of this sort auto-escapes HTML special characters in strings fed to it, by default -- it looks like yours doesn't do this, at least at first glance. Is that right?
Re:Pure python html templating using with statements
by catch404 on Monday December 12, 2011 @03:37AM
(#3342844)
Thanks, that would be a good approach, mine is currently very barebones! just trying to get the syntax right and get a feel for using it in actual projects - hope to put up a real sample soon.
Re:Pure python html templating using with statements
by Doboy on Sunday December 11, 2011 @11:06PM
(#3342204)
This is very interesting, I had the exact idea for the longest time but never got time to fully implement it fully, here is my simple version of it https://github.com/Doboy/Dopy Do.py was the file with the implementation and basic.py is an example input. I am extremely interested in where this project goes and would like to get involved.
Weby Templates are used in production on websites that have garnered over 500,000 uniques a month. They are incredibly easy to work with. They are the "templates for lazy people". They have 3 main benefits:
* easier * faster * more flexible
* The main codebase is implemented in 100 source lines of code.
* Extensive libraries only add just a couple hundred other lines of code.
* It is simple.
* It ensures that all tags have closing tags.
* It is compiled and fast.
* It is unicode compliant and safe.
* You can be fully fluent within 5 minutes since it is just Python and a transparent library.
http://www.jperla.com/blog/post/weby-templates-are-easier-fa...
(That said, aside from Atom feeds I haven't had the need to output XML rather than JSON in a very long time)
It's not friendly to UI designers who like to load it into something like Dreamweaver or translate their static design into the template. I haven't thought of any good solution for that though. Zope TAL seemed like a valiant attempt but I'm sure how successful it was.
this way using a html mockup from a designer is like using an 3D from a 3D model artist, because you only load the data in, selecting what you want and putting a animatinon mesh / functionality into it.
tldr-part: look at my wip code → https://github.com/dodo/node-dynamictemplate/blob/a46fb6ed18...
It could then be possible to make "custom" fields:
html( headers(), left_side(), content(), footer())
OTOH I think I like your syntax better.
http://davidbau.com/downloads/templet.py
And some notes about the implementation:
http://davidbau.com/archives/2007/03/11/python_string_functi...