package SugarTrail; use Dancer2 ':syntax'; use strict; use warnings; use SugarTrail::Repo; use Template; use helper; our $VERSION = '0.1'; my $r = SugarTrail::Repo->new( root => config->{repo_root} // "t/data/strepo", vcs => config->{repo_vcs} // "git" ); get qr|^/st/([^\?]*)(.*)$| => sub { my $params = request->params('query'); &helper::dmup (ENV => \%ENV); &helper::dmup (real_params => $params); my ($stpath, $query) = splat; my $format = $params->{__format} // 'plain'; header('Content-Type' => ( $format eq 'html' ? 'text/html' : 'text/plain' )); my $m = $r->load_master( source => "/$stpath.stm" ) or return template 'not_found'; my $s = $m->generate_slave($params); template 'st', { st_headers => $s->head(), content => $s->body(), warnings => $s->warnings() }, { layout => $format }; }; get '/' => sub { template 'index'; }; true;