Rejigged website generation. Decided to try using Cheetah (www.cheetahtemplate.org), a python templating library. This allows me to modify my html template, putting in variable names to be replaced by code. It was very easy to get going and it looks very powerful: you can virtually embed python code in your html.
Example:
#
from Cheetah.Template import Template
strTemplate = """<body>
A $simple example.<br/>
Hello $names['wibble'], how are you today?<br/>
$MYGOD( 'software')
<table>
#for oEntry in $ENTRIES
<tr><td>$oEntry['Title']</td><td>$oEntry['Date']</td></tr>
#end for
</table>
</body>"""
def MyGod( strPara):
return "Now that's what I call " + strPara
oEntries = [ { 'Title': 'Fred', 'Date': 'Now'},
{ 'Title': 'Noreen', 'Date': 'blub'}
]
oNames = { 'wibble': 'Peter' }
oSearchList = {
'simple': "Simple",
'names': oNames,
'MYGOD': MyGod,
'ENTRIES': oEntries
}
strHTML = Template( strTemplate, searchList=[oSearchList])
print strHTM
Generates:
<body>
A Simple example.<br/>
Hello Peter, how are you today?<br/>
Now that's what I call software
<table>
<tr><td>Fred</td><td>Now</td></tr>
<tr><td>Noreen</td><td>blub</td></tr>
</table>
</body>
The advantage of all this complexity over strHTML.replace( '$simple', strSimple) is in the way that it allows loops to be expanded. The system as it stands allows me to create the HTML and make it pretty using HTML-Kit, then use python to populate it up. My python script has no layout HTML in it. The only other HTML involved is that generated from the DayNotez entries using DocUtils.
|