Skip to content

Commit 6fc860e

Browse files
committed
Merge gh-1230 to add more feed data
1 parent ae71cf1 commit 6fc860e

File tree

15 files changed

+174
-19
lines changed

15 files changed

+174
-19
lines changed

Diff for: lib/MetaCPAN/Web/Controller/Feed.pm

+42-8
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ sub author : Chained('index') PathPart Args(1) {
7272

7373
my $author_cv = $c->model('API::Author')->get($author);
7474
my $releases_cv = $c->model('API::Release')->latest_by_author($author);
75-
my $data = {
76-
author => $author_cv->recv,
77-
releases =>
78-
[ map { $_->{fields} } @{ $releases_cv->recv->{hits}{hits} } ],
79-
};
75+
my $release_data
76+
= [ map { $_->{fields} } @{ $releases_cv->recv->{hits}{hits} } ];
77+
my $author_info = $author_cv->recv;
78+
my $faves_cv
79+
= $c->model('API::Favorite')->by_user( $author_info->{user} );
80+
my $faves_data
81+
= [ map { $_->{fields} } @{ $faves_cv->recv->{hits}{hits} } ];
8082

8183
$c->stash->{feed} = $self->build_feed(
82-
title => "Recent CPAN uploads by $data->{author}->{name} - MetaCPAN",
83-
entries => $data->{releases}
84+
title => "Recent CPAN activity of $author - MetaCPAN",
85+
entries => [
86+
sort { $b->{date} cmp $a->{date} }
87+
@{ $self->_format_release_entries($release_data) },
88+
@{ $self->_format_favorite_entries( $author, $faves_data ) }
89+
],
8490
);
8591
}
8692

