Skip to content

Commit

Permalink
Merge gh-1230 to add more feed data
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Aug 12, 2014
1 parent ae71cf1 commit 6fc860e
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 19 deletions.
50 changes: 42 additions & 8 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Expand Up @@ -72,15 +72,21 @@ sub author : Chained('index') PathPart Args(1) {

my $author_cv = $c->model('API::Author')->get($author);
my $releases_cv = $c->model('API::Release')->latest_by_author($author);
my $data = {
author => $author_cv->recv,
releases =>
[ map { $_->{fields} } @{ $releases_cv->recv->{hits}{hits} } ],
};
my $release_data
= [ map { $_->{fields} } @{ $releases_cv->recv->{hits}{hits} } ];
my $author_info = $author_cv->recv;
my $faves_cv
= $c->model('API::Favorite')->by_user( $author_info->{user} );
my $faves_data
= [ map { $_->{fields} } @{ $faves_cv->recv->{hits}{hits} } ];

$c->stash->{feed} = $self->build_feed(
title => "Recent CPAN uploads by $data->{author}->{name} - MetaCPAN",
entries => $data->{releases}
title => "Recent CPAN activity of $author - MetaCPAN",
entries => [
sort { $b->{date} cmp $a->{date} }
@{ $self->_format_release_entries($release_data) },
@{ $self->_format_favorite_entries( $author, $faves_data ) }
],
);
}

Expand All @@ -98,7 +104,7 @@ sub build_entry {
my $e = XML::Feed::Entry->new('RSS');
$e->title( $entry->{name} );
$e->link(
$entry->{link} // join( '/',
$entry->{link} ||= join( '/',
'http://metacpan.org', 'release',
$entry->{author}, $entry->{name} )
);
Expand All @@ -120,6 +126,34 @@ sub build_feed {
return $feed->as_xml;
}

sub _format_release_entries {
my ( $self, $releases ) = @_;
my @release_data;
foreach my $item ( @{$releases} ) {
$item->{link} = join( '/',
'https://metacpan.org', 'release',
$item->{author}, $item->{name} );
$item->{name} = "$item->{author} has released $item->{name}";
push( @release_data, $item );
}
return \@release_data;
}

sub _format_favorite_entries {
my ( $self, $author, $data ) = @_;
my @fav_data;
foreach my $fav ( @{$data} ) {
$fav->{abstract}
= "$author ++ed $fav->{distribution} from $fav->{author}";
$fav->{author} = $author;
$fav->{link} = join( '/',
'https://metacpan.org', 'release', $fav->{distribution} );
$fav->{name} = "$author ++ed $fav->{distribution}";
push( @fav_data, $fav );
}
return \@fav_data;
}

sub end : Private {
my ( $self, $c ) = @_;
$c->res->content_type('application/rss+xml; charset=UTF-8');
Expand Down
6 changes: 6 additions & 0 deletions root/author.html
Expand Up @@ -146,6 +146,12 @@
<!-- End left content -->

<div class="content">
<div id="feed_subscription" class="page-header">
<p>Activity for <% author.name %> (<% author.pauseid %>)</p>
<i class="fa fa-rss fa-2x">
<a href="/feed/author/<% author.pauseid %>"></a>
</i>
</div>
<div class="visible-xs inline-author-pic"><% INCLUDE inc/author-pic.html author = author %></div>
<% IF releases.0 %>
<% INCLUDE inc/release-table.html releases = aggregated, header = 1, tablesorter = 1, table_id = "author_releases" %>
Expand Down
5 changes: 5 additions & 0 deletions root/inc/release-tools.html
Expand Up @@ -19,6 +19,11 @@
<span class="glyphicon glyphicon-star black"></span>Rate this distribution
</a>
</li>
<li>
<a href="/feed/distribution/<% release.distribution %>">
<i class="fa fa-rss-square fa-fw black" id="rss-subscription"></i>Subscribe this distribution
</a>
</li>
<li>
<form action="/search">
<input type="hidden" name="q" value="dist:<% release.distribution %>">
Expand Down
2 changes: 1 addition & 1 deletion root/pod.html
Expand Up @@ -5,7 +5,7 @@

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

<ul class="nav nav-list slidepanel" id="pod-navlist" itemscope itemtype="http://schema.org/SoftwareApplication">
<ul class="nav nav-list slidepanel" itemscope itemtype="http://schema.org/SoftwareApplication">
<li class="visible-xs">
<% INCLUDE mobile/toolbar-search-form.html %>
</li>
Expand Down
6 changes: 6 additions & 0 deletions root/recent.html
Expand Up @@ -5,6 +5,12 @@
%>

<div class="content">
<div id="feed_subscription" class="page-header">
<p>Recent Uploads</p>
<i class="fa fa-rss fa-2x">
<a href="/feed/recent"></a>
</i>
</div>
<%-
MoY = [undef, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
DoW = [undef, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
Expand Down
4 changes: 4 additions & 0 deletions root/static/css/style.css
Expand Up @@ -338,4 +338,8 @@ div.qtip-github table th {

.news_feed {
float: right;
}

#icon-rss {
background: url('/static/icons/icon-rss.png');
}
Binary file added root/static/icons/icon-rss.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added root/static/icons/rss_feed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion root/static/less/account.less
Expand Up @@ -9,7 +9,6 @@
padding-left: 0px !important;
}


#account-profile {
.form-group:after {
clear: both !important;
Expand Down
26 changes: 26 additions & 0 deletions root/static/less/author.less
Expand Up @@ -64,3 +64,29 @@
}
}
}

#feed_subscription {
&.page-header {
margin: 0 0 5px;
font-weight: bold;
margin-left: 5px;
}

p {
font-size: 16px;
display: inline;
}

a {
display: inline;
width: 20px;
height: 20px;
padding-right: 20px;
float: right;
}

.fa {
float: right;
margin-right: -15px;
}
}
10 changes: 5 additions & 5 deletions root/static/less/button.less
Expand Up @@ -18,16 +18,16 @@
font-size: 14px;
line-height: 20px;
margin-bottom: 0;
padding: 4px 12px;
text-align: center;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
vertical-align: middle;



