1 Sometimes you want to match a page only if it has certain properties. The use
2 case I have in mind is this: show me all the pages that have children. You
3 can't do that with a pagespec, so I created a plugin that adds some pagespec
6 `match_relative(blah)` will match a page x if a pagespec from x would match
7 `blah`. This is only actually useful with relative pagespecs.
9 `match_has_child(blah)` will match a child if it has a descendant named
10 `blah`. If blah is empty, any child will match.
23 A pagespec `match_relative(./blah)` will match `foo/bar/bahoo`, because
24 a pagespec of `./blah` from `bahoo` would match `foo/bar/blah`. A
25 pagespec of `match_has_child(blah)` would match `foo`, `foo/bar`,
26 `foo/baz`, and `foo/baz/goo`.
28 Note that if you try to inline `*/blah` you will match `foo/blah`,
29 `foo/bar/blah`, and `foo/baz/goo/blah` -- that is, the blah pages
30 themselves rather than any relatives of theirs.
32 This patch is useful for (among other things) constructing blogging
33 systems where leaf nodes are organized hierarchically; using has_child,
34 you can inline only leaf nodes and ignore "intermediate" nodes.
35 match_relative can be used recursively to match properties of arbitrary
36 complexity: "show me all the pages who have children called foo that
37 have children called blah". I'm not sure what use it is, though.
39 You can see the patch in action at
40 <http://ikidev.betacantrips.com/conditionaltest/>,
41 so named because I had hoped that something in conditional.pm could
42 help me. I know the name "relative" sucks, feel free to come up with a
46 diff -urNX ignorepats ikiwiki/IkiWiki/Plugin/relative.pm ikidev/IkiWiki/Plugin/relative.pm
47 --- ikiwiki/IkiWiki/Plugin/relative.pm 1969-12-31 16:00:00.000000000 -0800
48 +++ ikidev/IkiWiki/Plugin/relative.pm 2007-07-26 21:48:10.642686000 -0700
51 +# relative.pm: support for pagespecs on possible matches
52 +package IkiWiki::Plugin::relative;
58 +package IkiWiki::PageSpec;
60 +sub match_relative($$;@) { #{{{
65 + foreach my $page (keys %IkiWiki::pagesources) {
66 + next if $page eq $parent;
67 + if (IkiWiki::pagespec_match($page, $spec, location => $parent)) {
68 + return IkiWiki::SuccessReason->new("$parent can match $spec against $page");
71 + return IkiWiki::FailReason->new("$parent can't match $spec against anything");
74 +sub match_has_child($$;@) { #{{{
76 + my $childname = shift;
78 + if ($childname) { #{{{
79 + $spec = "$page/$childname or $page/*/$childname";
85 + return match_relative($page, $spec, @_);