X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/26c2c63c97e6bfa704357503fdfd8d8834838851..4f0b10c13d8d85e6ad1818f5ada84477f43df43a:/IkiWiki/Plugin/polygen.pm diff --git a/IkiWiki/Plugin/polygen.pm b/IkiWiki/Plugin/polygen.pm index 2ed81c8e4..8ce62b754 100644 --- a/IkiWiki/Plugin/polygen.pm +++ b/IkiWiki/Plugin/polygen.pm @@ -7,28 +7,40 @@ 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; + $symbol = IkiWiki::possibly_foolish_untaint($symbol) if defined $symbol; 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) { @@ -40,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