aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/haiku.pm
blob: 7ce74696ba474aa3e4a75d12f7a2cf3eb49b02cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl
# haiku generator plugin
package IkiWiki::Plugin::haiku;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type => "getsetup", id => "haiku", call => \&getsetup);
	hook(type => "preprocess", id => "haiku", call => \&preprocess);
}

sub getsetup {
	return
		plugin => {
			safe => 1,
			rebuild => undef,
			section => "widget",
		},
}

sub preprocess (@) {
	my %params=@_;

	my $haiku;
	eval q{use Coy};
	if ($config{deterministic}) {
		$haiku = "Coy changes often.
			  For deterministic builds
			  try this substitute.
			 ",
	}
	elsif ($@ || ! Coy->can("Coy::with_haiku")) {
		my @canned=(
			"The lack of a Coy:
			 No darting, subtle haiku.
			 Instead, canned tuna.
			",
			"apt-get install Coy
			 no, wait, that's not quite it
			 instead: libcoy-perl
			",
			"Coyly I'll do it,
			 no code, count Five-Seven-Five
			 to make a haiku.
			",
		);
			 		 
		$haiku=$canned[rand @canned];
	}
	else {
		$haiku=Coy::with_haiku($params{hint} ? $params{hint} : $params{page});
		
		# trim off other text
		$haiku=~s/\s+-----\n//s;
		$haiku=~s/\s+-----.*//s;
	}
		
	$haiku=~s/^\s+//mg;
	$haiku=~s/\n/<br \/>\n/mg;
	
	return "\n\n<blockquote><p>$haiku</p></blockquote>\n\n";
}

1