Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ditch logo from the Dists model
We can now auto-generate logosprites from dist names and checking the logotype dir for the actual file, so we don"t need to store that piece of data in DB
  • Loading branch information
zoffixznet committed Nov 25, 2015
1 parent a78e86c commit 603b213
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
3 changes: 2 additions & 1 deletion lib/DbBuilder/Dist/Source.pm
Expand Up @@ -91,15 +91,16 @@ sub _fill_missing {
if ( length $dist->{name} ) {
$old_dist_data
= $self->_dist_db->find({ name => $dist->{name} })->first;
$old_dist_data and delete $old_dist_data->{logo};
}


%$dist = (
name => 'N/A',
author_id => $dist->{author}
// (@{ $dist->{authors}||[] })[0] // 'N/A',
url => 'N/A',
description => 'N/A',
logo => 'N_A',
stars => 0,
issues => 0,
date_updated => 0,
Expand Down
5 changes: 5 additions & 0 deletions lib/ModulesPerl6/Controller/Root.pm
Expand Up @@ -20,6 +20,11 @@ sub index {
}

for ( @$dists ) {
my $logo_base = 's-' . $_->{name} =~ s/\W/_/gr;
$_->{logo} = $logo_base if $self->app->static->file(
"content-pics/dist-logos/$logo_base.png"
);

$_->{date_updated} = strftime "%Y-%m-%d", localtime $_->{date_updated};
$_->{travis_url} = Mojo::URL->new($_->{url})->host('travis-ci.org');
$_->{is_hidden} = 1
Expand Down
8 changes: 1 addition & 7 deletions lib/ModulesPerl6/Model/Dists.pm
Expand Up @@ -64,7 +64,7 @@ sub add {
author_id => $dist->{author_id}, name => $dist->{author_id},
},
map +( $_ => $dist->{$_} ),
qw/name url description logo stars issues kwalitee
qw/name url description stars issues kwalitee
date_updated date_added build_id/,
});
}
Expand Down Expand Up @@ -149,7 +149,6 @@ if set, or C<modulesperl6.db>.
url => 'https://github.com/perl6/modules.perl6.org/',
description => 'Test Dist1',
author_id => 'Dynacoder',
logo => 'dist1',
has_readme => 1,
panda => 2,
has_tests => 1,
Expand Down Expand Up @@ -182,11 +181,6 @@ Short description of the dist.
Dists's "authority".
=head3 C<logo>
The name of dist's logo within the sprite generated by the build script
(this likely will be the name of the dist with C<\W+> changed to underscores).
=head3 C<has_readme>
Boolean: does the dist have README file?
Expand Down
1 change: 0 additions & 1 deletion lib/ModulesPerl6/Model/Dists/Schema/Result/Dist.pm
Expand Up @@ -7,7 +7,6 @@ column build_id => { data_type => 'text', is_foreign_key => 1 };
column travis_status => { data_type => 'text', is_foreign_key => 1 };
column url => { data_type => 'text' };
column description => { data_type => 'text' };
column logo => { data_type => 'text' };
column kwalitee => { data_type => 'integer' };
column stars => { data_type => 'integer' };
column issues => { data_type => 'integer' };
Expand Down
1 change: 0 additions & 1 deletion t/02-db-builder/02-github-source.t
Expand Up @@ -60,7 +60,6 @@ subtest 'Repo without a README, tests, or logotype' => sub {
is_deeply $m->find({name => 'TestRepo1'})->first, {
date_added => 0,
author_id => 'Zoffix Znet',
logo => 'N_A',
name => 'TestRepo1',
kwalitee => 100,
date_updated => 1448202981,
Expand Down
6 changes: 4 additions & 2 deletions t/03-app/01-home-page.t
Expand Up @@ -2,6 +2,7 @@

use strict;
use warnings FATAL => 'all';
use File::Temp;
use Test::Most;
use Mojo::URL;
use Test::Mojo::WithRoles qw/SubmitForm ElementCounter Debug/;
Expand All @@ -18,6 +19,7 @@ $_->{travis_url} = Mojo::URL->new($_->{url})->host('travis-ci.org')

{
diag 'Have dists table with right data';

$t->dive_reset->get_ok('/')->status_is(200)
->element_count_is('#dists tbody tr' => 2, 'we have just two dists')
->dive_in('#dists tbody tr:first-child ')
Expand All @@ -31,7 +33,7 @@ $_->{travis_url} = Mojo::URL->new($_->{url})->host('travis-ci.org')
# ->dived_text_is('.added' => '2015-11-04')
->element_count_is(".name a[href='$dist1->{url}']" => 1)
->element_count_is('.name a[href="/dist/Dist1"]' => 1)
->element_count_is('.name a i.dist-logos.s-dist1' => 1)
# ->element_count_is('.name a i.dist-logos.s-Dist1' => 1)
->element_count_is(".travis a[href='$dist1->{travis_url}']" => 1)
->element_count_is(".stars a[href='$dist1->{url}stargazers']" => 1)
->element_count_is(".issues a[href='$dist1->{url}issues']" => 1)
Expand All @@ -49,7 +51,7 @@ $_->{travis_url} = Mojo::URL->new($_->{url})->host('travis-ci.org')
# ->dived_text_is('.added' => '2015-10-26')
->element_count_is(".name a[href='$dist2->{url}']" => 1)
->element_count_is('.name a[href="/dist/Dist2"]' => 1)
->element_count_is('.name a i.dist-logos.s-dist2' => 1)
# ->element_count_is('.name a i.dist-logos.s-Dist2' => 1)
->element_count_is('.kwalitee a[href="/kwalitee/Dist2"]' => 1)
->element_count_is(".travis a[href='$dist2->{travis_url}']" => 1)
->element_count_is(".stars a[href='$dist2->{url}stargazers']" => 1)
Expand Down
4 changes: 0 additions & 4 deletions t/Helper.pm
Expand Up @@ -31,7 +31,6 @@ sub dist_in_data {
url => 'https://github.com/perl6/modules.perl6.org/',
description => 'Test Dist1',
author_id => 'Dynacoder',
logo => 's-dist1',
has_readme => 1,
panda => 2,
has_tests => 1,
Expand All @@ -47,7 +46,6 @@ sub dist_in_data {
url => 'https://github.com/perl6/ecosystem/',
description => 'Test Dist2',
author_id => 'Morbo',
logo => 's-dist2',
has_readme => 0,
panda => 0,
has_tests => 0,
Expand All @@ -68,7 +66,6 @@ sub dist_out_data {
url => 'https://github.com/perl6/modules.perl6.org/',
description => 'Test Dist1',
author_id => 'Dynacoder',
logo => 's-dist1',
kwalitee => 100,
travis_status=> 'passing',
stars => 42,
Expand All @@ -82,7 +79,6 @@ sub dist_out_data {
url => 'https://github.com/perl6/ecosystem/',
description => 'Test Dist2',
author_id => 'Morbo',
logo => 's-dist2',
kwalitee => 100,
travis_status=> 'failing',
stars => 14,
Expand Down
4 changes: 3 additions & 1 deletion templates/root/index.html.ep
Expand Up @@ -64,7 +64,9 @@
<a href="<%= $dist->{url} %>" class="github"></a>
<a href="<%= url_for('dist', dist => $dist->{name} ) %>"
><%= $dist->{name} %>
<i class="dist-logos <%= $dist->{logo} %>"></i>
<!-- % if ( length $dist->{logo} ) { -->
<i class="dist-logos <%= $dist->{logo} %>"></i>
<!-- % } -->
</a>
</td>
<td class="desc"><%= $dist->{description} %></td>
Expand Down

0 comments on commit 603b213

Please sign in to comment.