]> git.donarmstrong.com Git - ikiwiki_plugins.git/blobdiff - sweavealike.pm
make more verbose error messages
[ikiwiki_plugins.git] / sweavealike.pm
index 939f803dce772ea2ad7165eef871cf064e14e60e..661a4316e1806d7b38cd847747236c5043f2056a 100644 (file)
@@ -32,27 +32,35 @@ 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
 
-    if (not exists $param{code} or not defined $param{code}) {
+    if (not exists $param{code}
+       or not defined $param{code}
+       or not length $param{code}) {
        error("There wasn't any R code supplied");
     }
     my $code_result;
@@ -60,10 +68,10 @@ sub preprocess {
        $code_result = $pagestate{$param{page}}{$id}{R}->run($param{code});
     };
     if ($@) {
-       error($@);
+       error("code '$param{code}' produced error '$@'");
     }
-    my $output;
-    if ($param{verbatim}) {
+    my $output = "sweave output\n\n";
+    if (exists $param{verbatim}) {
        $output = $param{code};
        $output =~ s/^/> /mg;
     }