This is almost exactly what Cheetah does.  The formatter function can 
be changed with an arg to __init__ or by #formatter directives 
anywhere in a template.  It's very handy!  Have a look at some of the 
python code generated by Cheetah to see how it's implemented.

On Wednesday 13 March 2002 08:11, Geoffrey Talvola wrote:
> PSP currently converts expression blocks like <%=1234%> into
> servlet code like this:
>
>       res.write(str(1234))
>
> It would be convenient to be able to use a custom function instead
> of "str". For example, if I wanted all integers to be formatted
> like "1,234" I could do that in a custom function.
>
> There are a few ways to do this.  One way is to have PSP use some
> predefined method call instead of str():
>
>       res.write(self.htForValue(1234))
>
> and in the base class provide:
>
>       def htForValue(self, value):
>               return str(value)
>
> as a default implementation.  You could override it in the PSP
> itself using a method directive, or in your own base class.  (Any
> other suggestions for the name of the method?)
>
> Another thought is a special PSP directive that lets you specify
> the string conversion function or method (which would still default
> to str()):
>
>       <%@ page formatter="self.htForValue" %>
>
> And a third thought is that you don't actually need to do
> _anything_ to PSP to get this to work.  All you need to do is
> assign to str at the top of your PSP:
>
>       <%str = self.htForValue%>
>
> but that seems a bit too sneaky and could break if PSP's
> implementation changed to not use str() in the future.
>
> Thoughts?
>
>
> - Geoff
>
> _______________________________________________
> Webware-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/webware-devel

_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-devel

Reply via email to