Sometimes you want to match a page only if it has certain properties. The use
case I have in mind is this: show me all the pages that have children. You
can't do that with a pagespec, so I created a plugin that adds some pagespec
functions.
match_relative(blah)
will match a page x if a pagespec from x would match
blah
. This is only actually useful with relative pagespecs.
match_has_child(blah)
will match a child if it has a descendant named
blah
. If blah is empty, any child will match.
So if I have:
- foo
- foo/blah
- foo/bar
- foo/bar/blah
- foo/bar/bahoo
- foo/baz
- foo/baz/goo
- foo/baz/goo/blah
A pagespec match_relative(./blah)
will match foo/bar/bahoo
, because
a pagespec of ./blah
from bahoo
would match foo/bar/blah
. A
pagespec of match_has_child(blah)
would match foo
, foo/bar
,
foo/baz
, and foo/baz/goo
.
Note that if you try to inline */blah
you will match foo/blah
,
foo/bar/blah
, and foo/baz/goo/blah
-- that is, the blah pages
themselves rather than any relatives of theirs.
This patch is useful for (among other things) constructing blogging
systems where leaf nodes are organized hierarchically; using has_child
,
you can inline only leaf nodes and ignore "intermediate" nodes.
match_relative
can be used recursively to match properties of arbitrary
complexity: "show me all the pages who have children called foo that
have children called blah". I'm not sure what use it is, though.
You can see the patch in action at
http://ikidev.betacantrips.com/conditionaltest/,
so named because I had hoped that something in conditional.pm could
help me. I know the name "relative" sucks, feel free to come up with a
better one. --Ethan
This looks really interesting. It reminds me of XPath and its conditionals.
Those might actually work well adapted to pagespecs. For instance, to write
"match any page with a child blah", you could just write *[blah] , or if you
don't want to use relative-by-default in the conditionals, *[./blah].
-- [[JoshTriplett]]