|
@@ -3,33 +3,42 @@ use Dancer ':syntax';
|
3
|
3
|
|
4
|
4
|
use SugarTrail::Repo;
|
5
|
5
|
use helper;
|
6
|
|
-use URL::Encode qw/ url_decode /;
|
7
|
6
|
|
8
|
7
|
our $VERSION = '0.1';
|
9
|
8
|
|
10
|
|
-my $repo_root = '/srv/strail/strepo';
|
11
|
|
-my $repo_vcs = 'git';
|
|
9
|
+my $r = SugarTrail::Repo->new(
|
|
10
|
+ root => config->{repo_root},
|
|
11
|
+ vcs => config->{repo_vcs}
|
|
12
|
+);
|
12
|
13
|
|
13
|
|
-my $repo = SugarTrail::Repo->new( root => $repo_root, vcs=> $repo_vcs );
|
14
|
14
|
|
|
15
|
+get qr|^/st/([^\?]*)(.*)$| => sub {
|
15
|
16
|
|
|
17
|
+ my $p = params();
|
16
|
18
|
|
17
|
|
-get qr{(/[^\?]*)} => sub {
|
|
19
|
+ &helper::dmup (ENV => \%ENV);
|
|
20
|
+ &helper::dmup (params => scalar params);
|
|
21
|
+ &helper::dmup (config => config);
|
18
|
22
|
|
19
|
|
- my ($stm) = split '\?', $ENV{REQUEST_URI}, 2;
|
20
|
|
- $stm = url_decode($stm);
|
|
23
|
+ my ($stpath, $query) = splat;
|
|
24
|
+ my $format = params->{__format} // 'plain';
|
|
25
|
+ header('Content-Type' => (
|
|
26
|
+ $format eq 'html' ? 'text/html' : 'text/plain'
|
|
27
|
+ ));
|
21
|
28
|
|
22
|
|
- my $m = $repo->load_stm( stm => $stm . '.stm' );
|
23
|
|
- unless ($m) {
|
24
|
|
- return template 'not_found';
|
25
|
|
- }
|
|
29
|
+ my $m = $r->load_stm( stm => "/$stpath.stm" )
|
|
30
|
+ or return template 'not_found';
|
|
31
|
+ my $s = $m->generate_slave(scalar params);
|
26
|
32
|
|
27
|
|
- my $params = params();
|
28
|
|
- my $s = $m->generate_slave($params);
|
29
|
|
-
|
30
|
|
- &helper::dmup(params=>$params);
|
|
33
|
+ template 'st', {
|
|
34
|
+ st_headers => $s->head(),
|
|
35
|
+ content => $s->body(),
|
|
36
|
+ warnings => $s->warnings()
|
|
37
|
+ }, { layout => $format };
|
|
38
|
+};
|
31
|
39
|
|
32
|
|
- return '<pre>' . $s->source . '</pre>';
|
|
40
|
+get '/' => sub {
|
|
41
|
+ template 'index';
|
33
|
42
|
};
|
34
|
43
|
|
35
|
44
|
true;
|