@@ -98,7 +104,7 @@ sub build_entry {
98104
my $e = XML::Feed::Entry->new('RSS');
99105
$e->title( $entry->{name} );
100106
$e->link(
101-
$entry->{link} // join( '/',
107+
$entry->{link} ||= join( '/',
102108
'http://metacpan.org', 'release',
103109
$entry->{author}, $entry->{name} )
104110
);
@@ -120,6 +126,34 @@ sub build_feed {
120126
return $feed->as_xml;
121127
}
122128

129+
sub _format_release_entries {
130+
my ( $self, $releases ) = @_;
131+
my @release_data;
132+
foreach my $item ( @{$releases} ) {
133+
$item->{link} = join( '/',
134+
'https://metacpan.org', 'release',
135+
$item->{author}, $item->{name} );
136+
$item->{name} = "$item->{author} has released $item->{name}";
137+
push( @release_data, $item );
138+
}
139+
return \@release_data;
140+
}
141+
142+
sub _format_favorite_entries {
143+
my ( $self, $author, $data ) = @_;
144+
my @fav_data;
145+
foreach my $fav ( @{$data} ) {
146+
$fav->{abstract}
147+
= "$author ++ed $fav->{distribution} from $fav->{author}";
148+
$fav->{author} = $author;
149+
$fav->{link} = join( '/',
150+
'https://metacpan.org', 'release', $fav->{distribution} );
151+
$fav->{name} = "$author ++ed $fav->{distribution}";
152+
push( @fav_data, $fav );
153+
}
154+
return \@fav_data;
155+
}
156+
123157
sub end : Private {
124158
my ( $self, $c ) = @_;
125159
$c->res->content_type('application/rss+xml; charset=UTF-8');

Diff for: root/author.html

+6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@
146146
<!-- End left content -->
147147

148148
<div class="content">
149+
<div id="feed_subscription" class="page-header">
150+
<p>Activity for <% author.name %> (<% author.pauseid %>)</p>
151+
<i class="fa fa-rss fa-2x">
152+
<a href="/feed/author/<% author.pauseid %>"></a>
153+
</i>
154+
</div>
149155
<div class="visible-xs inline-author-pic"><% INCLUDE inc/author-pic.html author = author %></div>
150156
<% IF releases.0 %>
151157
<% INCLUDE inc/release-table.html releases = aggregated, header = 1, tablesorter = 1, table_id = "author_releases" %>

Diff for: root/inc/release-tools.html

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<span class="glyphicon glyphicon-star black"></span>Rate this distribution
2020
</a>
2121
</li>
22+
<li>
23+
<a href="/feed/distribution/<% release.distribution %>">
24+
<i class="fa fa-rss-square fa-fw black" id="rss-subscription"></i>Subscribe this distribution
25+
</a>
26+
</li>
2227
<li>
2328
<form action="/search">
2429
<input type="hidden" name="q" value="dist:<% release.distribution %>">

Diff for: root/pod.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<% INCLUDE inc/breadcrumbs.html plussers_div = plusser_authors%>
77

8-
<ul class="nav nav-list slidepanel" id="pod-navlist" itemscope itemtype="http://schema.org/SoftwareApplication">
8+
<ul class="nav nav-list slidepanel" itemscope itemtype="http://schema.org/SoftwareApplication">
99
<li class="visible-xs">
1010
<% INCLUDE mobile/toolbar-search-form.html %>
1111
</li>

Diff for: root/recent.html

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
%>
66

77
<div class="content">
8+
<div id="feed_subscription" class="page-header">
9+
<p>Recent Uploads</p>
10+
<i class="fa fa-rss fa-2x">
11+
<a href="/feed/recent"></a>
12+
</i>
13+
</div>
814
<%-
915
MoY = [undef, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
1016
DoW = [undef, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

Diff for: root/static/css/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,8 @@ div.qtip-github table th {
338338

339339
.news_feed {
340340
float: right;
341+
}
342+
343+
#icon-rss {
344+
background: url('/static/icons/icon-rss.png');
341345
}

Diff for: root/static/icons/icon-rss.png

1.38 KB
Loading

Diff for: root/static/icons/rss_feed.png

3.88 KB
Loading

Diff for: root/static/less/account.less

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
padding-left: 0px !important;
1010
}
1111

12-
1312
#account-profile {
1413
.form-group:after {
1514
clear: both !important;

Diff for: root/static/less/author.less

+26
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,29 @@
6464
}
6565
}
6666
}
67+
68+
#feed_subscription {
69+
&.page-header {
70+
margin: 0 0 5px;
71+
font-weight: bold;
72+
margin-left: 5px;
73+
}
74+
75+
p {
76+
font-size: 16px;
77+
display: inline;
78+
}
79+
80+
a {
81+
display: inline;
82+
width: 20px;
83+
height: 20px;
84+
padding-right: 20px;
85+
float: right;
86+
}
87+
88+
.fa {
89+
float: right;
90+
margin-right: -15px;
91+
}
92+
}

Diff for: root/static/less/button.less

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
font-size: 14px;
1919
line-height: 20px;
2020
margin-bottom: 0;
21+
padding: 4px 12px;
2122
text-align: center;
2223
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
2324
vertical-align: middle;
24-
25-
25+
2626
&:hover,
2727
&:focus {
28-
background-color: #e6e6e6;
29-
text-decoration: none;
30-
background-image: none;
28+
background-color: #e6e6e6;
29+
text-decoration: none;
30+
background-image: none;
3131
}
3232
}
3333

Diff for: root/static/less/nav-list.less

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ul.nav-list.box-right {
4848

4949
.nav > li {
5050
line-height: 20px;
51+
width: inherit;
5152
}
5253

5354
.nav-list > li > a,
@@ -100,6 +101,6 @@ ul.nav-list.box-right {
100101
line-height: 25px;
101102
}
102103

103-
#pod-navlist li {
104+
.left-toolbar li {
104105
width: 180px;
105-
}
106+
}

Diff for: root/static/less/responsive.less

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136

