]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/edittemplate.pm
incomplate edittemplate plugin
[ikiwiki.git] / IkiWiki / Plugin / edittemplate.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::edittemplate;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 sub import { #{{{
9         hook(type => "needsbuild", id => "edittemplate",
10                 call => \&needsbuild);
11         hook(type => "preprocess", id => "edittemplate",
12                 call => \&preprocess);
13         hook(type => "formbuilder_setup", id => "edittemplate",
14                 call => \&formbuilder_setup);
15 } #}}}
16
17 sub needsbuild (@) { #{{{
18         my $needsbuild=shift;
19
20         foreach my $page (keys %pagestate) {
21                 if (exists $pagestate{$page}{edittemplate}) {
22                         if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
23                                 # remove state, it will be re-added
24                                 # if the preprocessor directive is still
25                                 # there during the rebuild
26                                 delete $pagestate{$page}{edittemplate};
27                         }
28                 }
29         }
30 } #}}}
31
32 sub preprocess (@) { #{{{
33         my %params=@_;
34
35         return "" if $params{page} ne $params{destpage};
36
37         if (! exists $params{template} || ! length($params{template})) {
38                 return return "[[meta ".gettext("template not specified")."]]";
39         }
40         if (! exists $params{match} || ! length($params{match})) {
41                 return return "[[meta ".gettext("match not specified")."]]";
42         }
43
44         $pagestate{$params{page}}{edittemplate}{$params{match}}=$params{template};
45
46         return sprintf(gettext("edittemplate %s registered for %s"),
47                 $params{template}, $params{match});
48 } # }}}
49
50 sub formbuilder_setup { #{{{
51         my %params=@_;
52         my $form=$params{form};
53         my $page=$form->field("page");
54
55         return if $form->title ne "editpage"
56                   || $form->field("do") ne "create";
57
58         $form->field(name => "editcontent", value => "hi mom!");
59 } #}}}
60
61 1