X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sweavealike.pm;h=ec6660c09e77e4d26dbb32b3129b8db073aacbc7;hb=c0ca3e7a81d0efccde44e827671bf33e559f356d;hp=c8bcbadae185596050d1c407da39e9c50a71daee;hpb=ba8fd5520052c61c5eed8384453f374f81088bcc;p=ikiwiki_plugins.git diff --git a/sweavealike.pm b/sweavealike.pm index c8bcbad..ec6660c 100644 --- a/sweavealike.pm +++ b/sweavealike.pm @@ -28,27 +28,33 @@ use strict; use Statistics::R; -use IkiWIki '3.00'; +use IkiWiki '3.00'; my $id = "sweavealike"; sub import { + hook(type => "getsetup", id => $id, call => \&getsetup); hook(type => "preprocess", id => $id, call => \&preprocess); - hook(type => "preprocess", id => $id, call => \&preprocess_scan, scan => 1); hook(type => "htmlize", id => $id, call => \&htmlize); hook(type => "savestate", id => $id, call => \&savestate); } -sub preprocess_scan { - my %param = @_; - # start the R process here for this page - if (not defined $pagestate{$param{page}}{$id}{R}) { - $pagestate{$param{page}}{$id}{R} = Statistics::R->new(shared => 1) or error("Unable to create an R process"); - } +sub getsetup { + return(plugin => {safe => 1, + rebuild => 1, + section => "misc", + link => "http://git.donarmstrong.com/?p=ikiwiki_plugins.git;a=blob;f=sweavealike.pm;hb=HEAD", + description => "sweavealike plugin", + }, + ); } sub preprocess { my %param = @_; + if (not defined $pagestate{$param{page}}{$id}{R}) { + $pagestate{$param{page}}{$id}{R} = Statistics::R->new(shared => 1) + or error("Unable to create an R process"); + } # we currently don't bother to support anything but outputing the # entire segment of code and its R output @@ -62,8 +68,8 @@ sub preprocess { if ($@) { error($@); } - my $output; - if ($param{verbatim}) { + my $output = "sweave output\n\n"; + if (exists $param{verbatim}) { $output = $param{code}; $output =~ s/^/> /mg; } @@ -92,7 +98,7 @@ sub savestate { next unless exists $pagestate{$page}{$id}; next unless exists $pagestate{$page}{$id}{R}; if (defined $pagestate{$page}{$id}{R} - and $pagestate{$param{page}}{$id}{R}->is_started()) { + and $pagestate{$page}{$id}{R}->is_started()) { $pagestate{$page}{$id}{R}->stop; } delete $pagestate{$page}{$id}{R};