]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/polygen.pm
trail: Allow unescaped punctuation in pagenames
[git.ikiwiki.info.git] / IkiWiki / Plugin / polygen.pm
index 82fd575a78e5b921e1c73977626ff11d44825b4f..8ce62b754fa6161c51d94b30e4957c6d9b1d38c9 100644 (file)
@@ -7,21 +7,32 @@ package IkiWiki::Plugin::polygen;
 
 use warnings;
 use strict;
-use IkiWiki;
+use IkiWiki 3.00;
 use File::Find;
 
-sub import { #{{{
-       IkiWiki::hook(type => "preprocess", id => "polygen",
-               call => \&preprocess);
-} # }}}
+sub import {
+       hook(type => "getsetup", id => "polygen", call => \&getsetup);
+       hook(type => "preprocess", id => "polygen", call => \&preprocess);
+}
 
-sub preprocess (@) { #{{{
+sub getsetup () {
+       return 
+               plugin => {
+                       safe => 1,
+                       rebuild => undef,
+                       section => "widget",
+               },
+}
+
+sub preprocess (@) {
        my %params=@_;
        my $grammar = ($params{grammar} or 'polygen');
        my $symbol = ($params{symbol} or undef);
+       my $options = ($config{deterministic} ? '-seed 42' : '');
 
        # Sanitize parameters
        $grammar =~ IkiWiki::basename($grammar);
+       $grammar =~ s/[^A-Za-z0-9]//g;
        $grammar =~ s/\.grm$//;
        $grammar .= '.grm';
        $symbol =~ s/[^A-Za-z0-9]//g if defined $symbol;
@@ -29,7 +40,7 @@ sub preprocess (@) { #{{{
 
        my $grmfile = '/usr/share/polygen/ita/polygen.grm';
        if (! -d '/usr/share/polygen') {
-               return "[[polygen not installed]]";
+               error gettext("polygen not installed");
        }
        find({wanted => sub {
                        if (substr($File::Find::name, -length($grammar)) eq $grammar) {
@@ -41,20 +52,20 @@ sub preprocess (@) { #{{{
        
        my $res;
        if (defined $symbol) {
-               $res = `polygen -S $symbol $grmfile 2>/dev/null`;
+               $res = `polygen -S $symbol $options $grmfile 2>/dev/null`;
        }
        else {
-               $res = `polygen $grmfile 2>/dev/null`;
+               $res = `polygen $options $grmfile 2>/dev/null`;
        }
 
        if ($?) {
-               $res="[[polygen failed]]";
+               error gettext("command failed");
        }
 
-       # Strip trainling spaces and newlines so that we flow well with the
+       # Strip trailing spaces and newlines so that we flow well with the
        # markdown text
        $res =~ s/\s*$//;
        return $res;
-} # }}}
+}
 
 1