@matheusbsbs / matheus-bagliano / commits / ce58ec9158
Fork 0

gitweb: Refactor abbreviation-with-title-attribute code.

Signed-off-by: David Symonds <dsymonds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Symonds committed Oct 23, 2007 at 11:31 UTC ce58ec9158fe398dc7142e34cf575d336f408370
1 file changed +21 -24
gitweb/gitweb.perl
+21 -24
@@ -846,6 +846,23 @@ sub chop_str {
846 return "$body$tail";
847 }
848
849 +# takes the same arguments as chop_str, but also wraps a <span> around the
850 +# result with a title attribute if it does get chopped. Additionally, the
851 +# string is HTML-escaped.
852 +sub chop_and_escape_str {
853 + my $str = shift;
854 + my $len = shift;
855 + my $add_len = shift || 10;
856 +
857 + my $chopped = chop_str($str, $len, $add_len);
858 + if ($chopped eq $str) {
859 + return esc_html($chopped);
860 + } else {
861 + return qq{<span title="} . esc_html($str) . qq{">} .
862 + esc_html($chopped) . qq{</span>};
863 + }
864 +}
865 +
866 ## ----------------------------------------------------------------------
867 ## functions returning short strings
868
@@ -3437,12 +3454,7 @@ sub git_shortlog_body {
3454 print "<tr class=\"light\">\n";
3455 }
3456 $alternate ^= 1;
3440 - my $author = chop_str($co{'author_name'}, 10);
3441 - if ($author ne $co{'author_name'}) {
3442 - $author = "<span title=\"" . esc_html($co{'author_name'}) . "\">" . esc_html($author) . "</span>";
3443 - } else {
3444 - $author = esc_html($author);
3445 - }
3457 + my $author = chop_and_escape_str($co{'author_name'}, 10);
3458 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3459 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3460 "<td><i>" . $author . "</i></td>\n" .
@@ -3494,12 +3506,7 @@ sub git_history_body {
3506 }
3507 $alternate ^= 1;
3508 # shortlog uses chop_str($co{'author_name'}, 10)
3497 - my $author = chop_str($co{'author_name'}, 15, 3);
3498 - if ($author ne $co{'author_name'}) {
3499 - "<span title=\"" . esc_html($co{'author_name'}) . "\">" . esc_html($author) . "</span>";
3500 - } else {
3501 - $author = esc_html($author);
3502 - }
3509 + my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
3510 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3511 "<td><i>" . $author . "</i></td>\n" .
3512 "<td>";
@@ -3655,12 +3662,7 @@ sub git_search_grep_body {
3662 print "<tr class=\"light\">\n";
3663 }
3664 $alternate ^= 1;
3658 - my $author = chop_str($co{'author_name'}, 15, 5);
3659 - if ($author ne $co{'author_name'}) {
3660 - $author = "<span title=\"" . esc_html($co{'author_name'}) . "\">" . esc_html($author) . "</span>";
3661 - } else {
3662 - $author = esc_html($author);
3663 - }
3665 + my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
3666 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3667 "<td><i>" . $author . "</i></td>\n" .
3668 "<td>" .
@@ -5175,12 +5177,7 @@ sub git_search {
5177 print "<tr class=\"light\">\n";
5178 }
5179 $alternate ^= 1;
5178 - my $author = chop_str($co{'author_name'}, 15, 5);
5179 - if ($author ne $co{'author_name'}) {
5180 - $author = "<span title=\"" . esc_html($co{'author_name'}) . "\">" . esc_html($author) . "</span>";
5181 - } else {
5182 - $author = esc_html($author);
5183 - }
5180 + my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
5181 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5182 "<td><i>" . $author . "</i></td>\n" .
5183 "<td>" .