From: Julien Moutinho Date: Sat, 15 Mar 2014 03:07:57 +0000 (+0100) Subject: init X-Git-Url: http://git.heureux-cyclage.org/?p=ikiwiki%2Faction.git;a=commitdiff_plain;h=HEAD init --- e6e723b62839efd4c2a8d2995a8143f29e806a4b diff --git a/action.pm b/action.pm new file mode 100644 index 0000000..aa9de88 --- /dev/null +++ b/action.pm @@ -0,0 +1,60 @@ +#!/usr/bin/perl + # This file is une extension à IkiWiki + # permettant d’ajouter des actions aux pages. + # Copyright (C) 2010 Julien Moutinho + # + # 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 3 of the License, + # or 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, see . +package IkiWiki::Plugin::action; +use warnings; +use strict; +use IkiWiki 3.00; +sub import { + IkiWiki::hook + ( type => "preprocess" + , id => "action" + , call => \&hook_preprocess_action ); + IkiWiki::hook + ( type => "pageactions" + , id => "action" + , call => \&hook_preprocess_pageactions ); + } +my %map; +sub hook_preprocess_pageactions(@) { + my %env = @_; + my $page = $env{page}; + my @lst; + if (defined $page and exists $map{$page}) { + foreach (@{$map{$page}}) { + push @lst, $_; + } + } + return @lst; + } +sub hook_preprocess_action(@) { + my %env = @_; + my $page = $env{page}; + if (exists $env{html} and defined $env{html}) { + if (length $env{html}) { + $map{$page} = [] + if not defined $map{$page}; + push @{$map{$page}}, "$env{html}"; + } + else { + delete $map{$page}; + } + } + return ""; + } + +1;