X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sweavealike.pm;h=f802fa5957f78b476780ddd98ea51886eda7d8af;hb=66d9a79ab1e07d0c817b836c04e67f7bab2f6122;hp=d58ad6822c774b62ba597062699399f007abd592;hpb=77890a593855f45d0c70b8bfb29c91358875909e;p=ikiwiki_plugins.git diff --git a/sweavealike.pm b/sweavealike.pm index d58ad68..f802fa5 100644 --- a/sweavealike.pm +++ b/sweavealike.pm @@ -124,9 +124,8 @@ sub preprocess { error("There wasn't any R code supplied"); } - my $image_loc + my $image_loc = ''; if (exists $param{fig}) { - $pagestate{$param{page}}{$id}{fignum}++; $param{width} = '400' unless exists $param{width} and defined $param{width}; $param{height} = '400' unless exists $param{height} and defined $param{height}; for (qw(width height)) { @@ -134,17 +133,19 @@ sub preprocess { error("invalid $_; must be an integer: $param{$_}"); } } - # because even if the code is duplicated, the figure could still be the same. + # because even if the code is duplicated, the figure could + # still be different, we track the number of figures + $pagestate{$param{page}}{$id}{fignum}++; my $md5 = code_md5($param{code},$param{width},$param{height},$pagestate{$param{page}}{$id}{fignum}); $image_loc = "$param{page}/${md5}.png"; my $image_loc_esc = $image_loc; $image_loc_esc =~ s/"/\\"/g; will_render($param{page},$image_loc); eval { - $pagestate{$param{page}}{$id}{R}->run(qq{png(filename="$image_loc_esc",width=$param{width},height=$param{height});}); + $pagestate{$param{page}}{$id}{R}->run(qq|png(filename="$image_loc_esc",width=$param{width},height=$param{height});|); }; if ($@) { - error("code 'png(filename="$image_loc_esc",width=$param{width},height=$param{height});' (from internal figure handling) produced error '$@'"); + error(qq|code 'png(filename="$image_loc_esc",width=$param{width},height=$param{height});' (from internal figure handling) produced error '$@'|); } } my $code_result; @@ -175,7 +176,7 @@ sub preprocess { } if (not exists $param{results} or (defined $param{results} and - $param{results} !~ /^(hide|false)$/i;)) { + $param{results} !~ /^(hide|false)$/i)) { $output .= $code_result; } if (exists $param{echo} or @@ -203,12 +204,15 @@ sub savestate { # make sure we never try to save an R process for my $page (keys %pagestate) { next unless exists $pagestate{$page}{$id}; - next unless exists $pagestate{$page}{$id}{R}; - if (defined $pagestate{$page}{$id}{R} - and $pagestate{$page}{$id}{R}->is_started()) { - $pagestate{$page}{$id}{R}->stop; + if (exists $pagestate{$page}{$id}{R}) { + if (defined $pagestate{$page}{$id}{R} + and $pagestate{$page}{$id}{R}->is_started()) { + $pagestate{$page}{$id}{R}->stop; + } + } + if (exists $pagestate{$page}{$id}{fignum}) { + delete $pagestate{$page}{$id}{fignum} } - delete $pagestate{$page}{$id}{R}; } }