summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/edittemplate.pm61
-rw-r--r--doc/plugins/edittemplate.mdwn33
-rw-r--r--doc/templates.mdwn9
-rw-r--r--doc/todo/default_content_for_new_post.mdwn4
-rw-r--r--doc/wikitemplates.mdwn6
5 files changed, 106 insertions, 7 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
diff --git a/doc/plugins/edittemplate.mdwn b/doc/plugins/edittemplate.mdwn
new file mode 100644
index 000000000..6d889f5f1
--- /dev/null
+++ b/doc/plugins/edittemplate.mdwn
@@ -0,0 +1,33 @@
+[[template id=plugin name=edittemplate author="[[Joey]]"]]
+[[tag type/useful]]
+
+This plugin allows registering template pages, that provide default
+content for new pages created using the web frontend. To register a
+template, insert a [[PreprocessorDirective]] on some other page.
+
+ \[[edittemplate template="bugtemplate" match="bugs/*"]]
+
+In the above example, the page named "bugtemplate" is registered as a
+template to be used when any page named "bugs/*" is created.
+
+[[template id=note text="""
+Note: It's generally not a good idea to put the `edittemplate` directive in
+the template page itself, since the directive would then be included as
+part of the template on new pages, which would then in turn be registered
+as templates. If multiple pages are registered as templates for a new page,
+an arbitrary one is chosen, so that could get confusing.
+"""]]
+
+Often the template page contains a simple skeleton for a particular type of
+page. For the bug report pages in the above example, it might look
+something like:
+
+ Package:
+ Version:
+ Reproducible: y/n
+ Details:
+
+The template page can also contain [[cpan HTML::Template]] directives,
+similar to other ikiwiki [[templates]]. Currently only one variable is
+set: `<TMPL_VAR name>` is replaced with the name of the page being
+created.
diff --git a/doc/templates.mdwn b/doc/templates.mdwn
index 33e02b96d..0b0a61af2 100644
--- a/doc/templates.mdwn
+++ b/doc/templates.mdwn
@@ -43,11 +43,10 @@ To create a template, simply add a template directive to a page, and page will
provide a link that can be used to create the template. The template is a
regular wiki page, located in the `templates/` directory.
-The template uses the syntax used by the
-[cpan HTML::Template](http://search.cpan.org/search?mode=dist&query=HTML::Template)
-perl module, which allows for some fairly complex things to be done.
-Consult its documentation for the full syntax, but all you really need to know
-are a few things:
+The template uses the syntax used by the [[cpan HTML::Template]] perl
+module, which allows for some fairly complex things to be done. Consult its
+documentation for the full syntax, but all you really need to know are a
+few things:
* To insert the value of a variable, use `<TMPL_VAR variable>`.
* To make a block of text conditional on a variable being set use
diff --git a/doc/todo/default_content_for_new_post.mdwn b/doc/todo/default_content_for_new_post.mdwn
index d3e0b4bd8..48cb1cc9d 100644
--- a/doc/todo/default_content_for_new_post.mdwn
+++ b/doc/todo/default_content_for_new_post.mdwn
@@ -61,4 +61,6 @@ Of course this
will also only work when using web-editing, but the people using
rcs-editing (coining new terms, eh ;-)?) usually know what they're doing.
---[[tschwinge]] \ No newline at end of file
+--[[tschwinge]]
+
+> [[done]] in the [[plugins/edittemplate]] plugin. --[[Joey]]
diff --git a/doc/wikitemplates.mdwn b/doc/wikitemplates.mdwn
index 1beed649b..9643bcd79 100644
--- a/doc/wikitemplates.mdwn
+++ b/doc/wikitemplates.mdwn
@@ -38,4 +38,8 @@ The [[plugins/pagetemplate]] plugin can allow individual pages to use a
different template than `page.tmpl`.
The [[plugins/template]] plugin also uses templates, though those
-[[templates]] are stored in the wiki.
+[[templates]] are stored in the wiki and inserted into pages.
+
+The [[plugin/edittemplate]] plugin is used to make new pages default to
+containing text from a template, which can be filled as out the page is
+edited.