From 7807dd1d4d6ae4757e9fc7ce36c27bc5ca970432 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Wed, 27 Feb 2013 13:42:45 -0500 Subject: [PATCH 1/8] Add a list of contributors taken from the x_contributors META attribute. I strip the emails from the contributors, because we don't want an email straight on a webpage. I also see if the name is actually a CPAN ID, and if so go a little fancier. To see an example, look at Test-Strict. --- lib/MetaCPAN/Web/Controller/Release.pm | 15 +++++++ root/inc/author-pic.html | 2 - root/inc/contributors.html | 55 ++++++++++++++++++++++++++ root/release.html | 5 +++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 root/inc/contributors.html diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index 0ee2e85e2d..c1d6cb2035 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -82,6 +82,21 @@ sub view : Private { $c->res->last_modified( $out->{date} ); + if ( my $contributors = $out->{metadata}{x_contributors} ) { + for my $contributor ( @$contributors ) { + # don't put email addresses on a web page + next if $contributor =~ s/<.+?>//g; + + # looks like a cpan account? + next unless $contributor =~ /^[A-Z]+$/; + + $contributor = { + id => $contributor, + url => $c->uri_for_action( '/author/index', [ $contributor ] ), + }; + } + } + # TODO: make took more automatic (to include all) $c->stash( { template => 'release.html', diff --git a/root/inc/author-pic.html b/root/inc/author-pic.html index 1c3df537d1..e88032a079 100644 --- a/root/inc/author-pic.html +++ b/root/inc/author-pic.html @@ -1,4 +1,3 @@ -
<% IF author.gravatar_url %><% author.gravatar_url = author.gravatar_url.replace("^http://(www\.)?gravatar.com/", "https://secure.gravatar.com/") %>
<% END %>
<% author.name %> @@ -12,4 +11,3 @@ src="http://api.coderwall.com/<% p.id %>/endorsecount.png" />
<% END %> <% END %> - diff --git a/root/inc/contributors.html b/root/inc/contributors.html new file mode 100644 index 0000000000..7807c0a1cf --- /dev/null +++ b/root/inc/contributors.html @@ -0,0 +1,55 @@ +<% IF contributors %> + +
+ and <% contributors.size %> contributors +
+ show them +
+ +
+ + + +<% END %> diff --git a/root/release.html b/root/release.html index ce1645e9c7..f70581026b 100644 --- a/root/release.html +++ b/root/release.html @@ -57,7 +57,12 @@ +
<% INCLUDE inc/author-pic.html author = author %> +<% INCLUDE inc/contributors.html + contributors = release.metadata.x_contributors %> +
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>
From 67076418ba8a411a75ee9fc0941acebad01c861d Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Wed, 27 Feb 2013 14:20:09 -0500 Subject: [PATCH 2/8] recognize emails @cpan.org as pause ids gabor++ for the idea --- lib/MetaCPAN/Web/Controller/Release.pm | 21 ++++++++++++---- root/inc/contributors.html | 33 +++++++++++++------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index c1d6cb2035..e59fdb102f 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -84,15 +84,28 @@ sub view : Private { if ( my $contributors = $out->{metadata}{x_contributors} ) { for my $contributor ( @$contributors ) { + + my $cpan_id; + # don't put email addresses on a web page - next if $contributor =~ s/<.+?>//g; + # TODO can there be more than one <..> ? + if ( $contributor =~ s/<(.+?)>// ) { + my $email = $1; + + if ( $email =~ /^(.+)\@cpan.org/ ) { + $cpan_id = uc $1; + } + }; # looks like a cpan account? - next unless $contributor =~ /^[A-Z]+$/; + $cpan_id ||= $contributor if $contributor =~ /^[A-Z]+$/; + + next unless $cpan_id; $contributor = { - id => $contributor, - url => $c->uri_for_action( '/author/index', [ $contributor ] ), + cpan_id => $cpan_id, + name => $contributor, + url => $c->uri_for_action( '/author/index', [ $cpan_id ] ), }; } } diff --git a/root/inc/contributors.html b/root/inc/contributors.html index 7807c0a1cf..313ca6cfa7 100644 --- a/root/inc/contributors.html +++ b/root/inc/contributors.html @@ -10,10 +10,10 @@
    <% FOREACH contributor IN contributors %>
  • - <% IF contributor.id %> + <% IF contributor.cpan_id %> <% contributor.id %> + data-cpan-author="<% contributor.cpan_id %>"><% contributor.name %> <% ELSE %> <% contributor %> <% END %> @@ -32,21 +32,22 @@ } $.getJSON( "https://api.metacpan.org/author/" + author, function( data ){ - if ( typeof data.name != 'undefined' ) { - // TODO make this an :after pseudo-class - var gravatar = data.gravatar_url; - gravatar = gravatar.replace( - "^http://(www\.)?gravatar.com/", - "https://secure.gravatar.com/" - ).replace( - /s=\d+/, - 's=20' - ); - var $img = $('').attr( 'src', gravatar ) - .attr( 'width', 20 ) - .attr( 'height', 20 ); - $anchor.text( data.name + ' ' ).append( $img ); + if ( typeof data.name == 'undefined' ) { + return; } + // TODO make this an :after pseudo-class + var gravatar = data.gravatar_url; + gravatar = gravatar.replace( + "^http://(www\.)?gravatar.com/", + "https://secure.gravatar.com/" + ).replace( + /s=\d+/, + 's=20' + ); + var $img = $('').attr( 'src', gravatar ) + .attr( 'width', 20 ) + .attr( 'height', 20 ); + $anchor.text( data.name + ' ' ).append( $img ); }); }); }); From dd57b169878365de593bfa7f3464d13ca71f7328 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Wed, 27 Feb 2013 14:37:07 -0500 Subject: [PATCH 3/8] put the gravatar at the front (prettier) --- root/inc/contributors.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/root/inc/contributors.html b/root/inc/contributors.html index 313ca6cfa7..14d0af1c24 100644 --- a/root/inc/contributors.html +++ b/root/inc/contributors.html @@ -9,7 +9,7 @@
- - <% END %> diff --git a/root/static/js/contributors.js b/root/static/js/contributors.js new file mode 100644 index 0000000000..7bd78c5782 --- /dev/null +++ b/root/static/js/contributors.js @@ -0,0 +1,31 @@ +$(function(){ + $('a.cpan_author').each(function(){ + var $anchor = $(this); + var author = $anchor.attr('data-cpan-author'); + if( typeof author == 'undefined' ) { + return; + } + + $.getJSON( "https://api.metacpan.org/author/" + author, function( data ){ + if ( typeof data.name == 'undefined' ) { + return; + } + // TODO make this an :before pseudo-class + var gravatar = data.gravatar_url; + gravatar = gravatar.replace( + "^http://(www\.)?gravatar.com/", + "https://secure.gravatar.com/" + ).replace( + /s=\d+/, + 's=20' + ); + var $img = $('').attr( 'src', gravatar ) + .attr( 'width', 20 ) + .attr( 'height', 20 ); + $anchor.css( 'margin-left', '1px' ); + $anchor.parent().css( 'padding-left', '1px' ); + $anchor.text( data.name ); + $anchor.before( $img ); + }); + }); +}); From eb94b8fde40779a16ef10c52a80145dc5f671dea Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 3 Mar 2013 11:10:22 -0500 Subject: [PATCH 6/8] changing to the new x_contributor structure ... with a little automatic convertion done for testing with the current structure --- lib/MetaCPAN/Web/Controller/Release.pm | 59 ++++++++++++++------------ root/inc/contributors.html | 6 +-- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index e59fdb102f..57d783a8b7 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -82,33 +82,8 @@ sub view : Private { $c->res->last_modified( $out->{date} ); - if ( my $contributors = $out->{metadata}{x_contributors} ) { - for my $contributor ( @$contributors ) { + $self->groom_contributors( $c, $out ); - my $cpan_id; - - # don't put email addresses on a web page - # TODO can there be more than one <..> ? - if ( $contributor =~ s/<(.+?)>// ) { - my $email = $1; - - if ( $email =~ /^(.+)\@cpan.org/ ) { - $cpan_id = uc $1; - } - }; - - # looks like a cpan account? - $cpan_id ||= $contributor if $contributor =~ /^[A-Z]+$/; - - next unless $cpan_id; - - $contributor = { - cpan_id => $cpan_id, - name => $contributor, - url => $c->uri_for_action( '/author/index', [ $cpan_id ] ), - }; - } - } # TODO: make took more automatic (to include all) $c->stash( @@ -134,4 +109,36 @@ sub view : Private { ); } +# massage the x_contributors field into what we want +sub groom_contributors { + my( $self, $c, $out ) = @_; + + return unless $out->{metadata}{x_contributors}; + + # just in case a lonely contributor makes it as a scalar + $out->{metadata}{x_contributors} = [ + $out->{metadata}{x_contributors} + ] unless ref $out->{metadata}{x_contributors}; + + my @contributors = map { + s/<(.*)>//; + { name => $_, email => $1 } + } @{$out->{metadata}{x_contributors}}; + + $out->{metadata}{x_contributors} = \@contributors; + + for my $contributor ( @{ $out->{metadata}{x_contributors} } ) { + + # heuristic to autofill pause accounts + $contributor->{pauseid} = uc $1 + if !$contributor->{pauseid} + and $contributor->{email} =~ /^(.*)\@cpan.org/; + + next unless $contributor->{pauseid}; + + $contributor->{url} = + $c->uri_for_action( '/author/index', [ $contributor->{pauseid} ] ); + } +} + 1; diff --git a/root/inc/contributors.html b/root/inc/contributors.html index 4da70d8bf5..98251ee661 100644 --- a/root/inc/contributors.html +++ b/root/inc/contributors.html @@ -10,12 +10,12 @@