]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/haiku.pm
Merge branch 'master' into commentreorg
[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 ($@ || ! Coy->can("Coy::with_haiku")) {
29                 my @canned=(
30                         "The lack of a Coy:
31                          No darting, subtle haiku.
32                          Instead, canned tuna.
33                         ",
34                         "apt-get install Coy
35                          no, wait, that's not quite it
36                          instead: libcoy-perl
37                         ",
38                         "Coyly I'll do it,
39                          no code, count Five-Seven-Five
40                          to make a haiku.
41                         ",
42                 );
43                                          
44                 $haiku=$canned[rand @canned];
45         }
46         else {
47                 $haiku=Coy::with_haiku($params{hint} ? $params{hint} : $params{page});
48                 
49                 # trim off other text
50                 $haiku=~s/\s+-----\n//s;
51                 $haiku=~s/\s+-----.*//s;
52         }
53                 
54         $haiku=~s/^\s+//mg;
55         $haiku=~s/\n/<br \/>\n/mg;
56         
57         return "\n\n<blockquote><p>$haiku</p></blockquote>\n\n";
58 }
60 1