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 HTML::Template;
|
||||||
|
|
||||||
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
|
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
|
||||||
%renderedfiles %pagesources %depends %plugins};
|
%renderedfiles %pagesources %depends %hooks};
|
||||||
|
|
||||||
sub checkconfig () { #{{{
|
sub checkconfig () { #{{{
|
||||||
if ($config{cgi} && ! length $config{url}) {
|
if ($config{cgi} && ! length $config{url}) {
|
||||||
|
@ -387,12 +387,14 @@ sub globlist_match ($$) { #{{{
|
||||||
return 0;
|
return 0;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub register_plugin ($$$) { # {{{
|
sub hook (@) { # {{{
|
||||||
my $type=shift;
|
my %param=@_;
|
||||||
my $command=shift;
|
|
||||||
my $function=shift;
|
|
||||||
|
|
||||||
$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
|
1
|
||||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::register_plugin("preprocess", "brokenlinks", \&preprocess);
|
IkiWiki::hook(type => "preprocess", id => "brokenlinks",
|
||||||
|
call => \&preprocess);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
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
|
# Back to ikiwiki namespace for the rest, this code is very much
|
||||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::register_plugin("preprocess", "orphans", \&preprocess);
|
IkiWiki::hook(type => "preprocess", id => "orphans",
|
||||||
|
call => \&preprocess);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
|
|
@ -7,7 +7,8 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::register_plugin("preprocess", "pagecount", \&preprocess);
|
IkiWiki::hook(type => "preprocess", id => "pagecount",
|
||||||
|
call => \&preprocess);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# Ikiwiki skeleton plugin. Replace "skeleton" with the name of your plugin
|
# 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;
|
package IkiWiki::Plugin::skeleton;
|
||||||
|
|
||||||
use warnings;
|
use warnings;
|
||||||
|
@ -8,7 +8,8 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::register_plugin("preprocess", "skeleton", \&preprocess);
|
IkiWiki::hook(type => "preprocess", id => "skeleton",
|
||||||
|
call => \&preprocess);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
|
|
@ -134,12 +134,12 @@ sub preprocess ($$) { #{{{
|
||||||
if (length $escape) {
|
if (length $escape) {
|
||||||
return "[[$command $params]]";
|
return "[[$command $params]]";
|
||||||
}
|
}
|
||||||
elsif (exists $plugins{preprocess}{$command}) {
|
elsif (exists $hooks{preprocess}{$command}) {
|
||||||
my %params;
|
my %params;
|
||||||
while ($params =~ /(\w+)=\"([^"]+)"(\s+|$)/g) {
|
while ($params =~ /(\w+)=\"([^"]+)"(\s+|$)/g) {
|
||||||
$params{$1}=$2;
|
$params{$1}=$2;
|
||||||
}
|
}
|
||||||
return $plugins{preprocess}{$command}->(page => $page, %params);
|
return $hooks{preprocess}{$command}{call}->(page => $page, %params);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "[[$command not processed]]";
|
return "[[$command not processed]]";
|
||||||
|
|
Loading…
Reference in New Issue