summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@gnu.org>2007-08-29 00:44:55 +0200
committerThomas Schwinge <tschwinge@gnu.org>2007-08-30 12:02:19 +0200
commit3a074569abe0f687ee6b211516c895f5ef1aa158 (patch)
tree22683e9c5382bbbda728cf0d842c4d8e784563ae
parentf852ce7dae79614bd19c2f65b7b82d8040b47daa (diff)
First version of a `fill_empty_page' plugin.
-rw-r--r--.library/IkiWiki/Plugin/fill_empty_page.pm63
1 files changed, 63 insertions, 0 deletions
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 <tschwinge@gnu.org>
+#
+# 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.
+#
+# <http://ikiwiki.info/todo/default_content_for_new_post/>
+
+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