Hello Remi,
I'm new to CherryPy (using it for only 2 days) and have found it to be
very promising.
The only thing I didn't like much in it is the templating options
(CherryTemplate or Cheetah), because both mix Python and html togheter.
I'd prefer something that could permit me to do the gross of the page
in an wysiwyg HTML editor (it's a matter of productivity) and then add
the Python funcionality.
So I've made a small script that can parse a regular HTML file and
replace a special tag for the data from a dictionary passed to it.
The tag has the format:
<script language="amb"> Var </script>
"amb" are just my initials, the script permits you to change that to
whatever you like (ok, something like "javascript" would not work fine
;-).
The <script> tag is very common, so I think it would not be a
problem to use any comon HTML editor (I've used OpenOffice's), that it
will permit to choose the "language" attribute.
So the only thing you have to do is:
- edit an HTML template on an wysiwyg HTML editor, placing <script
language="amb"> Var </script> evreywhere you want
e.g: This is the <b>current date: <script language="amb">
Date </script></b><br>
and the <b>current time: <script language="amb">
Time </script></b>
- inside the CherryPy script call PrepPage passing a dictionary with
the data:
e.g:
import time
from cherrypy import cpg
from PrepPage import PrepPage
class MyPage:
def index(self):
Today = time.localtime()
PageDic = {'Date': '[%02d/%02d/%04d]' % (Today[2], Today[1],
Today[0]),
'Time': '[%02d:%02d:%02d]' %
(Today[3],Today[4], Today[5]}
return PrepPage('model.html', PageDic)
index.exposed = True
This way you get a good separation of template and Python code.
You could even use HTMLgen to generate rather complex HTML data as
objects, to be passed through the dictionary.
e.g.
from HTMLgen import *
...
Options = List(['First option', 'Second option']) #
This will generate a bullet list (it could be an entire table)
for NewOption in SomeList:
Options.append(NewOption)
PageDic = {'Date': '[%02d/%02d/%04d]' % (Today[2], Today[1],
Today[0]),
'Time': '[%02d:%02d:%02d]' %
(Today[3],Today[4], Today[5],
'OptionList': str(Options)}
I don't know if you (or someone) think it would be useful, at least it
was for me.
I'll probably have no more time to work on it (I'm very, very busy), so
I'm giving it for the CherryPy comunity in the hope it helps someone
else.
Armando