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