[ZPT] Truncating strings

fergal at esatclear.ie fergal at esatclear.ie
Fri Oct 24 05:08:13 EDT 2003


I said this yesterday but no one replied, so here it is again.

Just allow arguments to methods

<span tal:replace="lib/fmt/truncate(container/path/to/var, some/length)">

assuming that you shove a load of classes into some sort of collection
stored in lib.

No need for yet more namespace separators (/ is enough)

No need for python syntax in tales.

Anyone can see at a glance what is going on, no need for everyone to
retrain their neural nets.

Nestable, should you really need.

Not restricted to single arguments.

Ok, so no way of doing more='...' but you can't have everything and you
could easily add a truncate_elipsis function to fmt and you're laughing (in
fact it's probably better to do that than specify more='...' all over your
templates),

F


Original Message:
-----------------
From: Shane Hathaway shane at zope.com
Date: Thu, 23 Oct 2003 19:44:31 -0400 (EDT)
To: fmartins at hetnet.nl, zpt at zope.org
Subject: RE: [ZPT] Truncating strings


On Fri, 24 Oct 2003, Fernando Martins wrote:

> What's exactly wrong with a standard function call using a path(s) as a
> parameter:
> 
> <span tal:replace="fmt.truncate(container/path/to/var, 10, more='...')">

The problem is that this mixes path expression syntax with Pythonic
syntax.  Whenever you combine two syntaxes arbitrarily, the boundaries of
both syntaxes become unclear.  You have to choose which syntax will
dominate or the syntax will quickly degrade.

It looks like you would prefer Python syntax to dominate.  You could write 
it this way:

<span tal:replace="python:
  fmt.truncate(path('container/path/to/var'), 10, more='...')">

Assuming you import the name 'fmt' from somewhere, and 'fmt' has a
'truncate' method, you can already write this expression.  'path' is a 
special name you can use for evaluating path expressions in Python 
expressions.

Shane

_______________________________________________
ZPT mailing list
ZPT at zope.org
http://mail.zope.org/mailman/listinfo/zpt


--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .





More information about the ZPT mailing list