Monday, June 12, 2006

Neengine Update - Fun With Cheetah Templates

Finally, Neengine is looking cleaner and more visually palatable. Thanks
to a few hours on Googling on HTML formatting with Cheetah Templates.
I've been mulling moving over to templetor which seems will come by
default in webpy 2.0, but the '4 space' indentation thing actually irks
me. I can understand it in Python as a language, but as a hard
requirement in a templating system, its a bit irritating. The real
problem though is that right now, the errors caused by getting
indentation wrong are not accurately reported, and will probably lead
you to frustratingly look at other things. Since I'm not motivated to
hack that area, I'll just wait for Aaron to fix it, before I evaluate it
again :D

Anyways, I got to find out that Cheetah can control how special
characters in its place holders are treated, using something called
Output Filtering. With output filtering, you can either specify an
output filter as an argument to the rendering function, or you can do it
in the Template itself, using the #filter directive to cheetah.

By default, web.py treats HTML tags specially, hence rendering them
literally, instead of treating them as HTML. But using the two
directives: #filter ReplaceNone, #filter WebSafe, you can turn this
behaviour on and off. With the 'ReplaceNone' filter, you switch to
Cheetah's default behaviour, which is to only treat Python's 'None' as a
special character, replacing it with an empty space, every other thing
is rendered as is, so HTML tags will be rendered as HTML tags. With the
'WebSafe' filter, all characters that that can have special meanings on
the Web are escaped so as to be rendered visually literal.

I currently switch between these two when rendering Neengine's HTML
contents. Ofcourse, this is after turning linebreaks into and HTML break
tag. Currently, I still have to add transparent support for embedding
HTML into the posts, so it is escaped intelligently. I'm not even going
to think of how I'll do that now, till probably later in the week (if
i'm in the mood).

With that, Neengine is a lot more mature now. The only critical things
left now before I can declare a version 1.0 Neengine is Anti-Spam
validation for comments, so that I can enable back the comments section,
and RSS feed support. Other features like embedding images in posts will
probably come in a major version bump, since this will likely break the
database schema.

For now though, I'm off to hack thin client images :)

*enjoi*

0 Comments:

Post a Comment

<< Home