diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-07-29 20:01:29 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-07-29 20:01:29 +0000 |
commit | 35c90a5b582f0d40a122b151580e313c2b157b6f (patch) | |
tree | e7c73eb33d0ef8f84bba531aebdf9b3cd172b042 /IkiWiki/Plugin | |
parent | 3a2dfb94cbe475faa16f0329ffc5e75f330d1afa (diff) |
"Viva l'Italia!"
* Polygen plugin from Enrico.
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/polygen.pm | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/polygen.pm b/IkiWiki/Plugin/polygen.pm new file mode 100644 index 000000000..c14889167 --- /dev/null +++ b/IkiWiki/Plugin/polygen.pm @@ -0,0 +1,56 @@ +#!/usr/bin/perl +# +# Include polygen output in a page +# +# by Enrico Zini +package IkiWiki::Plugin::polygen; + +use warnings; +use strict; +use IkiWiki; +use File::Find; + +sub import { #{{{ + IkiWiki::hook(type => "preprocess", id => "polygen", + call => \&preprocess); +} # }}} + +sub preprocess (@) { #{{{ + my %params=@_; + my $grammar = ($params{grammar} or 'polygen'); + my $symbol = ($params{symbol} or undef); + + # Sanitize parameters + $grammar =~ IkiWiki::basename($grammar); + $grammar =~ s/\.grm$//; + $grammar .= '.grm'; + $symbol =~ s/[^A-Za-z0-9]//g if defined $symbol; + + my $grmfile = '/usr/share/polygen/ita/polygen.grm'; + find({wanted => sub { + if (substr($File::Find::name, -length($grammar)) eq $grammar) { + $grmfile = IkiWiki::possibly_foolish_untaint($File::Find::name); + } + }, + no_chdir => 1, + }, '/usr/share/polygen'); + + my $res; + if (defined $symbol) { + $res = `polygen -S $symbol $grmfile 2>/dev/null`; + } + else { + $res = `polygen $grmfile 2>/dev/null`; + } + + if ($?) { + $res="[[polygen failed]]"; + } + + # Strip trainling spaces and newlines so that we flow well with the + # markdown text + $res =~ s/\s*$//; + return $res; +} # }}} + +1 |