incomplate edittemplate plugin

master
Joey Hess 2007-12-12 01:52:26 -05:00
parent 035a57f209
commit 8576fe4c49
5 changed files with 106 additions and 7 deletions

View File

@ -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

View File

@ -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.

View 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 provide a link that can be used to create the template. The template is a
regular wiki page, located in the `templates/` directory. regular wiki page, located in the `templates/` directory.
The template uses the syntax used by the The template uses the syntax used by the [[cpan HTML::Template]] perl
[cpan HTML::Template](http://search.cpan.org/search?mode=dist&query=HTML::Template) module, which allows for some fairly complex things to be done. Consult its
perl module, which allows for some fairly complex things to be done. documentation for the full syntax, but all you really need to know are a
Consult its documentation for the full syntax, but all you really need to know few things:
are a few things:
* To insert the value of a variable, use `<TMPL_VAR variable>`. * To insert the value of a variable, use `<TMPL_VAR variable>`.
* To make a block of text conditional on a variable being set use * To make a block of text conditional on a variable being set use

View File

@ -61,4 +61,6 @@ Of course this
will also only work when using web-editing, but the people using will also only work when using web-editing, but the people using
rcs-editing (coining new terms, eh ;-)?) usually know what they're doing. rcs-editing (coining new terms, eh ;-)?) usually know what they're doing.
--[[tschwinge]] --[[tschwinge]]
> [[done]] in the [[plugins/edittemplate]] plugin. --[[Joey]]

View File

@ -38,4 +38,8 @@ The [[plugins/pagetemplate]] plugin can allow individual pages to use a
different template than `page.tmpl`. different template than `page.tmpl`.
The [[plugins/template]] plugin also uses templates, though those 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.