Skip to content

Commit 82c88e1

Browse files
committed
Merge pull request #1281 from haarg/contributors-improvements
Contributors improvements
2 parents 294968e + 17b89b8 commit 82c88e1

File tree

7 files changed

+73
-40
lines changed

7 files changed

+73
-40
lines changed

lib/MetaCPAN/Web/Controller/Pod.pm

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ sub view : Private {
161161
my $dist = $release->{distribution};
162162
$c->stash( $c->model('API::Favorite')->find_plussers($dist) );
163163

164+
my $contribs = $self->groom_contributors( $c, $release );
165+
164166
$c->stash(
165167
{
166168
module => $data,
@@ -169,6 +171,7 @@ sub view : Private {
169171
template => 'pod.html',
170172
canonical => $canonical,
171173
documented_module => $documented_module,
174+
contributors => $contribs,
172175
}
173176
);
174177
unless ( $reqs->{pod}->{raw} ) {

lib/MetaCPAN/Web/Controller/Release.pm

+3-32
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ sub view : Private {
101101

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

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

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

@@ -123,6 +123,8 @@ sub view : Private {
123123
examples => \@examples,
124124
files => \@view_files,
125125

126+
contributors => $contribs,
127+
126128
# TODO: Put this in a more general place.
127129
# Maybe make a hash for feature flags?
128130
(
@@ -135,35 +137,4 @@ sub view : Private {
135137
);
136138
}
137139

138-
# massage the x_contributors field into what we want
139-
sub groom_contributors {
140-
my ( $self, $c, $out ) = @_;
141-
142-
return unless $out->{metadata}{x_contributors};
143-
144-
# just in case a lonely contributor makes it as a scalar
145-
$out->{metadata}{x_contributors} = [ $out->{metadata}{x_contributors} ]
146-
unless ref $out->{metadata}{x_contributors};
147-
148-
my @contributors = map {
149-
s/<(.*)>//;
150-
{ name => $_, email => $1 }
151-
} @{ $out->{metadata}{x_contributors} };
152-
153-
$out->{metadata}{x_contributors} = \@contributors;
154-
155-
for my $contributor ( @{ $out->{metadata}{x_contributors} } ) {
156-
157-
# heuristic to autofill pause accounts
158-
$contributor->{pauseid} = uc $1
159-
if !$contributor->{pauseid}
160-
and $contributor->{email} =~ /^(.*)\@cpan.org/;
161-
162-
next unless $contributor->{pauseid};
163-
164-
$contributor->{url} = $c->uri_for_action( '/author/index',
165-
[ $contributor->{pauseid} ] );
166-
}
167-
}
168-
169140
1;

lib/MetaCPAN/Web/Role/ReleaseInfo.pm

+44
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,48 @@ sub recv_all {
6767
return { map { $_ => $condvars->{$_}->recv } keys %$condvars };
6868
}
6969

70+
# massage the x_contributors field into what we want
71+
sub groom_contributors {
72+
my ( $self, $c, $release ) = @_;
73+
74+
my $contribs = $release->{metadata}{x_contributors} || [];
75+
my $authors = $release->{metadata}{author} || [];
76+
77+
# just in case a lonely contributor makes it as a scalar
78+
$contribs = [$contribs]
79+
if !ref $contribs;
80+
$authors = [$authors]
81+
if !ref $authors;
82+
83+
my %seen = ( lc "$release->{author}\@cpan.org" => 1, );
84+
my @contribs;
85+
86+
for my $contrib ( @$authors, @$contribs ) {
87+
my $name = $contrib;
88+
$name =~ s/\s*<([^<>]+@[^<>]+)>//;
89+
my $info = {
90+
name => $name,
91+
$1 ? ( email => $1 ) : (),
92+
};
93+
94+
next
95+
if $seen{ $info->{email} }++;
96+
97+
# heuristic to autofill pause accounts
98+
if ( !$info->{pauseid}
99+
and $info->{email} =~ /^(.*)\@cpan\.org$/ )
100+
{
101+
$info->{pauseid} = uc $1;
102+
}
103+
104+
if ( $info->{pauseid} ) {
105+
$info->{url}
106+
= $c->uri_for_action( '/author/index', [ $info->{pauseid} ] );
107+
}
108+
push @contribs, $info;
109+
}
110+
111+
return \@contribs;
112+
}
113+
70114
1;

root/inc/contributors.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<% IF contributors %>
1+
<% IF contributors and contributors.size %>
22

33
<div id="contributors">
4-
<strong>and <% contributors.size %> contributors</strong>
4+
<div class="contributors-header">and <% contributors.size %> contributors</div>
55
<div align="right">
6-
<a name="authors" href="#authors"
7-
onclick="$(this).hide(); $('#contributors ul').slideDown()"
6+
<a href="#"
7+
onclick="$(this).hide(); $('#contributors ul').slideDown(); return false;"
88
>show them</a>
99
</div>
10-
<ul style="display: none">
10+
<ul class="nav nav-list box-right" style="display: none">
1111
<% FOREACH contributor IN contributors %>
1212
<li class="contributor<% ' cpan' IF contributor.pauseid %>">
1313
<% IF contributor.pauseid %>

root/pod.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
</ul>
4242

4343
<div class="pull-right">
44-
<div class="pull-right"><% INCLUDE inc/author-pic.html author = author %></div>
44+
<div class="pull-right">
45+
<% INCLUDE inc/author-pic.html author = author %>
46+
<% INCLUDE inc/contributors.html contributors = contributors %>
47+
</div>
4548
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>
4649
</div>
4750
<a name="___pod"></a>

root/release.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727

2828
<div class="pull-right hidden-phone">
2929
<% INCLUDE inc/author-pic.html author = author %>
30-
<% INCLUDE inc/contributors.html
31-
contributors = release.metadata.x_contributors %>
30+
<% INCLUDE inc/contributors.html contributors = contributors %>
3231
</div>
3332
<% INCLUDE inc/dependencies.html dependencies = release.dependency %>
3433

root/static/css/style.css

+13
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,19 @@ div.qtip-github table th {
311311
* see /release/Plack for example
312312
*/
313313

314+
#contributors {
315+
width: 180px;
316+
}
317+
318+
#contributors > ul {
319+
padding-top: 0;
320+
}
321+
322+
#contributors .contributors-header {
323+
font-weight: bold;
324+
text-align: center;
325+
}
326+
314327
#contributors .contributor {
315328
position: relative;
316329
text-align: left;

0 commit comments

Comments
 (0)