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

Commit

Permalink
Calculator: Switch to canonical structured answer (#3916)
Browse files Browse the repository at this point in the history
* Switch Calculator to canoncial structured answer

* Add Goodie Template
  • Loading branch information
moollaza authored Feb 6, 2017
1 parent a22710e commit 5f7329f
Show file tree
Hide file tree
Showing 3 changed files with 314 additions and 665 deletions.
21 changes: 14 additions & 7 deletions lib/DDG/Goodie/Calculator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ handle query_nowhitespace => sub {

my $results = prepare_for_display($query, $tmp_result, $style);

return unless $results && $results->{text};
return if $results->{text} =~ /^\s/;
return $results->{text},
structured_answer => $results->{structured},
heading => "Calculator";
structured_answer => $results->{structured};
};

sub prepare_for_display {
Expand All @@ -174,12 +174,19 @@ sub prepare_for_display {
$spaced_query =~ s/^ - /-/;

return +{
text => $spaced_query . ' = ' . $result,
text => "$spaced_query = $result",
structured => {
input => [$spaced_query],
operation => 'Calculate',
result => "<a href='javascript:;' onclick='document.x.q.value=\"$result\";document.x.q.focus();'>" . $style->with_html($result) . "</a>"
},
data => {
title_html => $style->with_html($result),
subtitle => "Calculate: $spaced_query"
},
templates => {
group => 'text',
options => {
title_content => 'DDH.calculator.title_content'
}
}
}
};
}

Expand Down
1 change: 1 addition & 0 deletions share/goodie/calculator/title_content.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h3 class="c-base__title">{{{title_html}}}</h3>
Loading

0 comments on commit 5f7329f

Please sign in to comment.