2014-03-09 10:05:19 -07:00
|
|
|
package DDG::Goodie::FIGlet;
|
|
|
|
# ABSTRACT: Uses FIGlet to make large letters out of ordinary text.
|
2014-11-05 12:33:49 -08:00
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2014-11-05 12:22:44 -08:00
|
|
|
use utf8;
|
2014-03-09 10:05:19 -07:00
|
|
|
use DDG::Goodie;
|
|
|
|
use Text::FIGlet;
|
|
|
|
|
2014-04-21 04:47:07 -07:00
|
|
|
triggers startend => "figlet", "bigtext", "big text";
|
2014-03-09 10:05:19 -07:00
|
|
|
primary_example_queries 'figlet DuckDuckGo';
|
2014-03-20 08:48:33 -07:00
|
|
|
secondary_example_queries 'figlet computer DuckDuckGo';
|
2014-03-09 10:05:19 -07:00
|
|
|
|
|
|
|
name 'FIGlet';
|
|
|
|
description 'Uses FIGlet to make large letters out of ordinary text.';
|
|
|
|
category 'transformations';
|
|
|
|
topics 'words_and_games';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Figlet.pm';
|
|
|
|
attribution
|
2014-03-31 09:15:14 -07:00
|
|
|
web => ['http://engvik.nu', 'Lars Jansøn Engvik'],
|
|
|
|
github => [ 'larseng', 'Lars Jansøn Engvik'];
|
2014-03-09 10:05:19 -07:00
|
|
|
|
|
|
|
zci answer_type => 'figlet';
|
|
|
|
zci is_cached => 1;
|
|
|
|
|
2014-04-06 07:11:11 -07:00
|
|
|
my $width = 800;
|
2014-03-09 10:05:19 -07:00
|
|
|
|
2014-03-20 11:49:37 -07:00
|
|
|
# Fetch available fonts.
|
|
|
|
opendir DIR, share();
|
|
|
|
my @fonts = readdir(DIR);
|
|
|
|
closedir DIR;
|
|
|
|
|
2014-03-20 08:48:33 -07:00
|
|
|
# Renders a figlet.
|
|
|
|
sub render_figlet {
|
2014-03-31 09:15:14 -07:00
|
|
|
my ($font, $text) = @_;
|
2014-06-05 02:34:43 -07:00
|
|
|
return Text::FIGlet->new(-f=>$font, -d=>share())->figify(-w=>$width, -A=>$text);
|
2014-03-20 08:48:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handle query => sub {
|
2014-03-31 09:15:14 -07:00
|
|
|
my $font;
|
|
|
|
my $text;
|
|
|
|
my $figlet;
|
2014-03-28 01:41:09 -07:00
|
|
|
my $html;
|
2014-03-31 09:15:14 -07:00
|
|
|
|
|
|
|
# Return if no input provided.
|
2014-05-13 13:02:20 -07:00
|
|
|
return if ((lc $_ eq 'figlet') || (lc $_ eq 'bigtext') || (lc $_ eq 'big text'));
|
2014-03-20 08:48:33 -07:00
|
|
|
|
2014-03-28 01:41:09 -07:00
|
|
|
# Parse query.
|
2014-05-13 13:02:20 -07:00
|
|
|
$_ =~ m/^(?:figlet|bigtext|big text)(?:\-|\s+)(.*)|(.*)\s+(?:figlet|bigtext|big text)$/i;
|
2014-03-28 01:41:09 -07:00
|
|
|
$text = $1 if $1;
|
|
|
|
$text = $2 if $2;
|
|
|
|
|
2014-03-31 09:15:14 -07:00
|
|
|
# Checks if the first word is a font.
|
|
|
|
$text =~ m/^\s*(\w+)/;
|
|
|
|
$font = lc $1 if grep /\b$1\b/i, @fonts;
|
|
|
|
|
|
|
|
# Strip the font from the text to render if we're using a font.
|
|
|
|
if ($font && $font ne $text) {
|
|
|
|
$text = substr $text, length ($font)+1, length $text;
|
|
|
|
} else {
|
|
|
|
$font = "standard";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Render the FIGlet
|
|
|
|
$figlet = render_figlet($font, $text);
|
|
|
|
|
2014-06-05 02:34:43 -07:00
|
|
|
$html = "<div id='figlet-wrapper'><span>Font: </span><span id='figlet-font'>$font</span><pre contenteditable='true'>$figlet</pre></div>";
|
|
|
|
|
2014-08-26 12:32:09 -07:00
|
|
|
return $figlet, html => $html if $figlet;
|
2014-03-31 09:15:14 -07:00
|
|
|
return;
|
2014-03-09 10:05:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
1;
|