-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.psgi
66 lines (59 loc) · 1.79 KB
/
app.psgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env perl
use strict;
use 5.10.1;
use lib qw(lib);
use Encode;
use Plack::Request;
use Plack::Response;
use Blawd::Storage;
use Blawd::Cmd::Container;
my $repo = '/Users/perigrin/dev/the-room/.git/';
my $app = sub {
my $req = Plack::Request->new(@_);
my $res = handle_request($req);
return $res->finalize;
};
sub handle_request {
my ($req) = @_;
my $storage = Blawd::Storage->create_storage($repo);
my $container = Blawd::Cmd::Container->new( storage => $storage );
my $blawd = $container->build_app();
my $renderer = $blawd->get_renderer('HTML');
my $res = Plack::Response->new( 200, { Content_Type => 'text/html' } );
given ( $req->path ) {
$_ =~ s|^/||;
when ('site.css') {
my $css = q[
html {
background-color: grey;
}
body {
width: 900px;
background: white;
border: 1px solid black;
padding-left: 25px;
padding-right: 25px;
}
];
$res->content_type('text/css');
$res->body( encode_utf8 $css);
return $res;
}
$_ =~ s|\..*?$||;
when ( $blawd->get_entry($_) ) {
my $entry = $blawd->get_entry($_);
$res->body( encode_utf8 $renderer->render_page($entry) );
return $res;
}
when ( $blawd->get_index($_) ) {
my $index = $blawd->get_index($_);
$res->body( encode_utf8 $renderer->render_page($index) );
return $res;
}
default {
my $index = $blawd->get_index('index');
$res->body( encode_utf8 $renderer->render_page($index) );
return $res;
}
}
}