137137
.home input.home-search-input {
138138
position: relative;
139+
right: 5px;
139140
width: 93%;
140141
font-size: 1.4em;
141142
}

Diff for: root/static/less/style.less

+12-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
@screen-sm-min: (@screen-xs + 1);
3636

3737
h1, .h1, h2, .h2, h3, .h3 {
38-
line-height: 35px;
38+
line-height: 35px;
3939
}
4040

4141
.black {
@@ -61,6 +61,11 @@ h1, .h1, h2, .h2, h3, .h3 {
6161

6262
input#search-input {
6363
font-size: 16px;
64+
height: 30px;
65+
}
66+
67+
.home {
68+
padding: 40px 0 50px;
6469
}
6570

6671
.home .btn {
@@ -183,7 +188,7 @@ li button.dependencies-graph {
183188
}
184189

185190
.top-content {
186-
padding-bottom: 10px;
191+
padding-bottom: 10px;
187192
}
188193

189194
.row-fluid {
@@ -206,3 +211,8 @@ li button.dependencies-graph {
206211
.message {
207212
padding-left: 5px;
208213
}
214+
215+
#rss-subscription {
216+
width: 1.2em;
217+
font-size: 1.1em;
218+
}

Diff for: t/controller/feed.t

+63
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use warnings;
33
use Test::More;
44
use MetaCPAN::Web::Test;
55
use Try::Tiny;
6+
use MetaCPAN::Web::Controller::Feed;
67

78
my @tests
89
= qw(/feed/recent /feed/author/PERLER /feed/distribution/Moose /feed/news);
@@ -52,4 +53,66 @@ sub valid_xml {
5253
return $tx;
5354
}
5455

56+
my $feed = MetaCPAN::Web::Controller::Feed->new();
57+
58+
subtest 'get correct author favorite data format' => sub {
59+
my $favorite_data = [
60+
{
61+
author => 'DOLMEN',
62+
date => '2013-07-05T14:41:26.000Z',
63+
distribution => 'Git-Sub',
64+
}
65+
];
66+
67+
my $entry
68+
= $feed->_format_favorite_entries( 'PERLHACKER', $favorite_data );
69+
is(
70+
$entry->[0]->{abstract},
71+
'PERLHACKER ++ed Git-Sub from DOLMEN',
72+
'get correct release abstract'
73+
);
74+
is(
75+
$entry->[0]->{link},
76+
'https://metacpan.org/release/Git-Sub',
77+
'get correct release link'
78+
);
79+
is(
80+
$entry->[0]->{name},
81+
'PERLHACKER ++ed Git-Sub',
82+
'get correct release title'
83+
);
84+
is( $entry->[0]->{author}, 'PERLHACKER', 'get correct author name' );
85+
};
86+
87+
subtest 'get correct author release data format' => sub {
88+
my $data = [
89+
{
90+
abstract => 'Easy OO access to the FreshBooks.com API',
91+
author => 'OALDERS',
92+
date => '2014-05-03T03:06:44.000Z',
93+
distribution => 'Net-FreshBooks-API',
94+
name => 'Net-FreshBooks-API-0.24',
95+
status => 'latest',
96+
}
97+
];
98+
99+
my $entry = $feed->_format_release_entries($data);
100+
is(
101+
$entry->[0]->{abstract},
102+
'Easy OO access to the FreshBooks.com API',
103+
'get correct release abstract'
104+
);
105+
is(
106+
$entry->[0]->{link},
107+
'https://metacpan.org/release/OALDERS/Net-FreshBooks-API-0.24',
108+
'get correct release link'
109+
);
110+
is(
111+
$entry->[0]->{name},
112+
'OALDERS has released Net-FreshBooks-API-0.24',
113+
'get correct release title'
114+
);
115+
is( $entry->[0]->{author}, 'OALDERS', 'get correct author name' );
116+
};
117+
55118
done_testing;

0 commit comments

Comments
 (0)