On Thu, Jan 7, 2010 at 8:55 PM, Daniel Garcia Moreno <[email protected]> wrote:
> This morning I was boring and I think that could be cool to have django
> style filters in web.py templator, something like $:('http://webpy.org'|
> urlize).
>
> I created a branch at github [1]. I don't know if it's interesting for
> someone but there it is.
>
> Here you have an example of use:
>
[...]
>        Hello $:(name|replace:'o', 'x'|fistro:'http://google.es', name)

In templetor, anything after $ is a python expression. I think,
deviating from Python will add confusion. The same feature can be
implemented slightly differently like this:

class stream:
    def __init__(self, s):
        self.s = s

    def __or__(self, filter):
        return stream(filter(self.s))

    def __str__(self):
        return str(self.s)

    def __unicode__(self):
        return unicode(self.s)

print stream("hello") | str.upper | (lambda x: x + " " + x)

However, you need to wrap the object with stream before you can start piping it.
-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.


Reply via email to