use HTML::Template;
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
- %renderedfiles %pagesources %depends %plugins};
+ %renderedfiles %pagesources %depends %hooks};
sub checkconfig () { #{{{
if ($config{cgi} && ! length $config{url}) {
return 0;
} #}}}
-sub register_plugin ($$$) { # {{{
- my $type=shift;
- my $command=shift;
- my $function=shift;
+sub hook (@) { # {{{
+ my %param=@_;
- $plugins{$type}{$command}=$function;
+ if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
+ error "hook requires type, call, and id parameters";
+ }
+
+ $hooks{$param{type}}{$param{id}}=\%param;
} # }}}
1
use IkiWiki;
sub import { #{{{
- IkiWiki::register_plugin("preprocess", "brokenlinks", \&preprocess);
+ IkiWiki::hook(type => "preprocess", id => "brokenlinks",
+ call => \&preprocess);
} # }}}
sub preprocess (@) { #{{{
use IkiWiki;
sub import { #{{{
- IkiWiki::register_plugin("preprocess", "inline", \&IkiWiki::preprocess_inline);
+ IkiWiki::hook(type => "preprocess", id => "inline",
+ call => \&IkiWiki::preprocess_inline);
} # }}}
# Back to ikiwiki namespace for the rest, this code is very much
use IkiWiki;
sub import { #{{{
- IkiWiki::register_plugin("preprocess", "orphans", \&preprocess);
+ IkiWiki::hook(type => "preprocess", id => "orphans",
+ call => \&preprocess);
} # }}}
sub preprocess (@) { #{{{
use IkiWiki;
sub import { #{{{
- IkiWiki::register_plugin("preprocess", "pagecount", \&preprocess);
+ IkiWiki::hook(type => "preprocess", id => "pagecount",
+ call => \&preprocess);
} # }}}
sub preprocess (@) { #{{{
#!/usr/bin/perl
# Ikiwiki skeleton plugin. Replace "skeleton" with the name of your plugin
-# in the lines below, and flesh out the methods to make it do something.
+# in the lines below, and flesh out the code to make it do something.
package IkiWiki::Plugin::skeleton;
use warnings;
use IkiWiki;
sub import { #{{{
- IkiWiki::register_plugin("preprocess", "skeleton", \&preprocess);
+ IkiWiki::hook(type => "preprocess", id => "skeleton",
+ call => \&preprocess);
} # }}}
sub preprocess (@) { #{{{
if (length $escape) {
return "[[$command $params]]";
}
- elsif (exists $plugins{preprocess}{$command}) {
+ elsif (exists $hooks{preprocess}{$command}) {
my %params;
while ($params =~ /(\w+)=\"([^"]+)"(\s+|$)/g) {
$params{$1}=$2;
}
- return $plugins{preprocess}{$command}->(page => $page, %params);
+ return $hooks{preprocess}{$command}{call}->(page => $page, %params);
}
else {
return "[[$command not processed]]";