2 package IkiWiki::Plugin::conditional;
9 # Globals used to pass information into the PageSpec functions.
10 our ($sourcepage, $destpage);
13 hook(type => "preprocess", id => "if", call => \&preprocess_if);
16 sub preprocess_if (@) { #{{{
19 if (! exists $params{test} || ! exists $params{then}) {
20 return "[[if ".gettext('"test" and "then" parameters are required')."]]";
24 $sourcepage=$params{page};
25 $destpage=$params{destpage};
26 # An optimisation to avoid needless looping over every page
27 # and adding of dependencies for simple uses of some of the
29 if ($params{test} =~ /^(enabled|sourcepage|destpage)\((.*)\)$/) {
30 $result=eval "IkiWiki::PageSpec::match_$1(undef, ".
31 IkiWiki::safequote($2).")";
34 add_depends($params{page}, $params{test});
36 foreach my $page (keys %pagesources) {
37 if (pagespec_match($page, $params{test}, $params{page})) {
50 elsif (exists $params{else}) {
56 return IkiWiki::preprocess($params{page}, $params{destpage},
57 IkiWiki::filter($params{page}, $ret));
60 package IkiWiki::PageSpec;
62 sub match_enabled ($$) { #{{{
66 # test if the plugin is enabled
67 return UNIVERSAL::can("IkiWiki::Plugin::".$plugin, "import");
70 sub match_sourcepage ($$) { #{{{
74 return match_glob($IkiWiki::Plugin::conditional::sourcepage, $glob,
75 $IkiWiki::Plugin::conditional::sourcepage);
78 sub match_destpage ($$) { #{{{
82 return match_glob($IkiWiki::Plugin::conditional::destpage, $glob,
83 $IkiWiki::Plugin::conditional::sourcepage);
86 sub match_included ($$) { #{{{
87 return $IkiWiki::Plugin::conditional::sourcepage ne $IkiWiki::Plugin::conditional::destpage;