summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2007-12-12 01:52:26 -0500
committerJoey Hess <joey@kitenet.net>2007-12-12 01:52:26 -0500
commit8576fe4c4913c2ebe678c54f9353ac22c6bdaa84 (patch)
tree5fb544d50ebdb2af4ceb5a5b434e15576f8992b1 /IkiWiki
parent035a57f209e02c954a0edf798bbc4879a6311a3f (diff)
incomplate edittemplate plugin
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/edittemplate.pm61
1 files changed, 61 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
new file mode 100644
index 000000000..b814c0e67
--- /dev/null
+++ b/IkiWiki/Plugin/edittemplate.pm
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::edittemplate;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+sub import { #{{{
+ hook(type => "needsbuild", id => "edittemplate",
+ call => \&needsbuild);
+ hook(type => "preprocess", id => "edittemplate",
+ call => \&preprocess);
+ hook(type => "formbuilder_setup", id => "edittemplate",
+ call => \&formbuilder_setup);
+} #}}}
+
+sub needsbuild (@) { #{{{
+ my $needsbuild=shift;
+
+ foreach my $page (keys %pagestate) {
+ if (exists $pagestate{$page}{edittemplate}) {
+ if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
+ # remove state, it will be re-added
+ # if the preprocessor directive is still
+ # there during the rebuild
+ delete $pagestate{$page}{edittemplate};
+ }
+ }
+ }
+} #}}}
+
+sub preprocess (@) { #{{{
+ my %params=@_;
+
+ return "" if $params{page} ne $params{destpage};
+
+ if (! exists $params{template} || ! length($params{template})) {
+ return return "[[meta ".gettext("template not specified")."]]";
+ }
+ if (! exists $params{match} || ! length($params{match})) {
+ return return "[[meta ".gettext("match not specified")."]]";
+ }
+
+ $pagestate{$params{page}}{edittemplate}{$params{match}}=$params{template};
+
+ return sprintf(gettext("edittemplate %s registered for %s"),
+ $params{template}, $params{match});
+} # }}}
+
+sub formbuilder_setup { #{{{
+ my %params=@_;
+ my $form=$params{form};
+ my $page=$form->field("page");
+
+ return if $form->title ne "editpage"
+ || $form->field("do") ne "create";
+
+ $form->field(name => "editcontent", value => "hi mom!");
+} #}}}
+
+1