[Petal] Multiple conditions?
Ronald Hayden
rhayden at apple.com
Sun Mar 9 10:03:13 GMT 2003
On Sunday, March 9, 2003, at 02:19 AM, jhiver at mkdoc.com wrote:
> It used to be documented somewhere, but I rewrote the docs (I'm still
> not satisfied with them...) and apparently it disapeared in the
> process :)
Along these lines, what I would enjoy most in the docs are more
examples. I find myself having to guess a lot at how/where to use an
item. It would be great if each feature came with a snippet showing
the feature in use.
Perhaps the website has more? I've seen several mentions of it on this
list, but I've only looked at the docs on CPAN. Come to think of it,
where is the website? I've never noticed it in many Google searches.
(Hmm, trying to find a Petal homepage is currently crashing Google!)
> Note that there is currently no trivial way of doing ORs...
Oops, and that's actually what I turned out to need! Well consider it
a feature request. In general I don't like putting much logic (beyond
condition and repeat) in the templates, but I'm finding that without an
OR, I have to have the code be more involved than I'd like. In this
case, we're generating a "Figures, Listings, and Tables" TOC, and the
template only wants to list a chapter if the chapter contains one of a
set of elements. The template has the ability to ask for a list of a
type of element in a chapter, so what I'd like do to is something like:
<section petal:repeat="chapter $book/chapters">
<chapter_section petal:condition="true:$chapter/descendants 'Figure'
OR true:$chapter/descendants 'CodeListing' OR true:$chapter/descendants
'Table'>
...
</chapter_section>
</section>
This way the template designers would be free to check for other kinds
of elements in the document later, with no need for change to the code.
They could create entirely new kinds of sections without needing the
code touched. As it is now, I added a $book/lofat_chapters function to
return only chapters that contain the elements in question. This means
that function has to stay in sync with what the template designers
need, requiring both a template designer and a programmer for basic
changes to be made.
If anyone has suggestions for a (simple!) solution, I'd love to hear
them!
Hmm, perhaps it would work to do something like this:
<section petal:repeat="chapter $book/chapters_with_elements 'Figure'
'CodeListing' 'Table'">
I'll go play with that now...
-- Ron
More information about the Petal
mailing list