[ZPT] Add 'parity' to repeat?

Shane Hathaway shane at zope.com
Mon Aug 25 17:37:59 EDT 2003


Evan Simpson wrote:
> The use of "python:test(path('repeat/thing/odd'), 'odd', 'even')" and 
> variants has become so common as to merit its own method.
> 
> I suggest that 'parity()' be added to the stock repeat object.  It would 
> return the string "odd" or "even", depending on the repetition index.
> 
> This would allow the nicely concise:
> 
>   <tr tal:attributes="class repeat/row/parity">
> 
> An alternate approach would be to create a subpath prefix that has a 
> 'parity' method, perhaps along with all of the other repetition methods 
> that are computed directly from 'index', such as 'roman' and 'odd'. Then 
> we could write "repeat/row/index/int:parity", for example.  Of course, 
> this depends on the inclusion of subpath prefixes into a release.

Uh-oh, I'm not sure I know how to read "int:parity".  Does "int:" look 
up an adapter?  Maybe the adapter ought to be called something like 
"numutil".

FWIW, it occurred to me the other day that the use of a double colon 
might be a little clearer.  C++ uses this and I think other languages do 
too.  "repeat/row/index/numutil::parity".  It says "get the index of the 
row, then apply the parity function from the numutil namespace to the 
result."  Depending on your background, that may please or burn your 
eyes. :-)

Shane




More information about the ZPT mailing list