Skip to content

Commit

Permalink
move code from template to the controller module
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Jul 18, 2016
1 parent b8f96dd commit 142bf87
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 31 deletions.
57 changes: 57 additions & 0 deletions lib/MetaCPAN/Web/Controller/Release.pm
Expand Up @@ -125,6 +125,8 @@ sub view : Private {
map +{ %{ $_->{fields} }, %{ $_->{_source} }, },
@{ $modules->{hits}->{hits} };

my $categories = _files_to_categories( $out, \@view_files );

my $changes
= $c->model('API::Changes')->last_version( $reqs->{changes}, $out );

Expand All @@ -140,6 +142,11 @@ sub view : Private {
examples => \@examples,
files => \@view_files,

documentation => $categories->{documentation},
documentation_raw => $categories->{documentation_raw},
provides => $categories->{provides},
modules => $categories->{modules},

# TODO: Put this in a more general place.
# Maybe make a hash for feature flags?
(
Expand All @@ -158,6 +165,56 @@ sub view : Private {
);
}

sub _files_to_categories {
my ( $release, $files ) = @_;
my $ret = +{
provides => [],
documentation => [],
documentation_raw => [],
modules => [],
};

for my $f ( @{$files} ) {
if ( length $f->{module} ) {
push @{ $ret->{modules} } => $f if $f->{documentation};
my %info = (
status => $f->{status},
path => $f->{path},
release => $release->{name},
author => $release->{author},
);
for my $m (
ref $f->{module} eq 'ARRAY'
? @{ $f->{module} }
: $f->{module}
)
{
$info{package} = $m->{name};
if ( $f->{documentation} ) {
if ( $m->{name} ne $f->{documentation}
and $m->{indexed}
and $m->{authorized} )
{
push @{ $ret->{provides} } =>
+{ %info, authorized => 1 };
}
}
else {
push @{ $ret->{provides} } => \%info;
}
}
}
elsif ( $f->{documentation} ) {
push @{ $ret->{documentation} } => $f;
}
else {
push @{ $ret->{documentation_raw} } => $f;
}
}

return $ret;
}

__PACKAGE__->meta->make_immutable;

1;
31 changes: 0 additions & 31 deletions root/release.html
Expand Up @@ -35,37 +35,6 @@

<div class="content">

<%-
documentation = [];
documentation_raw = [];
provides = [];
modules = [];
FOREACH file IN files;
IF file.documentation && file.module.size;
modules.push(file);
FOREACH module IN file.module;
IF module.name != file.documentation && module.indexed && module.authorized;
# There must be a better way...
provides.push({
authorized = module.authorized,
status = file.status, package = module.name, path = file.path, release = release.name, author = release.author });
END;
END;
ELSIF file.module.size;
FOREACH module IN file.module;
provides.push({
authorized = module.authorized,
status = file.status, package = module.name, path = file.path, release = release.name, author = release.author });
END;
ELSIF file.documentation;
documentation.push(file);
ELSE;
documentation_raw.push(file);
END;
END;
documentation = documentation.merge(documentation_raw);
%>

<% MACRO change_group(group) BLOCK; %>
<ul>
<%- FOREACH entry IN group; %>
Expand Down

0 comments on commit 142bf87

Please sign in to comment.