[ZPT] URLs and stuff

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Tue, 01 May 2001 15:32:00 +1000


Evan Simpson wrote:
> 
> From: <richard@bizarsoftware.com.au>
> > <body tal:process="here/munge_urls">
> > </body>
> >
> > Where munge_urls would be passed the parsed content of the tag. It
> should
> > then be able to add/remove/modify tags/attributes as needed.
> 
> This appeared in early drafts as the tal:method statement.  The problem
> we ran into, still unresolved, is how to properly implement it.  I want
> this feature very much, but I don't know how to get it right! Perhaps if
> I lay out the difficulties, you can help resolve them:
> 
> TAL uses an event-driven parser to convert the template source into an
> intermediate "program".  At render time, this program is combined with
> other programs (if macros are used) and interpreted to produce output.
> 
> 1. When should arbitrary munging take place?  Before, during, or after
> TAL parsing?  If after, then before, during, or after interpretation?
>
> 2. How should the munger "see" the source code, for manipulation
> purposes?  At no time is anything resembling a DOM tree constructed (a
> DOM was how we originally envisioned implementing tal:method).

Hey, I just thought of a different way (for me :) of approaching this
altogether...

How about just an extension to TALES such that there is another attribute
called 'tag' which is local to a given tag and contains a dictionary of its
attributes and its content as a string. This may then be passed to a python
method which may use the information to do its thing. So, 

   <a href="../basic/head.png"
      tal:attributes="href python:here/fixURL(tag, request)"
      class="frozzle">click here</a>

... with tag.attributes={'href': '../basic/head.png', 'tal:attributes':
'href python:here/fixURL(tag, request)'} and tag.content='click here'.

The tag structure would be immutable if need be for simplicity. Hrm. The
content strings would be horribly memory hogging, wouldn't they... is there
maybe some way they could reference the original raw string?


   Richard

-- 
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)