]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/sparkline.pm
support previewing of sparklines: embed in data uris for preview
[git.ikiwiki.info.git] / IkiWiki / Plugin / sparkline.pm
index a44e062520f9132d89f91f83ef37a8d3e49f50bc..63c2cf94391127018dbc57460ecb5a8569c73e46 100644 (file)
@@ -108,10 +108,6 @@ sub preprocess (@) { #{{{
                $php.=qq{\$sparkline->RenderResampled($width, $height);\n};
        }
        
-       if ($params{preview}) {
-               return "[[".gettext("sparkline previewing not implemented")."]]";
-       }
-       
        $php.=qq{\$sparkline->Output();\n?>\n};
 
        # Use the sha1 of the php code that generates the sparkline as
@@ -148,7 +144,16 @@ sub preprocess (@) { #{{{
                        return  "[[".gettext("sparkline failed to run php")."]]";
                }
 
-               writefile($fn, $config{destdir}, $png, 1);
+               if (! $params{preview}) {
+                       writefile($fn, $config{destdir}, $png, 1);
+               }
+               else {
+                       # can't write the file, so embed it in a data uri
+                       eval q{use MIME::Base64};
+                       error($@) if $@;
+                       return "<img src=\"data:image/png;base64,".
+                               encode_base64($png)."\" />";
+               }
        }
 
        return '<img src="'.