]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/haiku.pm
hack to support media:content
[git.ikiwiki.info.git] / IkiWiki / Plugin / haiku.pm
1 #!/usr/bin/perl
2 # haiku generator plugin
3 package IkiWiki::Plugin::haiku;
5 use warnings;
6 use strict;
7 use IkiWiki 3.00;
9 sub import {
10         hook(type => "getsetup", id => "haiku", call => \&getsetup);
11         hook(type => "preprocess", id => "haiku", call => \&preprocess);
12 }
14 sub getsetup {
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => undef,
19                         section => "widget",
20                 },
21 }
23 sub preprocess (@) {
24         my %params=@_;
26         my $haiku;
27         eval q{use Coy};
28         if ($config{deterministic}) {
29                 $haiku = "Coy changes often.
30                           For deterministic builds
31                           try this substitute.
32                          ",
33         }
34         elsif ($@ || ! Coy->can("Coy::with_haiku")) {
35                 my @canned=(
36                         "The lack of a Coy:
37                          No darting, subtle haiku.
38                          Instead, canned tuna.
39                         ",
40                         "apt-get install Coy
41                          no, wait, that's not quite it
42                          instead: libcoy-perl
43                         ",
44                         "Coyly I'll do it,
45                          no code, count Five-Seven-Five
46                          to make a haiku.
47                         ",
48                 );
49                                          
50                 $haiku=$canned[rand @canned];
51         }
52         else {
53                 $haiku=Coy::with_haiku($params{hint} ? $params{hint} : $params{page});
54                 
55                 # trim off other text
56                 $haiku=~s/\s+-----\n//s;
57                 $haiku=~s/\s+-----.*//s;
58         }
59                 
60         $haiku=~s/^\s+//mg;
61         $haiku=~s/\n/<br \/>\n/mg;
62         
63         return "\n\n<blockquote><p>$haiku</p></blockquote>\n\n";
64 }
66 1