App-mookview

 view release on metacpan or  search on metacpan

lib/App/mookview.pm  view on Meta::CPAN

    my $self = shift;
    return sub {
        my $req  = Plack::Request->new(shift);
        my $path = $req->path_info;
        return $self->return_markdown($path) if $path eq '/';
        return $self->return_css($path) if $path =~ m!^/css/.+!;
        Plack::App::Directory->new->to_app->($req->env);        
    };
}

sub return_404 {
    return [404, [ 'Content-Type' => 'text/plain' ], ['Not Found'] ];
}

sub return_css {
    my ($self, $path) = @_;
    return $self->return_404 unless $path;
    my ($name) = $path =~ m!/([^/]+?)$!;
    my $local_path = $self->local_or_share_path([qw/share static css/, $name]);
    return $self->return_404 unless $local_path;
    my $css = $local_path->slurp();
    return [200, [ 'Content-Type' => 'text/css', 'Content-Length' => length $css ], [ encode_utf8($css) ] ];
}

sub return_markdown {
    my ($self, $path) = @_;
    my $text = $self->{file_path}->slurp_utf8();
    my $length = format_number(length $text);
    $text = $self->filter_markdown($text);
    my $stock = '';   my $page = 1;  my $content = '';

t/01_basic.t  view on Meta::CPAN

use FindBin;
use Test::More;
use App::mookview;

my $app = App::mookview->new("$FindBin::Bin/../README.md");
isa_ok $app, 'App::mookview';

my $path = $app->local_or_share_path([qw/share/]);
ok $path;

my $not_found_response = $app->return_404();
ok $not_found_response;

my $css_response = $app->return_css('/css/screen.css');
ok $css_response;

my $code_block = $app->filter_markdown(<<'EOF');
```
my $foo = Foo->new();
$foo->bar();
```



( run in 2.596 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )