Skip to content

Contributors improvements #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/MetaCPAN/Web/Controller/Pod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ sub view : Private {
my $dist = $release->{distribution};
$c->stash( $c->model('API::Favorite')->find_plussers($dist) );

my $contribs = $self->groom_contributors( $c, $release );

$c->stash(
{
module => $data,
Expand All @@ -169,6 +171,7 @@ sub view : Private {
template => 'pod.html',
canonical => $canonical,
documented_module => $documented_module,
contributors => $contribs,
}
);
unless ( $reqs->{pod}->{raw} ) {
Expand Down
35 changes: 3 additions & 32 deletions lib/MetaCPAN/Web/Controller/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ sub view : Private {

$c->res->last_modified( $out->{date} );

$self->groom_contributors( $c, $out );
my $contribs = $self->groom_contributors( $c, $out );

$c->stash( $c->model('API::Favorite')->find_plussers($distribution) );

Expand All @@ -123,6 +123,8 @@ sub view : Private {
examples => \@examples,
files => \@view_files,

contributors => $contribs,

# TODO: Put this in a more general place.
# Maybe make a hash for feature flags?
(
Expand All @@ -135,35 +137,4 @@ 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;
44 changes: 44 additions & 0 deletions lib/MetaCPAN/Web/Role/ReleaseInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,48 @@ sub recv_all {
return { map { $_ => $condvars->{$_}->recv } keys %$condvars };
}

# massage the x_contributors field into what we want
sub groom_contributors {
my ( $self, $c, $release ) = @_;

my $contribs = $release->{metadata}{x_contributors} || [];
my $authors = $release->{metadata}{author} || [];

# just in case a lonely contributor makes it as a scalar
$contribs = [$contribs]
if !ref $contribs;
$authors = [$authors]
if !ref $authors;

my %seen = ( lc "$release->{author}\@cpan.org" => 1, );
my @contribs;

for my $contrib ( @$authors, @$contribs ) {
my $name = $contrib;
$name =~ s/\s*<([^<>]+@[^<>]+)>//;
my $info = {
name => $name,
$1 ? ( email => $1 ) : (),
};

next
if $seen{ $info->{email} }++;

# heuristic to autofill pause accounts
if ( !$info->{pauseid}
and $info->{email} =~ /^(.*)\@cpan\.org$/ )
{
$info->{pauseid} = uc $1;
}

if ( $info->{pauseid} ) {
$info->{url}
= $c->uri_for_action( '/author/index', [ $info->{pauseid} ] );
}
push @contribs, $info;
}

return \@contribs;
}

1;
10 changes: 5 additions & 5 deletions root/inc/contributors.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<% IF contributors %>
<% IF contributors and contributors.size %>

<div id="contributors">
<strong>and <% contributors.size %> contributors</strong>
<div class="contributors-header">and <% contributors.size %> contributors</div>
<div align="right">
<a name="authors" href="#authors"
onclick="$(this).hide(); $('#contributors ul').slideDown()"
<a href="#"
onclick="$(this).hide(); $('#contributors ul').slideDown(); return false;"
>show them</a>
</div>
<ul style="display: none">
<ul class="nav nav-list box-right" style="display: none">
<% FOREACH contributor IN contributors %>
<li class="contributor<% ' cpan' IF contributor.pauseid %>">
<% IF contributor.pauseid %>
Expand Down
5 changes: 4 additions & 1 deletion root/pod.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
</ul>

<div class="pull-right">
<div class="pull-right"><% INCLUDE inc/author-pic.html author = author %></div>
<div class="pull-right">
<% INCLUDE inc/author-pic.html author = author %>
<% INCLUDE inc/contributors.html contributors = contributors %>
</div>
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>
</div>
<% IF req.cookies.hideTOC.value %><style>#index { display:none}</style><% END %>
Expand Down
3 changes: 1 addition & 2 deletions root/release.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

<div class="pull-right hidden-phone">
<% INCLUDE inc/author-pic.html author = author %>
<% INCLUDE inc/contributors.html
contributors = release.metadata.x_contributors %>
<% INCLUDE inc/contributors.html contributors = contributors %>
</div>
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>

Expand Down
15 changes: 14 additions & 1 deletion root/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@ div.qtip-github table th {
* see /release/Plack for example
*/

#contributors {
width: 180px;
}

#contributors > ul {
padding-top: 0;
}

#contributors .contributors-header {
font-weight: bold;
text-align: center;
}

#contributors .contributor {
position: relative;
text-align: left;
Expand Down Expand Up @@ -343,4 +356,4 @@ div.qtip-github table th {

#icon-rss {
background: url('/static/icons/icon-rss.png');
}
}