add zci__mor-at class for links

master
nishanths 2014-06-17 02:59:20 +05:30
parent 617d27c394
commit d4fedd24d4
4 changed files with 25 additions and 24 deletions

View File

@ -230,12 +230,12 @@ sub make_html {
# Returns a html formatted string containing the HTML character name, entity, and a link
my $html = "";
if (scalar(@{$_[0]}) == 1) { # single line answer
$html = "<div>$_[0][0][0] (&$_[0][0][1];): &<span>$_[0][0][1]</span>;&nbsp;&nbsp;<a href=\"$url\">More at W3</a></div>" ; # link in the same line for single line answers
$html = "<div>$_[0][0][0] (&$_[0][0][1];): &<span>$_[0][0][1]</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"$url\">More at W3</a></div>" ; # link in the same line for single line answers
} else {
foreach my $i (0 .. scalar(@{$_[0]}) - 1) { # multiple line answer
$html = "$html" . "<div>$_[0][$i][0] (&$_[0][$i][1];): &<span>$_[0][$i][1]</span>;</div>";
}
$html = "$html" . "<div><a href=\"$url\">More at W3</a></div>";
$html = "$html" . "<div><a class=\"zci__more-at\" href=\"$url\">More at W3</a></div>";
}
return $html;
};
@ -255,6 +255,7 @@ handle remainder => sub {
$hashes_query =~ s/\-/ /; # change '-' to ' '
$hashes_query =~ s/"//; # remove double quote
$hashes_query =~ s/'//; # remove single quote
# If a string still exists after the stripping, lookup the accented_chars hash if it's an accented character query and if it's not an accented char look up the codes hash
if ($hashes_query) {
if ($hashes_query =~ /^(a|A|e|E|i|I|o|O|u|U)\s*(grave|acute)$/) { # search query is for an accented character
@ -285,7 +286,7 @@ handle remainder => sub {
$entity =~ s/^&//;
$entity =~ s/;$//;
my $text = "Encoded HTML Entity: &$entity;";
my $html = "<div>Encoded HTML Entity (&$entity;): &<span>$entity</span>;&nbsp;&nbsp;<a href=\"$url\">More at W3</a></div>";
my $html = "<div>Encoded HTML Entity: &<span>$entity</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"$url\">More at W3</a></div>";
return $text, html => $html;
}

View File

@ -22,6 +22,6 @@ triggers startend => 'url encode', 'encode url', 'urlencode', 'encodeurl', 'urle
my $url = "https://en.wikipedia.org/wiki/Url_encoding";
handle remainder => sub {
my $holder = uri_encode($_);
return "Encoded URL: $holder", html => "<div>Encoded URL: $holder</div><div>More at <a href=\"$url\">Wikipedia</a></div>";
return "Encoded URL: $holder", html => "<div>Encoded URL: $holder</div><div><a class=\"zci__more-at\" href=\"$url\">More at Wikipedia</a></div>";
};
1;

View File

@ -12,57 +12,57 @@ ddg_goodie_test(
# Test 1
'html code em dash' => test_zci(
"Em dash: &mdash;",
html => "<div>Em dash (&mdash;): &<span>mdash</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Em dash (&mdash;): &<span>mdash</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 2 - querying accented chars
'html entity A-acute' => test_zci(
"A-acute: &Aacute;",
html => "<div>A-acute (&Aacute;): &<span>Aacute</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>A-acute (&Aacute;): &<span>Aacute</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 3
'html encode &' => test_zci(
"Encoded HTML Entity: &amp;",
html => "<div>Encoded HTML Entity (&amp;): &<span>amp</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Encoded HTML Entity: &<span>amp</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 4 - hyphens in between don't matter
'html code em-dash' => test_zci(
"Em dash: &mdash;",
html => "<div>Em dash (&mdash;): &<span>mdash</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Em dash (&mdash;): &<span>mdash</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 5 - variety in querying accented chars
'html entity for E grave' => test_zci(
"E-grave: &Egrave;",
html => "<div>E-grave (&Egrave;): &<span>Egrave</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>E-grave (&Egrave;): &<span>Egrave</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 6
'html encode $' => test_zci(
"Encoded HTML Entity: &#36;",
html => "<div>Encoded HTML Entity (&#36;): &<span>#36</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Encoded HTML Entity: &<span>#36</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 7 - two entities returned
'html encode pound symbol' => test_zci(
"British Pound Sterling: &pound;\nNumber sign: &#35;",
html => "<div>British Pound Sterling (&pound;): &<span>pound</span>;</div><div>Number sign (&#35;): &<span>#35</span>;</div><div><a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>British Pound Sterling (&pound;): &<span>pound</span>;</div><div>Number sign (&#35;): &<span>#35</span>;</div><div><a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 8 - extra words like 'for' and 'sign' can be typed in, and are taken care of in the code / new trigger
'htmlencode pilcrow sign' => test_zci(
"Pilcrow: &#182;",
html => "<div>Pilcrow (&#182;): &<span>#182</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Pilcrow (&#182;): &<span>#182</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 9 - new trigger
'html escape greater than symbol' => test_zci(
"Greater than: &gt;",
html => "<div>Greater than (&gt;): &<span>gt</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Greater than (&gt;): &<span>gt</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 10 - handling too much space / new trigger
'space encodehtml' => test_zci(
"Non-breaking space: &nbsp;",
html => "<div>Non-breaking space (&nbsp;): &<span>nbsp</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Non-breaking space (&nbsp;): &<span>nbsp</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
# Test 11 - standardized output / new trigger
'aPostTophe escapehtml' => test_zci(
'ApoSTrophe escapehtml' => test_zci(
"Apostrophe: &#39;",
html => "<div>Apostrophe (&#39;): &<span>#39</span>;&nbsp;&nbsp;<a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
html => "<div>Apostrophe (&#39;): &<span>#39</span>;&nbsp;&nbsp;<a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
),
);

View File

@ -11,28 +11,28 @@ ddg_goodie_test(
[qw(DDG::Goodie::URLEncode)],
# Test 1 - simple
'url encode http://nospaces.duckduckgo.com/hook em horns' => test_zci("Encoded URL: http://nospaces.duckduckgo.com/hook%20em%20horns",
html => "<div>Encoded URL: http://nospaces.duckduckgo.com/hook%20em%20horns</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: http://nospaces.duckduckgo.com/hook%20em%20horns</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
# Test 2 - with spaces
'encode url xkcd.com/a webcomic of%romance+math+sarcasm+language' => test_zci("Encoded URL: xkcd.com/a%20webcomic%20of%25romance+math+sarcasm+language",
html => "<div>Encoded URL: xkcd.com/a%20webcomic%20of%25romance+math+sarcasm+language</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: xkcd.com/a%20webcomic%20of%25romance+math+sarcasm+language</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
# Test 3 - spaces between keyword and query data
'http://arstechnica.com/space after end url encode' => test_zci("Encoded URL: http://arstechnica.com/space%20after%20end%20",
html => "<div>Encoded URL: http://arstechnica.com/space%20after%20end%20</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: http://arstechnica.com/space%20after%20end%20</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
# Test 4 - nothing to encode
'apple.com/mac encode URL' => test_zci("Encoded URL: apple.com/mac",
html => "<div>Encoded URL: apple.com/mac</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: apple.com/mac</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
# Test 5 - new triggers
'https://example.com/zero#clickinfo^34* encodeurl' => test_zci("Encoded URL: https://example.com/zero#clickinfo%5E34*",
html => "<div>Encoded URL: https://example.com/zero#clickinfo%5E34*</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: https://example.com/zero#clickinfo%5E34*</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
# Test 6 - more characters to convert / new trigger
'urlencode https://example.org/the answer to"life%the-universe.and<>everything\|}{' => test_zci("Encoded URL: https://example.org/the%20answer%20to%22life%25the-universe.and%3C%3Eeverything%5C%7C%7D%7B",
html => "<div>Encoded URL: https://example.org/the%20answer%20to%22life%25the-universe.and%3C%3Eeverything%5C%7C%7D%7B</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: https://example.org/the%20answer%20to%22life%25the-universe.and%3C%3Eeverything%5C%7C%7D%7B</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
# Test 7 - even more characters / new trigger
'urlescape https://example.org/the-alchemist_`purified gold...in&the/middle!OfTheSandstorm' => test_zci("Encoded URL: https://example.org/the-alchemist_%60purified%20gold...in&the/middle!OfTheSandstorm",
html => "<div>Encoded URL: https://example.org/the-alchemist_%60purified%20gold...in&the/middle!OfTheSandstorm</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: https://example.org/the-alchemist_%60purified%20gold...in&the/middle!OfTheSandstorm</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
# Test 8 - brackets and parantheses / new trigger
'www.herokuapp.com/(){}[] urlencode' => test_zci("Encoded URL: www.herokuapp.com/()%7B%7D[]",
html => "<div>Encoded URL: www.herokuapp.com/()%7B%7D[]</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
html => "<div>Encoded URL: www.herokuapp.com/()%7B%7D[]</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
);
done_testing;