From abd685d3ae68d6c2d2aedc4cdcf1eaec352fd9fc Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 14 May 2016 20:21:54 +0100 Subject: [PATCH 1/7] Constants: Switching to text template --- lib/DDG/Goodie/Constants.pm | 12 +++++--- t/Constants.t | 59 +++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 33 deletions(-) mode change 100644 => 100755 lib/DDG/Goodie/Constants.pm mode change 100644 => 100755 t/Constants.t diff --git a/lib/DDG/Goodie/Constants.pm b/lib/DDG/Goodie/Constants.pm old mode 100644 new mode 100755 index a215b70ac..71e4b5b1d --- a/lib/DDG/Goodie/Constants.pm +++ b/lib/DDG/Goodie/Constants.pm @@ -34,10 +34,14 @@ handle query_lc => sub { my $result = $val->{'html'} ? $val->{'html'} : $val->{'plain'}; return $result, structured_answer => { - input => [], - operation => $constant->{'name'}, - result => $result, - meta => { + data => { + title => $result, + subtitle => $constant->{'name'} + }, + templates => { + group => 'text', + }, + meta => { signal => 'high' } }; diff --git a/t/Constants.t b/t/Constants.t old mode 100644 new mode 100755 index c2a743637..b36c30a41 --- a/t/Constants.t +++ b/t/Constants.t @@ -9,46 +9,47 @@ 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 => { + title => $title, + subtitle => $subtitle, + }, + templates => { + group => 'text', + }, + 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( + '13 + 123 = 93 + 103', + 'Hardy Ramanujan Number 1729', + "13 + 123 = 93 + 103", ), #without apostrophe - "Avogadros number" => test_zci( + "Avogadros number" => build_test( + '6.0221415 × 1023 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 × 1023 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, From 6a2bb230f97a3e766d00fe247ae5f30e3cdcb1b1 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 14 May 2016 20:24:19 +0100 Subject: [PATCH 2/7] Constants: Editor wasn't in DDG mode so there are tabs in here --- lib/DDG/Goodie/Constants.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/DDG/Goodie/Constants.pm b/lib/DDG/Goodie/Constants.pm index 71e4b5b1d..990016239 100755 --- a/lib/DDG/Goodie/Constants.pm +++ b/lib/DDG/Goodie/Constants.pm @@ -34,13 +34,13 @@ handle query_lc => sub { my $result = $val->{'html'} ? $val->{'html'} : $val->{'plain'}; return $result, structured_answer => { - data => { - title => $result, - subtitle => $constant->{'name'} - }, - templates => { - group => 'text', - }, + data => { + title => $result, + subtitle => $constant->{'name'} + }, + templates => { + group => 'text', + }, meta => { signal => 'high' } From 683018f4a19cee7691d7e6d148b179fefbcad120 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 14 May 2016 20:26:09 +0100 Subject: [PATCH 3/7] Constants: It's crap that the IA currently returns HTML for the plain answer; no remedied --- lib/DDG/Goodie/Constants.pm | 2 +- t/Constants.t | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/DDG/Goodie/Constants.pm b/lib/DDG/Goodie/Constants.pm index 990016239..909ded7d8 100755 --- a/lib/DDG/Goodie/Constants.pm +++ b/lib/DDG/Goodie/Constants.pm @@ -33,7 +33,7 @@ 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 => { + return $val->{'plain'}, structured_answer => { data => { title => $result, subtitle => $constant->{'name'} diff --git a/t/Constants.t b/t/Constants.t index b36c30a41..252566343 100755 --- a/t/Constants.t +++ b/t/Constants.t @@ -29,19 +29,19 @@ sub build_test ddg_goodie_test( [qw( DDG::Goodie::Constants )], "Hardy Ramanujan number" => build_test( - '13 + 123 = 93 + 103', + '1^3 + 12^3 = 9^3 + 10^3', 'Hardy Ramanujan Number 1729', "13 + 123 = 93 + 103", ), #without apostrophe "Avogadros number" => build_test( - '6.0221415 × 1023 mol-1', + '6.0221415 × 10^23 mol^-1', 'Avogadro\'s Number', '6.0221415 × 1023 mol-1', ), #with apostrophe "Avogadro's number" => build_test( - '6.0221415 × 1023 mol-1', + '6.0221415 × 10^23 mol^-1', 'Avogadro\'s Number', '6.0221415 × 1023 mol-1', ), From 39b44adc0ceae3d441f2f5f900e448e81cc54fb3 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 14 May 2016 20:30:39 +0100 Subject: [PATCH 4/7] Constants: Switching to customised template --- lib/DDG/Goodie/Constants.pm | 7 +++++-- t/Constants.t | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/DDG/Goodie/Constants.pm b/lib/DDG/Goodie/Constants.pm index 909ded7d8..3da902834 100755 --- a/lib/DDG/Goodie/Constants.pm +++ b/lib/DDG/Goodie/Constants.pm @@ -35,11 +35,14 @@ handle query_lc => sub { return $val->{'plain'}, structured_answer => { data => { - title => $result, - subtitle => $constant->{'name'} + constant => $result, + description => $constant->{'name'} }, templates => { group => 'text', + options => { + content => 'DDH.constants.content' + } }, meta => { signal => 'high' diff --git a/t/Constants.t b/t/Constants.t index 252566343..19a29631c 100755 --- a/t/Constants.t +++ b/t/Constants.t @@ -14,11 +14,14 @@ sub build_test my ($text, $subtitle, $title) = @_; return test_zci($text, structured_answer => { data => { - title => $title, - subtitle => $subtitle, + constant => $title, + description => $subtitle, }, templates => { group => 'text', + options => { + content => 'DDH.constants.content' + } }, meta => { signal => 'high' From c7de248453befad3ec72fa4ca239fd715465ad16 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 14 May 2016 20:31:11 +0100 Subject: [PATCH 5/7] Constants: Adding handlebars template --- share/goodie/constants/content.handlebars | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 share/goodie/constants/content.handlebars diff --git a/share/goodie/constants/content.handlebars b/share/goodie/constants/content.handlebars new file mode 100755 index 000000000..eb5c87f4f --- /dev/null +++ b/share/goodie/constants/content.handlebars @@ -0,0 +1,6 @@ +
+

{{{constant}}}

+

+ {{description}} +

+
\ No newline at end of file From 7413a55eaeae3589da2856f80d57a6a575763eaa Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 30 May 2016 18:58:41 +0100 Subject: [PATCH 6/7] Constants: Tidying up the markup --- share/goodie/constants/content.handlebars | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/share/goodie/constants/content.handlebars b/share/goodie/constants/content.handlebars index eb5c87f4f..f77962927 100755 --- a/share/goodie/constants/content.handlebars +++ b/share/goodie/constants/content.handlebars @@ -1,6 +1,4 @@ -
-

{{{constant}}}

-

- {{description}} -

-
\ No newline at end of file +

{{{constant}}}

+

+ {{description}} +

From cb79350f1f4c6f6f1358370b3a292ba57e64ca4b Mon Sep 17 00:00:00 2001 From: Zaahir Moolla Date: Mon, 30 May 2016 16:35:19 -0400 Subject: [PATCH 7/7] Switch to subtitle with title_content template --- lib/DDG/Goodie/Constants.pm | 4 ++-- share/goodie/constants/content.handlebars | 4 ---- share/goodie/constants/title_content.handlebars | 1 + t/Constants.t | 8 ++++---- 4 files changed, 7 insertions(+), 10 deletions(-) delete mode 100755 share/goodie/constants/content.handlebars create mode 100755 share/goodie/constants/title_content.handlebars diff --git a/lib/DDG/Goodie/Constants.pm b/lib/DDG/Goodie/Constants.pm index 3da902834..1d1f927da 100755 --- a/lib/DDG/Goodie/Constants.pm +++ b/lib/DDG/Goodie/Constants.pm @@ -36,12 +36,12 @@ handle query_lc => sub { return $val->{'plain'}, structured_answer => { data => { constant => $result, - description => $constant->{'name'} + subtitle => $constant->{'name'} }, templates => { group => 'text', options => { - content => 'DDH.constants.content' + title_content => 'DDH.constants.title_content' } }, meta => { diff --git a/share/goodie/constants/content.handlebars b/share/goodie/constants/content.handlebars deleted file mode 100755 index f77962927..000000000 --- a/share/goodie/constants/content.handlebars +++ /dev/null @@ -1,4 +0,0 @@ -

{{{constant}}}

-

- {{description}} -

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 index 19a29631c..c2fa33263 100755 --- a/t/Constants.t +++ b/t/Constants.t @@ -15,12 +15,12 @@ sub build_test return test_zci($text, structured_answer => { data => { constant => $title, - description => $subtitle, + subtitle => $subtitle, }, templates => { group => 'text', options => { - content => 'DDH.constants.content' + title_content => 'DDH.constants.title_content' } }, meta => { @@ -34,7 +34,7 @@ ddg_goodie_test( "Hardy Ramanujan number" => build_test( '1^3 + 12^3 = 9^3 + 10^3', 'Hardy Ramanujan Number 1729', - "13 + 123 = 93 + 103", + "13 + 123 = 93 + 103", ), #without apostrophe "Avogadros number" => build_test( @@ -55,7 +55,7 @@ ddg_goodie_test( '0.577215665', ), "How old is my grandma?" => undef, - "why?" => undef, + "why?" => undef, ); done_testing;