zeroclickinfo-goodies/lib/DDG/Goodie/CssColors.pm

65 lines
1.5 KiB
Perl
Raw Normal View History

2016-07-16 14:36:26 -07:00
package DDG::Goodie::CssColors;
# ABSTRACT: List of all the named CSS colors
use DDG::Goodie;
use strict;
use warnings;
use Color::Library;
zci answer_type => 'csscolors';
2016-07-16 14:36:26 -07:00
zci is_cached => 1;
triggers startend => share('triggers.txt')->slurp;
2016-07-18 14:13:33 -07:00
2016-08-09 12:48:27 -07:00
my @color_names = Color::Library::Dictionary::Mozilla->names;
2016-07-16 14:36:26 -07:00
handle remainder => sub {
2016-07-16 14:36:26 -07:00
# Verify we have no remainder
return if $_;
my $query_lc = $req->query_lc;
2016-07-16 14:36:26 -07:00
my @color_list;
2016-08-09 12:48:27 -07:00
foreach ( @color_names ) {
2016-08-09 12:46:10 -07:00
my $color_code = uc Color::Library->Mozilla->color($_);
push @color_list, { color_name => $_, color_code => "$color_code" };
}
my ($title, $subtitle);
$title = 'CSS ';
$subtitle = 'List of named CSS ';
if ( $query_lc =~ /colors/i ) {
$title .= 'Colors';
$subtitle .= 'colors';
} else {
$title .= 'Colours';
$subtitle .= 'colours';
}
2016-07-16 14:36:26 -07:00
return 'CSS Colors',
structured_answer => {
data => {
title => $title,
subtitle => $subtitle,
list => \@color_list
2016-07-16 14:36:26 -07:00
},
templates => {
group => 'list',
options => {
2016-07-16 15:19:04 -07:00
list_content => 'DDH.css_colors.content'
2016-07-16 14:36:26 -07:00
}
2016-10-11 09:00:20 -07:00
},
meta => {
sourceName => 'Mozilla Developer Network',
sourceUrl => 'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_keywords'
2016-07-16 14:36:26 -07:00
}
};
};
1;