]> sipb.mit.edu Git - ikiwiki.git/commitdiff
incomplate edittemplate plugin
authorJoey Hess <joey@kitenet.net>
Wed, 12 Dec 2007 06:52:26 +0000 (01:52 -0500)
committerJoey Hess <joey@kitenet.net>
Wed, 12 Dec 2007 06:52:26 +0000 (01:52 -0500)
IkiWiki/Plugin/edittemplate.pm [new file with mode: 0644]
doc/plugins/edittemplate.mdwn [new file with mode: 0644]
doc/templates.mdwn
doc/todo/default_content_for_new_post.mdwn
doc/wikitemplates.mdwn

diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
new file mode 100644 (file)
index 0000000..b814c0e
--- /dev/null
@@ -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 (file)
index 0000000..6d889f5
--- /dev/null
@@ -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.
index 33e02b96df91f28b87d8004eabf19f7f61c278a0..0b0a61af26ef17dc204390997ff73d0061801251 100644 (file)
@@ -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
index d3e0b4bd86898694e255bef363250923d5b08648..48cb1cc9d4bf9073bb2e18dab6d486df8a702e70 100644 (file)
@@ -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]]
index 1beed649b7c84f0488408a03151a95a157879cc5..9643bcd79d59ae766f8f120223ce14d927d227c4 100644 (file)
@@ -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.