Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions lib/MetaCPAN/Web/Controller/ContributingDoc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sub get : Private {

my $file = List::Util::first { $_->{name} =~ /$contributing_re/ } @$files;

if ( !exists $file->{path} ) {
if ( !$file || !exists $file->{path} ) {
my $release_info = $c->model('ReleaseInfo')->get( $author, $release );
$c->stash( $release_info->get );
$c->stash( {
Expand All @@ -47,17 +47,11 @@ sub get : Private {
$c->response->status(404);
}
else {
if ( $file->{pod_lines} && @{ $file->{pod_lines} } ) {
$c->stash(
author_name => $author,
release_name => $release,
);
$c->forward( '/view/release', [ $file->{path} ] );
}
else {
$c->forward( '/source/view',
[ $file->{author}, $file->{release}, $file->{path} ] );
}
$c->stash(
author_name => $author,
release_name => $release,
);
$c->forward( '/view/release', [ $file->{path} ] );
}
}

Expand Down
22 changes: 22 additions & 0 deletions lib/MetaCPAN/Web/Controller/MD.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package MetaCPAN::Web::Controller::MD;

use Moose;

use namespace::autoclean;

BEGIN { extends 'MetaCPAN::Web::Controller' }

sub view : Private {
my ( $self, $c, $author, $release, @path ) = @_;

my $source = $c->model('API::File')->source( $author, $release, @path );

$c->stash( {
source => $source->get->{raw},
template => 'md.tx',
} );
}

__PACKAGE__->meta->make_immutable;

1;
7 changes: 1 addition & 6 deletions lib/MetaCPAN/Web/Controller/Pod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sub find : Path : Args(1) {

# TODO: Disambiguate if there's more than one match. #176

$c->forward( 'view', [@path] );
$c->forward( '/view/file', [@path] );
}

sub view : Private {
Expand Down Expand Up @@ -70,11 +70,6 @@ sub view : Private {
$c->detach('/not_found')
if ( $pod->{code} || 0 ) > 399;

# Store at fastly for a year - as we will purge!
$c->cdn_max_age('1y');
$c->add_dist_key( $release->{distribution} );
$c->add_author_key( $release->{author} );

if ( $data->{deprecated} ) {
$c->stash->{notification} ||= { type => 'MODULE_DEPRECATED' };
}
Expand Down
28 changes: 26 additions & 2 deletions lib/MetaCPAN/Web/Controller/View.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sub dist : Chained('/dist/root') PathPart('view') Args {
%$release_data, file => $c->model('API::File')->get(@path)->get,
} );

$c->forward( '/pod/view', [@path] );
$c->forward( 'file', [@path] );
}

sub release : Chained('/release/root') PathPart('view') Args {
Expand All @@ -52,7 +52,31 @@ sub release : Chained('/release/root') PathPart('view') Args {
permalinks => 1,
} );

$c->forward( '/pod/view', [ $author, $release, @path ] );
$c->forward( 'file', [ $author, $release, @path ] );
}

sub file : Private {
my ( $self, $c, @path ) = @_;

my $release = $c->stash->{release};
my $file = $c->stash->{file};

$c->cdn_max_age('1y');
$c->add_dist_key( $release->{distribution} );
$c->add_author_key( $release->{author} );

if ( $file->{mime} eq 'text/x-script.perl'
|| $file->{mime} eq 'text/x-script.perl-module'
|| $file->{mime} eq 'text/x-pod' )
{
$c->forward( '/pod/view', \@path );
}
elsif ( $file->{mime} eq 'text/markdown' ) {
$c->forward( '/md/view', \@path );
}
else {
$c->forward( '/source/view', \@path );
}
}

__PACKAGE__->meta->make_immutable;
Expand Down
11 changes: 11 additions & 0 deletions lib/MetaCPAN/Web/Model/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ use Try::Tiny qw( catch try );
use URI ();
use URI::Escape qw( uri_escape );

use Data::Dump ();
use Data::Dump::Filtered ();

Data::Dump::Filtered::add_dump_filter( sub {
my ( $ctx, $object_ref ) = @_;
if ( $ctx->object_isa('IO::Async::Loop') ) {
return { dump => "bless({ '...' => '...' }, '" . $ctx->class . "')" };
}
return undef;
} );

my $loop;

sub loop {
Expand Down
2 changes: 1 addition & 1 deletion root/base.tx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<div class="content-navigation">
%% block breadcrumbs -> { }
</div>
<main class="[% block content_classes -> { 'content' } %]">
<main class="[% block content_classes -> { } %]">
%% block content -> { }
</main>
<div class="content-pagination">
Expand Down
2 changes: 1 addition & 1 deletion root/inc/link_to_file.tx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
my $title = $file.documentation || $file.path;

# If there is pod for this file...
if $file.documentation || $file.pod_lines.size() || $file.has_associated_pod {
if $file.documentation || $file.pod_lines.size() || $file.has_associated_pod || $file.mime == 'text/markdown' {
-%]
<a href="[%
if !$permalinks {
Expand Down
4 changes: 4 additions & 0 deletions root/md.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%% cascade pod
%% override content -> {
[% $source | markdown | filter_html %]
%% }
5 changes: 0 additions & 5 deletions root/source.tx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@
%% }
%% override content -> {
%% if !$file.binary {
%% if $file.mime == 'text/markdown' {
[% $source | markdown | filter_html %]
%% }
%% else {
<pre id="metacpan_source" class="line-numbers pod-toggle[% if $file.sloc > 10 { " pod-hidden"; } %]" data-pod-lines="[%
$file.pod_lines.map(-> $lines { $lines[0] ~ '-' ~ ($lines[0]+$lines[1]) }).join(', ');
%]"><code class="language-[% $syntax_type %]">[% $source %]</code></pre>
%% }
%% }
%% else {
This file cannot be displayed inline. Try the <a href="[% $api_public ~ '/source/' ~ $file.author ~ '/' ~ $file.release ~ '/' ~ $file.path %]">raw file</a>.
Expand Down
2 changes: 1 addition & 1 deletion root/static/js/cpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ for (const favButton of document.querySelectorAll('.breadcrumbs .favorite')) {

jQuery('.dropdown-toggle').dropdown(); // bootstrap

const toc = document.querySelector('.content .toc');
const toc = document.querySelector('main .toc');
if (toc) {
formatTOC(toc);
}
Expand Down
2 changes: 1 addition & 1 deletion root/static/js/syntaxhighlighter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ if (source) {
}
}

for (const code of document.querySelectorAll('.content pre > code')) {
for (const code of document.querySelectorAll('main pre > code')) {
const pre = code.parentNode;

const config = {
Expand Down
4 changes: 2 additions & 2 deletions root/static/less/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ h3,
.content-navigation {
grid-area: breadcrumbs;
}
.content {
main {
grid-area: content;
}
.content-pagination {
Expand Down Expand Up @@ -444,7 +444,7 @@ h3,
padding-left: 5px;
}

.content {
main {
justify-self: center;
line-height: 1.54em;
padding: 40px;
Expand Down
2 changes: 1 addition & 1 deletion root/static/less/pod.less
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
}
}

.content .toc {
main .toc {
display: inline-block;
border: 1px solid rgb(215, 215, 215);
padding: 3px 10px;
Expand Down
4 changes: 2 additions & 2 deletions root/static/less/release.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.content {
main {
.release-documentation,
.release-modules,
.release-provides {
Expand Down Expand Up @@ -46,7 +46,7 @@
* See /release/CPAN-Changes for example
*/
#metacpan_last-changes {
h2:extend(.content .file-group h2) {
h2:extend(main .file-group h2) {
}

ul {
Expand Down
2 changes: 1 addition & 1 deletion root/static/less/responsive.less
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
width: 95%;
}

.content {
main {
padding: 20px;
}

Expand Down
2 changes: 1 addition & 1 deletion t/controller/changes.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_psgi app, sub {
is( $res->code, 200, "200 on $url" );
my $tx = tx($res);
$tx->like(
'//*[contains-token(@class, "content")]//pre[@id="metacpan_source"]',
'//main//pre[@id="metacpan_source"]',
qr/^Revision history for File-Spec-Native/,
'source view for plain text change log'
);
Expand Down
3 changes: 1 addition & 2 deletions t/controller/contributing-to.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ test_psgi app, sub {
is( $res->code, 404, 'code 404' );

my $tx2 = tx($res);
$tx2->find_value( '//div[contains-token(@class, "content")]',
'page has content' );
$tx2->find_value( '//main', 'page has content' );
$tx2->like(
q[//div[contains-token(@class, 'about')]],
qr/No Contributing guidelines.+found/,
Expand Down
7 changes: 3 additions & 4 deletions t/controller/pod.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ test_psgi app, sub {
);

my $tx2 = tx($res);
ok( $tx->find_value('//*[contains-token(@class, "content")]'),
'page has content' );
ok( $tx->find_value('//main'), 'page has content' );
is(
$tx2->find_value('//*[contains-token(@class, "content")]'),
$tx->find_value('//*[contains-token(@class, "content")]'),
$tx2->find_value('//main'),
$tx->find_value('//main'),
'content of both urls is exactly the same'
);

Expand Down
7 changes: 3 additions & 4 deletions t/controller/release.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ test_psgi app, sub {
),
'contains link to "this" version'
);
my $latest = $tx->find_value('//*[contains-token(@class, "content")]');
my $latest = $tx->find_value('//main');
ok( $res = $cb->( GET $this ), "GET $this" );
my $tx_latest = tx($res);
is(
$latest,
$tx_latest->find_value('//*[contains-token(@class, "content")]'),
$tx_latest->find_value('//main'),
'content of both urls is exactly the same'
);

Expand Down Expand Up @@ -223,8 +223,7 @@ sub test_heading_order {
my $heading = 0;

# Boohoo... testing with XPATH :-(
my $xpath_prefix
= '//*[contains-token(@class, "content")]/div[contains-token(@class, "file-group")]';
my $xpath_prefix = '//main/div[contains-token(@class, "file-group")]';
$tx->ok(
"$xpath_prefix/h2",
sub {
Expand Down
4 changes: 2 additions & 2 deletions t/controller/source.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ test_psgi app, sub {
my @tests = (
{
uri => '/release/RJBS/Dist-Zilla-5.043/source/bin/dzil',
xpath => '//*[contains-token(@class, "content")]/pre/code/@class',
xpath => '//main/pre/code/@class',
expected => qr/\blanguage-perl\b/,
desc => 'has pre-block with expected syntax brush',
},
{
uri => '/release/ETHER/Moose-2.1005/source/README.md',
uri => '/release/ETHER/Moose-2.1005/view/README.md',
xpath => '//h1[@id="moose"]',
expected => qr/^Moose$/,
desc => 'markdown rendered as HTML',
Expand Down
Loading