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