1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package SugarTrail;
  2. use Dancer ':syntax';
  3. use SugarTrail::Repo;
  4. use helper;
  5. our $VERSION = '0.1';
  6. my $r = SugarTrail::Repo->new(
  7. root => config->{repo_root} // "t/data/strepo",
  8. vcs => config->{repo_vcs} // "git"
  9. );
  10. get qr|^/st/([^\?]*)(.*)$| => sub {
  11. my $p = params();
  12. &helper::dmup (ENV => \%ENV);
  13. &helper::dmup (params => scalar params);
  14. &helper::dmup (config => config);
  15. my ($stpath, $query) = splat;
  16. my $format = params->{__format} // 'plain';
  17. header('Content-Type' => (
  18. $format eq 'html' ? 'text/html' : 'text/plain'
  19. ));
  20. my $m = $r->load_master( source => "/$stpath.stm" )
  21. or return template 'not_found';
  22. my $s = $m->generate_slave(scalar params);
  23. template 'st', {
  24. st_headers => $s->head(),
  25. content => $s->body(),
  26. warnings => $s->warnings()
  27. }, { layout => $format };
  28. };
  29. get '/' => sub {
  30. template 'index';
  31. };
  32. true;