Live data from Hacker News

Pure python html templating using with statements

gist.github.com

11–20 of 24 posts

Re: Pure python html templating using with statements

#12
post #3

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…

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.

tldr-part: look at my wip code → https://github.com/dodo/node-dynamictemplate/blob/a46fb6ed18...

Re: Pure python html templating using with statements

#14
post #10

Here is a simple idea: html( head( title('This is the title')), body( div(id='header', body=...))) We could also create a shortcut for div ID and classes.. for instance a keyword capitalized is an ID, or something starting with _ could be a class. It could then be possible to make "custom" fields: html( headers(), left_side(), content(), footer())

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

#17
post #10

Here is a simple idea: html( head( title('This is the title')), body( div(id='header', body=...))) We could also create a shortcut for div ID and classes.. for instance a keyword capitalized is an ID, or something starting with _ could be a class. It could then be possible to make "custom" fields: html( headers(), left_side(), content(), footer())

I've been playing with a similar syntax: https://github.com/maplambda/py-htmlout/blob/master/htmlgen.... I need to provide better examples, tests and form handling. I'm finding it nice to work with.

Re: Pure python html templating using with statements

#19
post #14
post #10

Here is a simple idea: html( head( title('This is the title')), body( div(id='header', body=...))) We could also create a shortcut for div ID and classes.. for instance a keyword capitalized is an ID, or something starting with _ could be a class. It could then be possible to make "custom" fields: html( headers(), left_side(), content(), footer())

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".

the gist contains example using lxml:

  E.html(
    E.head(...),
    E.body(...))

Re: Pure python html templating using with statements

#20
post #3

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…

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/
Post reply on HN