Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Commit 5f44c57

Browse files
author
Jag Talon
committed
Merge pull request #359 from larseng/master
Adding FIGlet support.
2 parents 4053bd5 + 3a4d7be commit 5f44c57

File tree

155 files changed

+5543
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+5543
-0
lines changed

dist.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Math::Int2Base = 1.00
1919
Data::GUID = 0.046
2020
IO::All = 0.44
2121
File::ShareDir::ProjectDistDir = 0.2.0
22+
Text::FIGlet = 2.19.3
2223
Text::Unidecode = 0.04
2324
Date::Calc = 6.3
2425
Date::Hijri = 0.02

lib/DDG/Goodie/FIGlet.pm

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package DDG::Goodie::FIGlet;
2+
# ABSTRACT: Uses FIGlet to make large letters out of ordinary text.
3+
4+
use DDG::Goodie;
5+
use Text::FIGlet;
6+
7+
triggers startend => "figlet", "bigtext", "big text";
8+
primary_example_queries 'figlet DuckDuckGo';
9+
secondary_example_queries 'figlet computer DuckDuckGo';
10+
11+
name 'FIGlet';
12+
description 'Uses FIGlet to make large letters out of ordinary text.';
13+
category 'transformations';
14+
topics 'words_and_games';
15+
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Figlet.pm';
16+
attribution
17+
web => ['http://engvik.nu', 'Lars Jansøn Engvik'],
18+
github => [ 'larseng', 'Lars Jansøn Engvik'];
19+
20+
zci answer_type => 'figlet';
21+
zci is_cached => 1;
22+
23+
my $width = 800;
24+
my $css = share("style.css")->slurp;
25+
26+
# Fetch available fonts.
27+
opendir DIR, share();
28+
my @fonts = readdir(DIR);
29+
closedir DIR;
30+
31+
# Renders a figlet.
32+
sub render_figlet {
33+
my ($font, $text) = @_;
34+
return Text::FIGlet->new(-f=>$font, -d=>share())->figify(-w=>$width, -A=>$text);
35+
}
36+
37+
# Apply CSS.
38+
sub apply_css {
39+
my ($html) = @_;
40+
return "<style type='text/css'>$css</style>\n" . $html;
41+
}
42+
43+
handle query => sub {
44+
my $font;
45+
my $text;
46+
my $figlet;
47+
my $html;
48+
49+
# Return if no input provided.
50+
return if ((lc $_ eq 'figlet') || (lc $_ eq 'bigtext') || (lc $_ eq 'big text'));
51+
52+
# Parse query.
53+
$_ =~ m/^(?:figlet|bigtext|big text)(?:\-|\s+)(.*)|(.*)\s+(?:figlet|bigtext|big text)$/i;
54+
$text = $1 if $1;
55+
$text = $2 if $2;
56+
57+
# Checks if the first word is a font.
58+
$text =~ m/^\s*(\w+)/;
59+
$font = lc $1 if grep /\b$1\b/i, @fonts;
60+
61+
# Strip the font from the text to render if we're using a font.
62+
if ($font && $font ne $text) {
63+
$text = substr $text, length ($font)+1, length $text;
64+
} else {
65+
$font = "standard";
66+
}
67+
68+
# Render the FIGlet
69+
$figlet = render_figlet($font, $text);
70+
71+
$html = "<div id='figlet-wrapper'><span>Font: </span><span id='figlet-font'>$font</span><pre contenteditable='true'>$figlet</pre></div>";
72+
73+
return $figlet, html => apply_css($html) if $figlet;
74+
return;
75+
};
76+
77+
1;

share/goodie/figlet/3d.flf

1.47 KB
Binary file not shown.

share/goodie/figlet/3x5.flf

754 Bytes
Binary file not shown.
1.7 KB
Binary file not shown.

share/goodie/figlet/acrobatic.flf

3.14 KB
Binary file not shown.

share/goodie/figlet/alligator.flf

1.47 KB
Binary file not shown.

share/goodie/figlet/alligator2.flf

1.37 KB
Binary file not shown.

share/goodie/figlet/alphabet.flf

1.63 KB
Binary file not shown.

share/goodie/figlet/avatar.flf

1.29 KB
Binary file not shown.

0 commit comments

Comments
 (0)