diff --git a/lib/DDG/Goodie/Constants.pm b/lib/DDG/Goodie/Constants.pm old mode 100644 new mode 100755 index a215b70ac..1d1f927da --- a/lib/DDG/Goodie/Constants.pm +++ b/lib/DDG/Goodie/Constants.pm @@ -33,11 +33,18 @@ handle query_lc => sub { #fallback to plain answer if html is not present my $result = $val->{'html'} ? $val->{'html'} : $val->{'plain'}; - return $result, structured_answer => { - input => [], - operation => $constant->{'name'}, - result => $result, - meta => { + return $val->{'plain'}, structured_answer => { + data => { + constant => $result, + subtitle => $constant->{'name'} + }, + templates => { + group => 'text', + options => { + title_content => 'DDH.constants.title_content' + } + }, + meta => { signal => 'high' } }; diff --git a/share/goodie/constants/title_content.handlebars b/share/goodie/constants/title_content.handlebars new file mode 100755 index 000000000..7513260a9 --- /dev/null +++ b/share/goodie/constants/title_content.handlebars @@ -0,0 +1 @@ +

{{{constant}}}

diff --git a/t/Constants.t b/t/Constants.t old mode 100644 new mode 100755 index 95ceb80be..8f8239bf1 --- a/t/Constants.t +++ b/t/Constants.t @@ -10,49 +10,53 @@ use DDG::Test::Goodie; zci answer_type => "constants"; 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( [qw( DDG::Goodie::Constants )], - "Hardy Ramanujan number" => test_zci( - '13 + 123 = 93 + 103', - structured_answer => { - input => [], - operation => 'Hardy Ramanujan Number 1729', - result => "13 + 123 = 93 + 103", - meta => {signal => 'high'} - } + "Hardy Ramanujan number" => build_test( + '1^3 + 12^3 = 9^3 + 10^3', + 'Hardy Ramanujan Number 1729', + "13 + 123 = 93 + 103", ), #without apostrophe - "Avogadros number" => test_zci( + "Avogadros number" => build_test( + '6.0221415 × 10^23 mol^-1', + 'Avogadro\'s Number', '6.0221415 × 1023 mol-1', - structured_answer => { - input => [], - operation => 'Avogadro\'s Number', - result => '6.0221415 × 1023 mol-1', - meta => {signal => 'high'} - } ), #with apostrophe - "Avogadro's number" => test_zci( + "Avogadro's number" => build_test( + '6.0221415 × 10^23 mol^-1', + 'Avogadro\'s Number', '6.0221415 × 1023 mol-1', - structured_answer => { - input => [], - operation => 'Avogadro\'s Number', - result => '6.0221415 × 1023 mol-1', - meta => {signal => 'high'} - } ), #constant without html (only plain) - "Eulers constant" => test_zci( + "Eulers constant" => build_test( + '0.577215665', + "Euler's Constant", '0.577215665', - structured_answer => { - input => [], - operation => 'Euler\'s Constant', - result => '0.577215665', - meta => {signal => 'high'} - } ), "How old is my grandma?" => undef, - "why?" => undef, + "why?" => undef, ); done_testing;