Merge pull request #3051 from duckduckgo/mintsoft/constants-template

Constants: Switching to template
master
Zaahir Moolla 2016-06-08 15:27:45 -04:00
commit 520893b409
3 changed files with 47 additions and 35 deletions

17
lib/DDG/Goodie/Constants.pm Normal file → Executable file
View File

@ -33,11 +33,18 @@ handle query_lc => sub {
#fallback to plain answer if html is not present #fallback to plain answer if html is not present
my $result = $val->{'html'} ? $val->{'html'} : $val->{'plain'}; my $result = $val->{'html'} ? $val->{'html'} : $val->{'plain'};
return $result, structured_answer => { return $val->{'plain'}, structured_answer => {
input => [], data => {
operation => $constant->{'name'}, constant => $result,
result => $result, subtitle => $constant->{'name'}
meta => { },
templates => {
group => 'text',
options => {
title_content => 'DDH.constants.title_content'
}
},
meta => {
signal => 'high' signal => 'high'
} }
}; };

View File

@ -0,0 +1 @@
<h3 class='c-base__title'>{{{constant}}}</h3>

64
t/Constants.t Normal file → Executable file
View File

@ -10,49 +10,53 @@ use DDG::Test::Goodie;
zci answer_type => "constants"; zci answer_type => "constants";
zci is_cached => 1; zci is_cached => 1;
sub build_test
{
my ($text, $subtitle, $title) = @_;
return test_zci($text, structured_answer => {
data => {
constant => $title,
subtitle => $subtitle,
},
templates => {
group => 'text',
options => {
title_content => 'DDH.constants.title_content'
}
},
meta => {
signal => 'high'
}
});
}
ddg_goodie_test( ddg_goodie_test(
[qw( DDG::Goodie::Constants )], [qw( DDG::Goodie::Constants )],
"Hardy Ramanujan number" => test_zci( "Hardy Ramanujan number" => build_test(
'1<sup>3</sup> + 12<sup>3</sup> = 9<sup>3</sup> + 10<sup>3</sup>', '1^3 + 12^3 = 9^3 + 10^3',
structured_answer => { 'Hardy Ramanujan Number 1729',
input => [], "1<sup>3</sup> + 12<sup>3</sup> = 9<sup>3</sup> + 10<sup>3</sup>",
operation => 'Hardy Ramanujan Number 1729',
result => "1<sup>3</sup> + 12<sup>3</sup> = 9<sup>3</sup> + 10<sup>3</sup>",
meta => {signal => 'high'}
}
), ),
#without apostrophe #without apostrophe
"Avogadros number" => test_zci( "Avogadros number" => build_test(
'6.0221415 × 10^23 mol^-1',
'Avogadro\'s Number',
'6.0221415 × 10<sup>23</sup> mol<sup>-1</sup>', '6.0221415 × 10<sup>23</sup> mol<sup>-1</sup>',
structured_answer => {
input => [],
operation => 'Avogadro\'s Number',
result => '6.0221415 × 10<sup>23</sup> mol<sup>-1</sup>',
meta => {signal => 'high'}
}
), ),
#with apostrophe #with apostrophe
"Avogadro's number" => test_zci( "Avogadro's number" => build_test(
'6.0221415 × 10^23 mol^-1',
'Avogadro\'s Number',
'6.0221415 × 10<sup>23</sup> mol<sup>-1</sup>', '6.0221415 × 10<sup>23</sup> mol<sup>-1</sup>',
structured_answer => {
input => [],
operation => 'Avogadro\'s Number',
result => '6.0221415 × 10<sup>23</sup> mol<sup>-1</sup>',
meta => {signal => 'high'}
}
), ),
#constant without html (only plain) #constant without html (only plain)
"Eulers constant" => test_zci( "Eulers constant" => build_test(
'0.577215665',
"Euler's Constant",
'0.577215665', '0.577215665',
structured_answer => {
input => [],
operation => 'Euler\'s Constant',
result => '0.577215665',
meta => {signal => 'high'}
}
), ),
"How old is my grandma?" => undef, "How old is my grandma?" => undef,
"why?" => undef, "why?" => undef,
); );
done_testing; done_testing;