From 3a074569abe0f687ee6b211516c895f5ef1aa158 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 29 Aug 2007 00:44:55 +0200 Subject: First version of a `fill_empty_page' plugin. --- .library/IkiWiki/Plugin/fill_empty_page.pm | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .library/IkiWiki/Plugin/fill_empty_page.pm (limited to '.library/IkiWiki') diff --git a/.library/IkiWiki/Plugin/fill_empty_page.pm b/.library/IkiWiki/Plugin/fill_empty_page.pm new file mode 100644 index 00000000..30396438 --- /dev/null +++ b/.library/IkiWiki/Plugin/fill_empty_page.pm @@ -0,0 +1,63 @@ +# A plugin for ikiwiki to implement filling newly created pages from a template +# file. + +# Copyright © 2007 Thomas Schwinge +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# Newly created pages will be filled from a file `empty_page.mdwn' if such a +# file can be found by using the same rules as for the sidebar plugin. +# +# + +package IkiWiki::Plugin::fill_empty_page; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import +{ + hook (type => "formbuilder_setup", id => "fill_empty_page", + call => \&formbuilder_setup); +} + +sub formbuilder_setup +{ + my %params = @_; + my $form = $params {form}; + my $page = $form->field ("page"); + + return if $form->title ne "editpage"; + return if $form->field("do") ne "create"; + + # This is obviously not the last conclusion of wisdom. + my $empty_page_page = bestlink ($page, "empty_page") || return; + my $empty_page_file = $pagesources {$empty_page_page} || return; + my $empty_page_type = pagetype ($empty_page_file); + return unless defined $empty_page_type; + + my $content = readfile (srcfile ($empty_page_file)); + + if (defined $content && length $content) + { + $form->field (name => "editcontent", value => $content); + + $form->tmpl_param ("page_preview", "Filled automagically from `" + . $empty_page_file . "`."); + } +} + +1 -- cgit v1.2.3