[Petal] [IDEA] Hash with params
Evan Simpson
evan at 4-am.com
Wed Sep 10 11:54:27 BST 2003
Jean-Michel Hiver wrote:
> I'm not really sure I really understand what this is all about. I
> remember a ZPT undocumented feature which allowed paths as follows:
>
> /path/with/?variable
>
> How does it relates to prefixes?
It was a rather half-assed way of doing a specific thing that prefixes
nicely generalize. With prefixes, the above can be written as
"/path/with/var:variable". I'm not sure how useful the current set of
builtin prefixes would be in Petal, since they mostly deal with explicit
control of traversal (as hash key, list index, object attribute, etc),
and Petal does paths a bit differently. Using non-builtin prefixes by
writing 'tal:define="prefix myprefixname ext:a_prefix"', on the other
hand, allows you to perform arbitrary transformations while traversing a
path.
> As far as I understand, if a file (let's call it foo.xml) contained a
> METAL define-macro="bar" instruction then Petal would have to look at
> this XML fragment as a virtual file called 'foo/bar'. Or should it be
> 'foo.xml/bar' ?
In the ZPT implementation, all macros defined by a template are accessed
through a 'macros' collection, so the address would be
'foo.xml/macros/bar'. Of course, a ZPT template is an object with
methods, not just a file, so we have to worry about name clashes.
> Reversely, would metal:use-macro="somemacro" map to Petal's
> <?include file="somemacro.xml" ?>
The argument of metal:use-macro is just a TALES expression, so you would
need a variable that maps names to files (or file proxy objects) for a
path expression, or a new TALES expression type that takes a filename
and a macro name. Then you could write either
'metal:use-macro="files/somemacro.xml/macros/bar"' or
'metal:use-macro="file:somemacro.xml bar"'.
> How about metal:slot and metal:fill-slot? In which way would I need to
> extend Petal's include mechanism to provide equivalent functionality?
Those are tricky. A metal:define-slot essentially creates a named
parameter for its macro, along with a default value. A metal:fill-slot
passes its statement element to the used macro as an argument for the
named parameter. Perhaps you need a new directive like this:
<?include-slots file="somemacro.xml" macro="bar" ?>
<?fill-slot slot="s1" ?><p>some text</p><?/fill-slot ?>
<?/include-slots ?>
Cheers,
Evan @ 4-am
More information about the Petal
mailing list