change plugin interface to use named parameters for flexability
parent
4ba45ec3fc
commit
a44bfb158d
14
IkiWiki.pm
14
IkiWiki.pm
|
@ -7,7 +7,7 @@ use File::Spec;
|
|||
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}) {
|
||||
|
@ -387,12 +387,14 @@ sub globlist_match ($$) { #{{{
|
|||
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
|
||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
|||
use IkiWiki;
|
||||
|
||||
sub import { #{{{
|
||||
IkiWiki::register_plugin("preprocess", "brokenlinks", \&preprocess);
|
||||
IkiWiki::hook(type => "preprocess", id => "brokenlinks",
|
||||
call => \&preprocess);
|
||||
} # }}}
|
||||
|
||||
sub preprocess (@) { #{{{
|
||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
|||
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
|
||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
|||
use IkiWiki;
|
||||
|
||||
sub import { #{{{
|
||||
IkiWiki::register_plugin("preprocess", "orphans", \&preprocess);
|
||||
IkiWiki::hook(type => "preprocess", id => "orphans",
|
||||
call => \&preprocess);
|
||||
} # }}}
|
||||
|
||||
sub preprocess (@) { #{{{
|
||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
|||
use IkiWiki;
|
||||
|
||||
sub import { #{{{
|
||||
IkiWiki::register_plugin("preprocess", "pagecount", \&preprocess);
|
||||
IkiWiki::hook(type => "preprocess", id => "pagecount",
|
||||
call => \&preprocess);
|
||||
} # }}}
|
||||
|
||||
sub preprocess (@) { #{{{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/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;
|
||||
|
@ -8,7 +8,8 @@ use strict;
|
|||
use IkiWiki;
|
||||
|
||||
sub import { #{{{
|
||||
IkiWiki::register_plugin("preprocess", "skeleton", \&preprocess);
|
||||
IkiWiki::hook(type => "preprocess", id => "skeleton",
|
||||
call => \&preprocess);
|
||||
} # }}}
|
||||
|
||||
sub preprocess (@) { #{{{
|
||||
|
|
|
@ -134,12 +134,12 @@ 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]]";
|
||||
|
|
Loading…
Reference in New Issue