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