Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki.git] / IkiWiki / Plugin / haiku.pm
blobbf23dce673f4b93a264545a4ab4c4156ef869eef
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);
14 sub getsetup {
15 return
16 plugin => {
17 safe => 1,
18 rebuild => undef,
19 section => "widget",
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.
34 "apt-get install Coy
35 no, wait, that's not quite it
36 instead: libcoy-perl
38 "Coyly I'll do it,
39 no code, count Five-Seven-Five
40 to make a haiku.
44 $haiku=$canned[rand @canned];
46 else {
47 $haiku=Coy::with_haiku($params{hint} ? $params{hint} : $params{page});
49 # trim off other text
50 $haiku=~s/\s+-----\n//s;
51 $haiku=~s/\s+-----.*//s;
54 $haiku=~s/^\s+//mg;
55 $haiku=~s/\n/<br \/>\n/mg;
57 return "\n\n<blockquote><p>$haiku</p></blockquote>\n\n";