From fbd578ecaca9c88c95f251e1c2bea44b37c0018d Mon Sep 17 00:00:00 2001 From: jagtalon Date: Wed, 4 Jun 2014 16:57:36 +0000 Subject: [PATCH 1/5] Conversions: Increase font-size to 1.5em I added style.css in the share directory of the conversions so that I can make the output prettier. --- lib/DDG/Goodie/Conversions.pm | 11 ++- share/goodie/conversions/style.css | 3 + t/Conversions.t | 118 ++++++++++++++--------------- 3 files changed, 72 insertions(+), 60 deletions(-) create mode 100644 share/goodie/conversions/style.css diff --git a/lib/DDG/Goodie/Conversions.pm b/lib/DDG/Goodie/Conversions.pm index e0ab198db01..73b9c7ae67b 100755 --- a/lib/DDG/Goodie/Conversions.pm +++ b/lib/DDG/Goodie/Conversions.pm @@ -55,6 +55,14 @@ my %plural_exceptions = ( 'pounds force' => 'pounds force', ); +# This function adds some HTML and styling to our output +# so that we can make it prettier. +my $css = share("style.css")->slurp; +sub wrap_html { + my $output = shift; + return "
$output
"; +} + handle query_lc => sub { # hack around issues with feet and inches for now $_ =~ s/"/inches/; @@ -131,7 +139,8 @@ handle query_lc => sub { $result->{'result'} = defined($f_result) ? $f_result : sprintf("%.${precision}f", $result->{'result'}); $result->{'result'} =~ s/\.0{$precision}$//; - return "$factor $result->{'from_unit'} is $result->{'result'} $result->{'to_unit'}"; + my $output = "$factor $result->{'from_unit'} is $result->{'result'} $result->{'to_unit'}"; + return $output, html => wrap_html($output); }; diff --git a/share/goodie/conversions/style.css b/share/goodie/conversions/style.css new file mode 100644 index 00000000000..ad44ee8f416 --- /dev/null +++ b/share/goodie/conversions/style.css @@ -0,0 +1,3 @@ +.zci--answer .zci--conversions { + font-size: 1.5em; +} \ No newline at end of file diff --git a/t/Conversions.t b/t/Conversions.t index 6c4e0a7591a..f7b4187ee60 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -10,44 +10,44 @@ zci answer_type => 'conversions'; ddg_goodie_test( ['DDG::Goodie::Conversions'], - 'convert 5 oz to g' => test_zci('5 ounces is 141.747 grams',), - 'convert 1 ton to long ton' => test_zci('1 ton is 0.893 long tons',), - 'convert 158 ounce to lbm' => test_zci('158 ounces is 9.875 pounds',), - 'convert 0.111 stone to pound' => test_zci('0.111 stone is 1.554 pounds',), - '3 kilogramme to pound' => test_zci('3 kilograms is 6.614 pounds',), - '1.3 tonnes to ton' => test_zci('1.3 metric tons is 1.433 tons',), - '2 tons to kg' => test_zci('2 tons is 1.81e+03 kilograms',), - '1 ton to kilos' => test_zci('1 ton is 907.186 kilograms',), - '3.9 oz in g' => test_zci('3.9 ounces is 110.563 grams',), - '2 miles to km' => test_zci('2 miles is 3.219 kilometers',), - 'convert 5 feet to in' => test_zci('5 feet is 60 inches',), - '0.5 nautical mile to klick' => test_zci('0.5 nautical miles is 0.926 kilometers',), - '500 miles in metres' => test_zci('500 miles is 8.05e+05 meters',), - '25 cm in inches' => test_zci('25 centimeters is 9.843 inches',), - '1760 yards to miles' => test_zci('1760 yards is 1 mile',), - '3520yards to miles' => test_zci('3520 yards is 2 miles',), - 'convert 1stone to lbs' => test_zci('1 stone is 14 pounds',), - '30cm in in' => test_zci('30 centimeters is 11.811 inches',), - '36 months to years' => test_zci('36 months is 3 years',), - '43200 seconds in hours' => test_zci('43200 seconds is 12 hours',), - '4 hours to minutes' => test_zci('4 hours is 240 minutes',), - 'convert 5 kelvin to fahrenheit' => test_zci('5 kelvin is -450.670 degrees fahrenheit'), - '1 bar to pascal' => test_zci('1 bar is 100000 pascals',), - '1 kilopascal to psi' => test_zci('1 kilopascal is 0.145 pounds per square inch',), - '1 atm to kpa' => test_zci('1 atmosphere is 101.325 kilopascals',), - '5yrds to km' => test_zci('5 yards is 0.005 kilometers'), - '12" to cm' => test_zci('12 inches is 30.480 centimeters'), - 'convert 25 inches into feet' => test_zci('25 inches is 2.083 feet'), - '42 kilowatt hours in joules' => test_zci('42 kilowatt-hours is 1.51e+08 joules'), - '2500kcal in tons of tnt' => test_zci('2500 large calories is 0.003 tons of TNT'), - '90 ps in watts' => test_zci('90 metric horsepower is 6.62e+04 watts'), - '1 gigawatt in horsepower' => test_zci('1 gigawatt is 1.34e+06 horsepower'), - '180 degrees in radians' => test_zci('180 degrees is 3.142 radians'), - '270 degrees in quadrants' => test_zci('270 degrees is 3 quadrants'), - '180 degrees in grads' => test_zci('180 degrees is 200 gradians'), - '45 newtons to pounds force' => test_zci('45 newtons is 10.116 pounds force'), - '8 poundal to newtons' => test_zci('8 poundals is 1.106 newtons'), - 'convert 5 f to celsius' => test_zci('5 degrees fahrenheit is -15 degrees celsius'), + 'convert 5 oz to g' => test_zci('5 ounces is 141.747 grams', html => qr/.*/), + 'convert 1 ton to long ton' => test_zci('1 ton is 0.893 long tons', html => qr/.*/), + 'convert 158 ounce to lbm' => test_zci('158 ounces is 9.875 pounds', html => qr/.*/), + 'convert 0.111 stone to pound' => test_zci('0.111 stone is 1.554 pounds', html => qr/.*/), + '3 kilogramme to pound' => test_zci('3 kilograms is 6.614 pounds', html => qr/.*/), + '1.3 tonnes to ton' => test_zci('1.3 metric tons is 1.433 tons', html => qr/.*/), + '2 tons to kg' => test_zci('2 tons is 1.81e+03 kilograms', html => qr/.*/), + '1 ton to kilos' => test_zci('1 ton is 907.186 kilograms', html => qr/.*/), + '3.9 oz in g' => test_zci('3.9 ounces is 110.563 grams', html => qr/.*/), + '2 miles to km' => test_zci('2 miles is 3.219 kilometers', html => qr/.*/), + 'convert 5 feet to in' => test_zci('5 feet is 60 inches', html => qr/.*/), + '0.5 nautical mile to klick' => test_zci('0.5 nautical miles is 0.926 kilometers', html => qr/.*/), + '500 miles in metres' => test_zci('500 miles is 8.05e+05 meters', html => qr/.*/), + '25 cm in inches' => test_zci('25 centimeters is 9.843 inches', html => qr/.*/), + '1760 yards to miles' => test_zci('1760 yards is 1 mile', html => qr/.*/), + '3520yards to miles' => test_zci('3520 yards is 2 miles', html => qr/.*/), + 'convert 1stone to lbs' => test_zci('1 stone is 14 pounds', html => qr/.*/), + '30cm in in' => test_zci('30 centimeters is 11.811 inches', html => qr/.*/), + '36 months to years' => test_zci('36 months is 3 years', html => qr/.*/), + '43200 seconds in hours' => test_zci('43200 seconds is 12 hours', html => qr/.*/), + '4 hours to minutes' => test_zci('4 hours is 240 minutes', html => qr/.*/), + 'convert 5 kelvin to fahrenheit' => test_zci('5 kelvin is -450.670 degrees fahrenheit', html => qr/.*/), + '1 bar to pascal' => test_zci('1 bar is 100000 pascals', html => qr/.*/), + '1 kilopascal to psi' => test_zci('1 kilopascal is 0.145 pounds per square inch', html => qr/.*/), + '1 atm to kpa' => test_zci('1 atmosphere is 101.325 kilopascals', html => qr/.*/), + '5yrds to km' => test_zci('5 yards is 0.005 kilometers', html => qr/.*/), + '12" to cm' => test_zci('12 inches is 30.480 centimeters', html => qr/.*/), + 'convert 25 inches into feet' => test_zci('25 inches is 2.083 feet', html => qr/.*/), + '42 kilowatt hours in joules' => test_zci('42 kilowatt-hours is 1.51e+08 joules', html => qr/.*/), + '2500kcal in tons of tnt' => test_zci('2500 large calories is 0.003 tons of TNT', html => qr/.*/), + '90 ps in watts' => test_zci('90 metric horsepower is 6.62e+04 watts', html => qr/.*/), + '1 gigawatt in horsepower' => test_zci('1 gigawatt is 1.34e+06 horsepower', html => qr/.*/), + '180 degrees in radians' => test_zci('180 degrees is 3.142 radians', html => qr/.*/), + '270 degrees in quadrants' => test_zci('270 degrees is 3 quadrants', html => qr/.*/), + '180 degrees in grads' => test_zci('180 degrees is 200 gradians', html => qr/.*/), + '45 newtons to pounds force' => test_zci('45 newtons is 10.116 pounds force', html => qr/.*/), + '8 poundal to newtons' => test_zci('8 poundals is 1.106 newtons', html => qr/.*/), + 'convert 5 f to celsius' => test_zci('5 degrees fahrenheit is -15 degrees celsius', html => qr/.*/), '6^2 oz to grams' => undef, 'NaN oz to stones' => undef, '45x10 oz to stones' => undef, @@ -59,27 +59,27 @@ ddg_goodie_test( 'use a ton of stones' => undef, 'shoot onself in the foot' => undef, 'foot in both camps' => undef, - '10 mg to tons' => test_zci('10 milligrams is 1.1e-08 tons'), - '10000 minutes in microseconds' => test_zci('10000 minutes is 6e+11 microseconds'), - 'convert 5 bytes to bit' => test_zci('5 bytes is 40 bits'), - '5 GB to megabyte' => test_zci('5 gigabytes is 5000 megabytes'), - '0.013 mb in bits' => test_zci('0.013 megabytes is 104000 bits'), - '1 exabyte to pib' => test_zci('1 exabyte is 888.178 pebibytes'), - 'convert 1 yb to yib' => test_zci('1 yottabyte is 0.827 yobibytes'), - '16 years in months' => test_zci('16 years is 192 months'), - '1 year in months' => test_zci('1 year is 12 months'), - '360 degrees in revolutions' => test_zci('360 degrees is 1 revolution'), - 'convert km to cm' => test_zci('1 kilometer is 100000 centimeters'), - 'convert 10ms to seconds' => test_zci('10 milliseconds is 0.010 seconds'), - 'what is 1 inch in cm' => test_zci('1 inch is 2.540 centimeters'), - 'what are 10 yards in metres' => test_zci('10 yards is 9.144 meters'), - 'how long is 42 days in mins' => test_zci('42 days is 60480 minutes'), - 'how much is 40 kelvin in celsius' => test_zci('40 kelvin is -233.150 degrees celsius'), - '12 degrees Celsius to Fahrenheit' => test_zci('12 degrees celsius is 53.600 degrees fahrenheit'), - '1 degrees Fahrenheit to celsius' => test_zci('1 degrees fahrenheit is -17.222 degrees celsius'), - '0 c in k' => test_zci('0 degrees celsius is 273.150 kelvin'), - '234 f to c' => test_zci('234 degrees fahrenheit is 112.222 degrees celsius'), - '234 f to k' => test_zci('234 degrees fahrenheit is 385.372 kelvin') + '10 mg to tons' => test_zci('10 milligrams is 1.1e-08 tons', html => qr/.*/), + '10000 minutes in microseconds' => test_zci('10000 minutes is 6e+11 microseconds', html => qr/.*/), + 'convert 5 bytes to bit' => test_zci('5 bytes is 40 bits', html => qr/.*/), + '5 GB to megabyte' => test_zci('5 gigabytes is 5000 megabytes', html => qr/.*/), + '0.013 mb in bits' => test_zci('0.013 megabytes is 104000 bits', html => qr/.*/), + '1 exabyte to pib' => test_zci('1 exabyte is 888.178 pebibytes', html => qr/.*/), + 'convert 1 yb to yib' => test_zci('1 yottabyte is 0.827 yobibytes', html => qr/.*/), + '16 years in months' => test_zci('16 years is 192 months', html => qr/.*/), + '1 year in months' => test_zci('1 year is 12 months', html => qr/.*/), + '360 degrees in revolutions' => test_zci('360 degrees is 1 revolution', html => qr/.*/), + 'convert km to cm' => test_zci('1 kilometer is 100000 centimeters', html => qr/.*/), + 'convert 10ms to seconds' => test_zci('10 milliseconds is 0.010 seconds', html => qr/.*/), + 'what is 1 inch in cm' => test_zci('1 inch is 2.540 centimeters', html => qr/.*/), + 'what are 10 yards in metres' => test_zci('10 yards is 9.144 meters', html => qr/.*/), + 'how long is 42 days in mins' => test_zci('42 days is 60480 minutes', html => qr/.*/), + 'how much is 40 kelvin in celsius' => test_zci('40 kelvin is -233.150 degrees celsius', html => qr/.*/), + '12 degrees Celsius to Fahrenheit' => test_zci('12 degrees celsius is 53.600 degrees fahrenheit', html => qr/.*/), + '1 degrees Fahrenheit to celsius' => test_zci('1 degrees fahrenheit is -17.222 degrees celsius', html => qr/.*/), + '0 c in k' => test_zci('0 degrees celsius is 273.150 kelvin', html => qr/.*/), + '234 f to c' => test_zci('234 degrees fahrenheit is 112.222 degrees celsius', html => qr/.*/), + '234 f to k' => test_zci('234 degrees fahrenheit is 385.372 kelvin', html => qr/.*/) ); done_testing; From 73981cbff8f0a155742e6049e46dbac9c30a0663 Mon Sep 17 00:00:00 2001 From: jagtalon Date: Wed, 4 Jun 2014 20:05:38 +0000 Subject: [PATCH 2/5] Conversions: Add design suggestions From https://github.com/duckduckgo/zeroclickinfo-goodies/issues/460#issuecomment-45122090 --- lib/DDG/Goodie/Conversions.pm | 15 +++- share/goodie/conversions/style.css | 5 ++ t/Conversions.t | 118 ++++++++++++++--------------- 3 files changed, 75 insertions(+), 63 deletions(-) diff --git a/lib/DDG/Goodie/Conversions.pm b/lib/DDG/Goodie/Conversions.pm index 73b9c7ae67b..dc9cbb004a0 100755 --- a/lib/DDG/Goodie/Conversions.pm +++ b/lib/DDG/Goodie/Conversions.pm @@ -58,9 +58,16 @@ my %plural_exceptions = ( # This function adds some HTML and styling to our output # so that we can make it prettier. my $css = share("style.css")->slurp; +sub append_css { + my $html = shift; + return "$html"; +} + sub wrap_html { - my $output = shift; - return "
$output
"; + my ($factor, $result) = @_; + my $from = "$factor $result->{'from_unit'}"; + my $to = "$result->{'result'} $result->{'to_unit'}"; + return append_css("
$from = $to
"); } handle query_lc => sub { @@ -139,8 +146,8 @@ handle query_lc => sub { $result->{'result'} = defined($f_result) ? $f_result : sprintf("%.${precision}f", $result->{'result'}); $result->{'result'} =~ s/\.0{$precision}$//; - my $output = "$factor $result->{'from_unit'} is $result->{'result'} $result->{'to_unit'}"; - return $output, html => wrap_html($output); + my $output = "$factor $result->{'from_unit'} = $result->{'result'} $result->{'to_unit'}"; + return $output, html => wrap_html($factor, $result); }; diff --git a/share/goodie/conversions/style.css b/share/goodie/conversions/style.css index ad44ee8f416..217b47abb6f 100644 --- a/share/goodie/conversions/style.css +++ b/share/goodie/conversions/style.css @@ -1,3 +1,8 @@ .zci--answer .zci--conversions { font-size: 1.5em; + font-weight: 300; +} + +.zci--answer .zci--conversions .unit { + color: #808080; } \ No newline at end of file diff --git a/t/Conversions.t b/t/Conversions.t index f7b4187ee60..f963767ae4e 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -10,44 +10,44 @@ zci answer_type => 'conversions'; ddg_goodie_test( ['DDG::Goodie::Conversions'], - 'convert 5 oz to g' => test_zci('5 ounces is 141.747 grams', html => qr/.*/), - 'convert 1 ton to long ton' => test_zci('1 ton is 0.893 long tons', html => qr/.*/), - 'convert 158 ounce to lbm' => test_zci('158 ounces is 9.875 pounds', html => qr/.*/), - 'convert 0.111 stone to pound' => test_zci('0.111 stone is 1.554 pounds', html => qr/.*/), - '3 kilogramme to pound' => test_zci('3 kilograms is 6.614 pounds', html => qr/.*/), - '1.3 tonnes to ton' => test_zci('1.3 metric tons is 1.433 tons', html => qr/.*/), - '2 tons to kg' => test_zci('2 tons is 1.81e+03 kilograms', html => qr/.*/), - '1 ton to kilos' => test_zci('1 ton is 907.186 kilograms', html => qr/.*/), - '3.9 oz in g' => test_zci('3.9 ounces is 110.563 grams', html => qr/.*/), - '2 miles to km' => test_zci('2 miles is 3.219 kilometers', html => qr/.*/), - 'convert 5 feet to in' => test_zci('5 feet is 60 inches', html => qr/.*/), - '0.5 nautical mile to klick' => test_zci('0.5 nautical miles is 0.926 kilometers', html => qr/.*/), - '500 miles in metres' => test_zci('500 miles is 8.05e+05 meters', html => qr/.*/), - '25 cm in inches' => test_zci('25 centimeters is 9.843 inches', html => qr/.*/), - '1760 yards to miles' => test_zci('1760 yards is 1 mile', html => qr/.*/), - '3520yards to miles' => test_zci('3520 yards is 2 miles', html => qr/.*/), - 'convert 1stone to lbs' => test_zci('1 stone is 14 pounds', html => qr/.*/), - '30cm in in' => test_zci('30 centimeters is 11.811 inches', html => qr/.*/), - '36 months to years' => test_zci('36 months is 3 years', html => qr/.*/), - '43200 seconds in hours' => test_zci('43200 seconds is 12 hours', html => qr/.*/), - '4 hours to minutes' => test_zci('4 hours is 240 minutes', html => qr/.*/), - 'convert 5 kelvin to fahrenheit' => test_zci('5 kelvin is -450.670 degrees fahrenheit', html => qr/.*/), - '1 bar to pascal' => test_zci('1 bar is 100000 pascals', html => qr/.*/), - '1 kilopascal to psi' => test_zci('1 kilopascal is 0.145 pounds per square inch', html => qr/.*/), - '1 atm to kpa' => test_zci('1 atmosphere is 101.325 kilopascals', html => qr/.*/), - '5yrds to km' => test_zci('5 yards is 0.005 kilometers', html => qr/.*/), - '12" to cm' => test_zci('12 inches is 30.480 centimeters', html => qr/.*/), - 'convert 25 inches into feet' => test_zci('25 inches is 2.083 feet', html => qr/.*/), - '42 kilowatt hours in joules' => test_zci('42 kilowatt-hours is 1.51e+08 joules', html => qr/.*/), - '2500kcal in tons of tnt' => test_zci('2500 large calories is 0.003 tons of TNT', html => qr/.*/), - '90 ps in watts' => test_zci('90 metric horsepower is 6.62e+04 watts', html => qr/.*/), - '1 gigawatt in horsepower' => test_zci('1 gigawatt is 1.34e+06 horsepower', html => qr/.*/), - '180 degrees in radians' => test_zci('180 degrees is 3.142 radians', html => qr/.*/), - '270 degrees in quadrants' => test_zci('270 degrees is 3 quadrants', html => qr/.*/), - '180 degrees in grads' => test_zci('180 degrees is 200 gradians', html => qr/.*/), - '45 newtons to pounds force' => test_zci('45 newtons is 10.116 pounds force', html => qr/.*/), - '8 poundal to newtons' => test_zci('8 poundals is 1.106 newtons', html => qr/.*/), - 'convert 5 f to celsius' => test_zci('5 degrees fahrenheit is -15 degrees celsius', html => qr/.*/), + 'convert 5 oz to g' => test_zci('5 ounces = 141.747 grams', html => qr/.*/), + 'convert 1 ton to long ton' => test_zci('1 ton = 0.893 long tons', html => qr/.*/), + 'convert 158 ounce to lbm' => test_zci('158 ounces = 9.875 pounds', html => qr/.*/), + 'convert 0.111 stone to pound' => test_zci('0.111 stone = 1.554 pounds', html => qr/.*/), + '3 kilogramme to pound' => test_zci('3 kilograms = 6.614 pounds', html => qr/.*/), + '1.3 tonnes to ton' => test_zci('1.3 metric tons = 1.433 tons', html => qr/.*/), + '2 tons to kg' => test_zci('2 tons = 1.81e+03 kilograms', html => qr/.*/), + '1 ton to kilos' => test_zci('1 ton = 907.186 kilograms', html => qr/.*/), + '3.9 oz in g' => test_zci('3.9 ounces = 110.563 grams', html => qr/.*/), + '2 miles to km' => test_zci('2 miles = 3.219 kilometers', html => qr/.*/), + 'convert 5 feet to in' => test_zci('5 feet = 60 inches', html => qr/.*/), + '0.5 nautical mile to klick' => test_zci('0.5 nautical miles = 0.926 kilometers', html => qr/.*/), + '500 miles in metres' => test_zci('500 miles = 8.05e+05 meters', html => qr/.*/), + '25 cm in inches' => test_zci('25 centimeters = 9.843 inches', html => qr/.*/), + '1760 yards to miles' => test_zci('1760 yards = 1 mile', html => qr/.*/), + '3520yards to miles' => test_zci('3520 yards = 2 miles', html => qr/.*/), + 'convert 1stone to lbs' => test_zci('1 stone = 14 pounds', html => qr/.*/), + '30cm in in' => test_zci('30 centimeters = 11.811 inches', html => qr/.*/), + '36 months to years' => test_zci('36 months = 3 years', html => qr/.*/), + '43200 seconds in hours' => test_zci('43200 seconds = 12 hours', html => qr/.*/), + '4 hours to minutes' => test_zci('4 hours = 240 minutes', html => qr/.*/), + 'convert 5 kelvin to fahrenheit' => test_zci('5 kelvin = -450.670 degrees fahrenheit', html => qr/.*/), + '1 bar to pascal' => test_zci('1 bar = 100000 pascals', html => qr/.*/), + '1 kilopascal to psi' => test_zci('1 kilopascal = 0.145 pounds per square inch', html => qr/.*/), + '1 atm to kpa' => test_zci('1 atmosphere = 101.325 kilopascals', html => qr/.*/), + '5yrds to km' => test_zci('5 yards = 0.005 kilometers', html => qr/.*/), + '12" to cm' => test_zci('12 inches = 30.480 centimeters', html => qr/.*/), + 'convert 25 inches into feet' => test_zci('25 inches = 2.083 feet', html => qr/.*/), + '42 kilowatt hours in joules' => test_zci('42 kilowatt-hours = 1.51e+08 joules', html => qr/.*/), + '2500kcal in tons of tnt' => test_zci('2500 large calories = 0.003 tons of TNT', html => qr/.*/), + '90 ps in watts' => test_zci('90 metric horsepower = 6.62e+04 watts', html => qr/.*/), + '1 gigawatt in horsepower' => test_zci('1 gigawatt = 1.34e+06 horsepower', html => qr/.*/), + '180 degrees in radians' => test_zci('180 degrees = 3.142 radians', html => qr/.*/), + '270 degrees in quadrants' => test_zci('270 degrees = 3 quadrants', html => qr/.*/), + '180 degrees in grads' => test_zci('180 degrees = 200 gradians', html => qr/.*/), + '45 newtons to pounds force' => test_zci('45 newtons = 10.116 pounds force', html => qr/.*/), + '8 poundal to newtons' => test_zci('8 poundals = 1.106 newtons', html => qr/.*/), + 'convert 5 f to celsius' => test_zci('5 degrees fahrenheit = -15 degrees celsius', html => qr/.*/), '6^2 oz to grams' => undef, 'NaN oz to stones' => undef, '45x10 oz to stones' => undef, @@ -59,27 +59,27 @@ ddg_goodie_test( 'use a ton of stones' => undef, 'shoot onself in the foot' => undef, 'foot in both camps' => undef, - '10 mg to tons' => test_zci('10 milligrams is 1.1e-08 tons', html => qr/.*/), - '10000 minutes in microseconds' => test_zci('10000 minutes is 6e+11 microseconds', html => qr/.*/), - 'convert 5 bytes to bit' => test_zci('5 bytes is 40 bits', html => qr/.*/), - '5 GB to megabyte' => test_zci('5 gigabytes is 5000 megabytes', html => qr/.*/), - '0.013 mb in bits' => test_zci('0.013 megabytes is 104000 bits', html => qr/.*/), - '1 exabyte to pib' => test_zci('1 exabyte is 888.178 pebibytes', html => qr/.*/), - 'convert 1 yb to yib' => test_zci('1 yottabyte is 0.827 yobibytes', html => qr/.*/), - '16 years in months' => test_zci('16 years is 192 months', html => qr/.*/), - '1 year in months' => test_zci('1 year is 12 months', html => qr/.*/), - '360 degrees in revolutions' => test_zci('360 degrees is 1 revolution', html => qr/.*/), - 'convert km to cm' => test_zci('1 kilometer is 100000 centimeters', html => qr/.*/), - 'convert 10ms to seconds' => test_zci('10 milliseconds is 0.010 seconds', html => qr/.*/), - 'what is 1 inch in cm' => test_zci('1 inch is 2.540 centimeters', html => qr/.*/), - 'what are 10 yards in metres' => test_zci('10 yards is 9.144 meters', html => qr/.*/), - 'how long is 42 days in mins' => test_zci('42 days is 60480 minutes', html => qr/.*/), - 'how much is 40 kelvin in celsius' => test_zci('40 kelvin is -233.150 degrees celsius', html => qr/.*/), - '12 degrees Celsius to Fahrenheit' => test_zci('12 degrees celsius is 53.600 degrees fahrenheit', html => qr/.*/), - '1 degrees Fahrenheit to celsius' => test_zci('1 degrees fahrenheit is -17.222 degrees celsius', html => qr/.*/), - '0 c in k' => test_zci('0 degrees celsius is 273.150 kelvin', html => qr/.*/), - '234 f to c' => test_zci('234 degrees fahrenheit is 112.222 degrees celsius', html => qr/.*/), - '234 f to k' => test_zci('234 degrees fahrenheit is 385.372 kelvin', html => qr/.*/) + '10 mg to tons' => test_zci('10 milligrams = 1.1e-08 tons', html => qr/.*/), + '10000 minutes in microseconds' => test_zci('10000 minutes = 6e+11 microseconds', html => qr/.*/), + 'convert 5 bytes to bit' => test_zci('5 bytes = 40 bits', html => qr/.*/), + '5 GB to megabyte' => test_zci('5 gigabytes = 5000 megabytes', html => qr/.*/), + '0.013 mb in bits' => test_zci('0.013 megabytes = 104000 bits', html => qr/.*/), + '1 exabyte to pib' => test_zci('1 exabyte = 888.178 pebibytes', html => qr/.*/), + 'convert 1 yb to yib' => test_zci('1 yottabyte = 0.827 yobibytes', html => qr/.*/), + '16 years in months' => test_zci('16 years = 192 months', html => qr/.*/), + '1 year in months' => test_zci('1 year = 12 months', html => qr/.*/), + '360 degrees in revolutions' => test_zci('360 degrees = 1 revolution', html => qr/.*/), + 'convert km to cm' => test_zci('1 kilometer = 100000 centimeters', html => qr/.*/), + 'convert 10ms to seconds' => test_zci('10 milliseconds = 0.010 seconds', html => qr/.*/), + 'what is 1 inch in cm' => test_zci('1 inch = 2.540 centimeters', html => qr/.*/), + 'what are 10 yards in metres' => test_zci('10 yards = 9.144 meters', html => qr/.*/), + 'how long is 42 days in mins' => test_zci('42 days = 60480 minutes', html => qr/.*/), + 'how much is 40 kelvin in celsius' => test_zci('40 kelvin = -233.150 degrees celsius', html => qr/.*/), + '12 degrees Celsius to Fahrenheit' => test_zci('12 degrees celsius = 53.600 degrees fahrenheit', html => qr/.*/), + '1 degrees Fahrenheit to celsius' => test_zci('1 degrees fahrenheit = -17.222 degrees celsius', html => qr/.*/), + '0 c in k' => test_zci('0 degrees celsius = 273.150 kelvin', html => qr/.*/), + '234 f to c' => test_zci('234 degrees fahrenheit = 112.222 degrees celsius', html => qr/.*/), + '234 f to k' => test_zci('234 degrees fahrenheit = 385.372 kelvin', html => qr/.*/) ); done_testing; From d3c5a5bb4ad3f1eec11b6ba9f1df07ac205d7bd2 Mon Sep 17 00:00:00 2001 From: jagtalon Date: Wed, 4 Jun 2014 21:16:36 +0000 Subject: [PATCH 3/5] Conversions: Encode HTML output. --- lib/DDG/Goodie/Conversions.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/DDG/Goodie/Conversions.pm b/lib/DDG/Goodie/Conversions.pm index 879f889dfc4..9f6323a49ef 100755 --- a/lib/DDG/Goodie/Conversions.pm +++ b/lib/DDG/Goodie/Conversions.pm @@ -2,6 +2,8 @@ package DDG::Goodie::Conversions; # ABSTRACT: convert between various units of measurement use DDG::Goodie; + +use HTML::Entities; use Math::Round qw/nearest/; use Scalar::Util qw/looks_like_number/; use bignum; @@ -65,8 +67,8 @@ sub append_css { sub wrap_html { my ($factor, $result) = @_; - my $from = "$factor $result->{'from_unit'}"; - my $to = "$result->{'result'} $result->{'to_unit'}"; + my $from = encode_entities($factor) . " " . encode_entities($result->{'from_unit'}) . ""; + my $to = encode_entities($result->{'result'}) . " " . encode_entities($result->{'to_unit'}) . ""; return append_css("
$from = $to
"); } From 206977806d057f491256e6ca87b745d3ae4ff768 Mon Sep 17 00:00:00 2001 From: jagtalon Date: Thu, 5 Jun 2014 13:21:36 +0000 Subject: [PATCH 4/5] Conversions: Add some padding around the IA. --- share/goodie/conversions/style.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/share/goodie/conversions/style.css b/share/goodie/conversions/style.css index 217b47abb6f..105b630ac7d 100644 --- a/share/goodie/conversions/style.css +++ b/share/goodie/conversions/style.css @@ -1,6 +1,8 @@ .zci--answer .zci--conversions { font-size: 1.5em; font-weight: 300; + padding-top: .25em; + padding-bottom: .25em; } .zci--answer .zci--conversions .unit { From 9313be2f774370ff865436159e5b8702dc2e42ea Mon Sep 17 00:00:00 2001 From: jagtalon Date: Thu, 5 Jun 2014 20:16:04 +0000 Subject: [PATCH 5/5] Conversions: Numbers should have color of #393939. --- share/goodie/conversions/style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/share/goodie/conversions/style.css b/share/goodie/conversions/style.css index 105b630ac7d..c5b527e4569 100644 --- a/share/goodie/conversions/style.css +++ b/share/goodie/conversions/style.css @@ -3,6 +3,7 @@ font-weight: 300; padding-top: .25em; padding-bottom: .25em; + color: #393939; } .zci--answer .zci--conversions .unit {