From 8576fe4c4913c2ebe678c54f9353ac22c6bdaa84 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 12 Dec 2007 01:52:26 -0500 Subject: incomplate edittemplate plugin --- IkiWiki/Plugin/edittemplate.pm | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 IkiWiki/Plugin/edittemplate.pm (limited to 'IkiWiki/Plugin') 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 -- cgit v1.2.3