]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/teximg.pm
add plugin safe/rebuild info (part 3 of 3)
[ikiwiki.git] / IkiWiki / Plugin / teximg.pm
index f7fd91ddf2a7156934a0a6c71ee52b1f294bea01..369c1088203cb2ec86e397bd46e9a98e1a4e544d 100644 (file)
@@ -11,9 +11,18 @@ use HTML::Entities;
 use IkiWiki 2.00;
 
 sub import { #{{{
+       hook(type => "getsetup", id => "teximg", call => \&getsetup);
        hook(type => "preprocess", id => "teximg", call => \&preprocess);
 } #}}}
 
+sub getsetup () { #{{{
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => undef,
+               },
+} #}}}
+
 sub preprocess (@) { #{{{
        my %params = @_;
        
@@ -27,14 +36,14 @@ sub preprocess (@) { #{{{
        
        my $code = $params{code};
        if (! defined $code && ! length $code) {
-               return "[[teximg ".gettext("missing tex code"). "]]";
+               error gettext("missing tex code");
        }
 
        if (check($code)) {
                return create($code, check_height($height), \%params);
        }
        else {
-               return "[[teximg ".gettext("code includes disallowed latex commands"). "]]";
+               error gettext("code includes disallowed latex commands")
        }
 } #}}}
 
@@ -70,13 +79,13 @@ sub create ($$$) { #{{{
 
        my $digest = md5_hex($code, $height);
 
-       my $imglink= $params->{destpage} . "/$digest.png";
-       my $imglog =  $params->{destpage} .  "/$digest.log";
-       will_render($params->{destpage}, $imglink);
-       will_render($params->{destpage}, $imglog);
+       my $imglink= $params->{page} . "/$digest.png";
+       my $imglog =  $params->{page} .  "/$digest.log";
+       will_render($params->{page}, $imglink);
+       will_render($params->{page}, $imglog);
 
        my $imgurl=urlto($imglink, $params->{destpage});
-       my $logurl=urlto($imglink, $params->{destpage});
+       my $logurl=urlto($imglog, $params->{destpage});
        
        if (-e "$config{destdir}/$imglink" ||
            gen_image($code, $height, $digest, $params->{page})) {
@@ -85,7 +94,7 @@ sub create ($$$) { #{{{
                        .qq{" class="teximg" />};
        }
        else {
-               return qq{[[teximg <a href="$logurl">}.gettext("failed to generate image from code")."</a>]]";
+               error qq{<a href="$logurl">}.gettext("failed to generate image from code")."</a>";
        }
 } #}}}
 
@@ -119,12 +128,13 @@ sub gen_image ($$$$) { #{{{
        }
        else {
                # store failure log
-               my $log;
+               my $log="";
                {
-                       open(my $f, '<', "$tmp/$digest.log");
-                       local $/=undef;
-                       $log = <$f>;
-                       close($f);
+                       if (open(my $f, '<', "$tmp/$digest.log")) {
+                               local $/=undef;
+                               $log = <$f>;
+                               close($f);
+                       }
                }
                writefile("$digest.log", "$config{destdir}/$imagedir", $log);