Skip to content

Commit 2f3328c

Browse files
committed
browse
1 parent b09f830 commit 2f3328c

File tree

5 files changed

+77
-50
lines changed

5 files changed

+77
-50
lines changed

lib/MetaCPAN/Web/Controller/Source.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ sub index : Path : Args {
3636
$self->add_cache_headers( $c, $module );
3737

3838
$c->stash( {
39-
template => 'browse.html',
4039
files => $files,
4140
author => shift @module,
4241
release => shift @module,
4342
directory => \@module,
4443
maturity => $module->{maturity},
44+
current_view => 'Xslate',
45+
template => 'browse.tx',
4546
} );
4647
}
4748
elsif ( exists $source->{raw} ) {

lib/MetaCPAN/Web/View/Xslate/Bridge.pm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ sub format_number {
2424
$num_formatter->format_number($number);
2525
}
2626

27+
sub format_bytes {
28+
my ($number) = @_;
29+
$num_formatter->format_bytes($number);
30+
}
31+
2732
my $md = Text::MultiMarkdown->new(heading_ids => 1);
2833
sub markdown {
2934
my ($text) = @_;
@@ -167,11 +172,17 @@ sub decode_punycode {
167172
} || $url_string;
168173
}
169174

175+
sub slice {
176+
my ( $array, $start, $end ) = @_;
177+
return [ @{$array}[$start .. $end] ];
178+
}
179+
170180
no strict 'refs';
171181
__PACKAGE__->bridge(
172182
scalar => {
173183
map +($_ => \&$_), qw(
174184
format_number
185+
format_bytes
175186
markdown
176187
int
177188
json
@@ -182,6 +193,7 @@ __PACKAGE__->bridge(
182193
function => {
183194
map +($_ => \&$_), qw(
184195
format_number
196+
format_bytes
185197
markdown
186198
datetime
187199
gravatar_image
@@ -199,6 +211,7 @@ __PACKAGE__->bridge(
199211
json
200212
json_pretty
201213
indexed_by
214+
slice
202215
),
203216
},
204217
hash => {

root/browse.html

Lines changed: 0 additions & 49 deletions
This file was deleted.

root/browse.tx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
%% cascade base {
2+
%% title => 'Browse ' ~ [$author, $release].merge($directory).join('/'),
3+
%% }
4+
%% override breadcrumbs -> {
5+
<div class="breadcrumbs">
6+
<a href="/source/[% $author %]/[% $release %]">[% $author %] / [% $release %]</a>
7+
%% for $directory -> $part {
8+
%% my $link = $base ~ '/' ~ $directory.slice(0, $~part).join('/')
9+
/ [% if $~part.is_last { $part } else { %]<a href="/source/[% $link %]">[% $part %]</a>[% } %]
10+
%% }
11+
</div>
12+
%% }
13+
%% override left_nav_content -> {
14+
%% include inc::release_status { maturity => $maturity, banner_class => 'release-banner-source' }
15+
<li class="nav-header">Tools</li>
16+
<li><a data-keyboard-shortcut="g d" href="/release/[% $author %]/[% $release %]"><i class="fa fa-fw fa-info-circle black"></i>Release Info</a></li>
17+
<li><a data-keyboard-shortcut="g a" href="/author/[% $author %]"><i class="fa fa-user fa-fw black"></i>Author</a></li>
18+
<li><a href="[% $source_host %]/source/[% [$author, $release].merge($directory).join('/') %]"><i class="fa fa-file-text-o fa-fw black"></i>Raw browser</a></li>
19+
<li class="nav-header">Info</li>
20+
%% my $folder_count = $files.map(-> $f { $f.directory ? 1 : 0 }).sum();
21+
%% my $file_count = $files.size() - $folder_count;
22+
<li>[% pluralize("%d folder(s)", $folder_count) %]</li>
23+
<li>[% pluralize("%d file(s)", $file_count) %]</li>
24+
%% }
25+
%% override content -> {
26+
<div class="content">
27+
<table id="metacpan-file-browse" class="table table-condensed table-striped file-table tablesorter">
28+
<thead>
29+
<tr>
30+
<th class="name">Name</th>
31+
<th class="documentation">Documentation</th>
32+
<th class="size">Size</th>
33+
<th class="mtime">Last Modified</th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
%% for $files -> $file {
38+
<tr>
39+
<td class="name" sort="[% ( $file.directory == 1 ? "!" : '' ) ~ $file.name %]"><a href="/source/[% $author %]/[% $release %]/[% $file.path %]" class="[%
40+
$file.directory ? 'silk-folder'
41+
: $file.mime.match("perl") ? 'silk-page-white-code'
42+
: $file.mime.match("x-c") ? 'silk-page-white-c'
43+
: 'silk-page-white'
44+
%]" title="[% $file.path %]">[% $file.name %]</a></td>
45+
<td class="documentation"><strong><a href="/pod/release/[% $author %]/[% $release %]/[% $file.path %]" title="[% $file.path %]" class="ellipsis">[% $file.slop ? $file.documentation ? $file.documentation : $file.name : "" %]</a></strong></td>
46+
<!-- [% $file | dump %] -->
47+
<td class="size" sort="[% $file.directory ? 0 : $file['stat.size'] %]">[% $file.directory ? '' : format_bytes($file['stat.size']) %]</td>
48+
%% my $date = datetime($file['stat.mtime']).to_http;
49+
<td class="mtime relatize" nowrap="nowrap" sort="[% $date %]">[% $date %]</td>
50+
</tr>
51+
%% }
52+
</tbody>
53+
</table>
54+
</div>
55+
%% }

root/inc/release_status.tx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%% if $maturity == 'developer' {
2+
<li>
3+
<span class="dist-release maturity-developer">
4+
<b class="[% $banner_class %]">Development release</b>
5+
</span>
6+
</li>
7+
%% }

0 commit comments

Comments
 (0)