&:hover,
&:focus {
background-color: #e6e6e6;
text-decoration: none;
background-image: none;
background-color: #e6e6e6;
text-decoration: none;
background-image: none;
}
}

Expand Down
5 changes: 3 additions & 2 deletions root/static/less/nav-list.less
Expand Up @@ -48,6 +48,7 @@ ul.nav-list.box-right {

.nav > li {
line-height: 20px;
width: inherit;
}

.nav-list > li > a,
Expand Down Expand Up @@ -100,6 +101,6 @@ ul.nav-list.box-right {
line-height: 25px;
}

#pod-navlist li {
.left-toolbar li {
width: 180px;
}
}
1 change: 1 addition & 0 deletions root/static/less/responsive.less
Expand Up @@ -136,6 +136,7 @@

.home input.home-search-input {
position: relative;
right: 5px;
width: 93%;
font-size: 1.4em;
}
Expand Down
14 changes: 12 additions & 2 deletions root/static/less/style.less
Expand Up @@ -35,7 +35,7 @@
@screen-sm-min: (@screen-xs + 1);

h1, .h1, h2, .h2, h3, .h3 {
line-height: 35px;
line-height: 35px;
}

.black {
Expand All @@ -61,6 +61,11 @@ h1, .h1, h2, .h2, h3, .h3 {

input#search-input {
font-size: 16px;
height: 30px;
}

.home {
padding: 40px 0 50px;
}

.home .btn {
Expand Down Expand Up @@ -183,7 +188,7 @@ li button.dependencies-graph {
}

.top-content {
padding-bottom: 10px;
padding-bottom: 10px;
}

.row-fluid {
Expand All @@ -206,3 +211,8 @@ li button.dependencies-graph {
.message {
padding-left: 5px;
}

#rss-subscription {
width: 1.2em;
font-size: 1.1em;
}
63 changes: 63 additions & 0 deletions t/controller/feed.t
Expand Up @@ -3,6 +3,7 @@ use warnings;
use Test::More;
use MetaCPAN::Web::Test;
use Try::Tiny;
use MetaCPAN::Web::Controller::Feed;

my @tests
= qw(/feed/recent /feed/author/PERLER /feed/distribution/Moose /feed/news);
Expand Down Expand Up @@ -52,4 +53,66 @@ sub valid_xml {
return $tx;
}

my $feed = MetaCPAN::Web::Controller::Feed->new();

subtest 'get correct author favorite data format' => sub {
my $favorite_data = [
{
author => 'DOLMEN',
date => '2013-07-05T14:41:26.000Z',
distribution => 'Git-Sub',
}
];

my $entry
= $feed->_format_favorite_entries( 'PERLHACKER', $favorite_data );
is(
$entry->[0]->{abstract},
'PERLHACKER ++ed Git-Sub from DOLMEN',
'get correct release abstract'
);
is(
$entry->[0]->{link},
'https://metacpan.org/release/Git-Sub',
'get correct release link'
);
is(
$entry->[0]->{name},
'PERLHACKER ++ed Git-Sub',
'get correct release title'
);
is( $entry->[0]->{author}, 'PERLHACKER', 'get correct author name' );
};

subtest 'get correct author release data format' => sub {
my $data = [
{
abstract => 'Easy OO access to the FreshBooks.com API',
author => 'OALDERS',
date => '2014-05-03T03:06:44.000Z',
distribution => 'Net-FreshBooks-API',
name => 'Net-FreshBooks-API-0.24',
status => 'latest',
}
];

my $entry = $feed->_format_release_entries($data);
is(
$entry->[0]->{abstract},
'Easy OO access to the FreshBooks.com API',
'get correct release abstract'
);
is(
$entry->[0]->{link},
'https://metacpan.org/release/OALDERS/Net-FreshBooks-API-0.24',
'get correct release link'
);
is(
$entry->[0]->{name},
'OALDERS has released Net-FreshBooks-API-0.24',
'get correct release title'
);
is( $entry->[0]->{author}, 'OALDERS', 'get correct author name' );
};

done_testing;

0 comments on commit 6fc860e

Please sign in to comment.