Phillip Pearson - Second p0st

tech notes and web hackery from the guy that brought you bzero, python community server, the blogging ecosystem, the new zealand coffee review and the internet topic exchange

2003-7-23

Miniature Java template compiler

Why are there so many Java templating engines, when JSP is right there for you to use? I'm starting to understand -- JSP has a strange 'feel'. It should be possible to do FreeEnergy with the include directive though. Hmm.

The start of an experiment:

#!/usr/local/bin/python

import sys
html = open(sys.argv[1]).read()

while 1:
    x = html.split('<%', 1)
    if x[0]:
        print 'out.write("%s");' % x[0].replace('\\', '\\\\').replace('"', '\"').replace('\n', '\\n')
    if len(x) == 1: break
    code, html = x[1].split('%>', 1)
    if code:
        if code[0] == '=': code = 'out.write(%s)' % code[1:]
        print code


More on this later.
... more like this: [, ]