From: Giuseppe Bilotta Date: Sun, 21 Jun 2009 17:57:05 GMT Subject: [PATCHv3 2/2] gitweb: refactor author+gravatar insertion Message-ID: <1245607025-19296-3-git-send-email-giuseppe.bilotta@gmail.com> In-Reply-To: <1245607025-19296-2-git-send-email-giuseppe.bilotta@gmail.com> --- gitweb/gitweb.css | 5 +++- gitweb/gitweb.perl | 69 ++++++++++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css index eaf74c3..ddf982b 100644 --- a/gitweb/gitweb.css +++ b/gitweb/gitweb.css @@ -136,11 +136,14 @@ div.list_head { font-style: italic; } +.author_date, .author { + font-style: italic; +} + div.author_date { padding: 8px; border: solid #d9d8d1; border-width: 0px 0px 1px 0px; - font-style: italic; } a.list { diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index f5654d7..cb4ecc3 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1496,6 +1496,31 @@ sub format_subject_html { } } +# insert a gravatar for the given $email at the given $size if the feature +# is enabled +sub git_get_gravatar { + if ($git_gravatar_enabled) { + my ($email, %params) = @_; + my $pre_white = ($params{'space_before'} ? " " : ""); + my $post_white = ($params{'space_after'} ? " " : ""); + my $size = $avatar_size{$params{'size'}} || $avatar_size{'default'}; + return $pre_white . "" . $post_white; + } else { + return ""; + } +} + +# format, perhaps shortened and preceded by the gravatar, the author name +sub format_author_html { + my $tag = shift; + my $co = shift; + my $author = chop_and_escape_str($co->{'author_name'}, @_); + return "<$tag class=\"author\">" . + git_get_gravatar($co->{'author_email'}, 'space_after' => 1) . + $author . "\n"; +} + # format git diff header line, i.e. "diff --(git|combined|cc) ..." sub format_git_diff_header_line { my $line = shift; @@ -3241,28 +3266,14 @@ sub git_print_header_div { "\n\n"; } -# insert a gravatar for the given $email at the given $size if the feature -# is enabled -sub git_get_gravatar { - if ($git_gravatar_enabled) { - my ($email, %params) = @_; - my $pre_white = ($params{'space_before'} ? " " : ""); - my $post_white = ($params{'space_after'} ? " " : ""); - my $size = $avatar_size{$params{'size'}} || $avatar_size{'default'}; - return $pre_white . "" . $post_white; - } else { - return ""; - } -} - +# Outputs the author name and date in long form, followed by the gravatar sub git_print_authorship { my $co = shift; + my $tag = shift || 'div'; my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); - print "
" . + print "<$tag class=\"author_date\">" . esc_html($co->{'author_name'}) . - git_get_gravatar($co->{'author_email'}, 'space_before' => 1) . " [$ad{'rfc2822'}"; if ($ad{'hour_local'} < 6) { printf(" (%02d:%02d %s)", @@ -3271,7 +3282,9 @@ sub git_print_authorship { printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); } - print "]
\n"; + print "]" . + git_get_gravatar($co->{'author_email'}, 'space_before' => 1) . + "\n"; } sub git_print_page_path { @@ -4185,11 +4198,9 @@ sub git_shortlog_body { print "\n"; } $alternate ^= 1; - my $author = chop_and_escape_str($co{'author_name'}, 10); # git_summary() used print "$co{'age_string'}\n" . print "$co{'age_string_date'}\n" . - "" . git_get_gravatar($co{'author_email'}, 'space_after' => 1) . "" . $author . "\n" . - ""; + format_author_html('td', \%co, 10) . ""; print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref); print "\n" . @@ -4236,11 +4247,9 @@ sub git_history_body { print "\n"; } $alternate ^= 1; - # shortlog uses chop_str($co{'author_name'}, 10) - my $author = chop_and_escape_str($co{'author_name'}, 15, 3); print "$co{'age_string_date'}\n" . - "" . git_get_gravatar($co{'author_email'}, 'space_after' => 1) . "" . $author . "\n" . - ""; + # shortlog uses format_author_html('td', \%co, 10) + format_author_html('td', \%co, 15, 3) . ""; # originally git_history used chop_str($co{'title'}, 50) print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref); @@ -4393,9 +4402,8 @@ sub git_search_grep_body { print "\n"; } $alternate ^= 1; - my $author = chop_and_escape_str($co{'author_name'}, 15, 5); print "$co{'age_string_date'}\n" . - "" . git_get_gravatar($co{'author_email'}, 'space_after' => 1) . "" . $author . "\n" . + format_author_html('td', \%co, 15, 5) . "" . $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"}, @@ -5137,10 +5145,9 @@ sub git_log { " | " . $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") . "
\n" . - "\n" . - "" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}] " . - git_get_gravatar($co{'author_email'}) . - "
\n\n"; + "\n"; + git_print_authorship(\%co); + print "
\n\n"; print "
\n"; git_print_log($co{'comment'}, -final_empty_line=> 1); -- 1.6.3.rc1.192.gdbfcb