X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FGruntmaster.pm;h=131b7542bcf99f7ded495590527392bcdf6dff5f;hb=fdbf59e5def9cbb4e1c0749f819ba8d946c37725;hp=60ab49f963b184207cdbf6e507c6e5b1b13bff52;hpb=7dc3247307f2e86af154dc449224f22ba8923c79;p=gruntmaster-page.git diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 60ab49f..131b754 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -7,8 +7,12 @@ use parent qw/Plack::Component/; no if $] >= 5.017011, warnings => 'experimental::smartmatch'; our $VERSION = '5999.000_001'; +use File::Slurp qw/read_file/; use HTTP::Negotiate qw/choose/; use Plack::Request; +use Gruntmaster::Page::Log; +use Gruntmaster::Page::Pb::Entry; +use Gruntmaster::Page::Generic; my %handlers; @@ -21,7 +25,21 @@ sub call { my @args; next unless @args = $r->path =~ m/^$re$/a; my $format = choose $obj->variants, $r->headers; - return $obj->generate($format, $env->{'psgix.logger'}, map { $_ // '' } @args); + return $obj->generate($format, $env, map { $_ // '' } @args); + } + + if ($r->method eq 'GET' || $r->method eq 'HEAD') { + my $article = $r->path eq '/' ? '/index' : $r->path; + $article = substr $article, 1; + $article =~ tr,/,_,; + my @variants = grep { !/\.title$/ } ; + if (@variants) { + my $lang = choose [ map { [$_, 1, 'text/html', undef, undef, $_, undef] } map { /\.(.+)$/ } @variants ], $r->headers; + my $content = read_file "a/$article.$lang"; + my $title = read_file "a/$article.$lang.title"; + my $html = Gruntmaster::Page::Base::header($lang, $title) . $content . Gruntmaster::Page::Base::footer($lang); + return [200, ['Content-Type' => 'text/html', 'Content-Language' => $lang, 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=300'], [$html] ] + } } [404, ['Content-Type' => 'text/plain'], ['Not found']] @@ -43,20 +61,24 @@ BEGIN{ my $word = qr,(\w+),a; my $ct = qr,(?:\/ct/$word)?,a; - get qr,/css/$word, => 'CSS'; - get qr,/js, => 'JS'; + get qr,/css/$word\.css, => 'CSS'; + get qr,/js\.js, => 'JS'; get qr,/ct/, => 'Ct'; - get qr,/ct/$word, => 'Ct::Entry'; + get qr,/ct/$word/, => 'Ct::Entry'; get qr,/us/, => 'Us'; get qr,/us/$word, => 'Us::Entry'; get qr,$ct/log/(\d+)?, => 'Log'; get qr,$ct/log/st, => 'St'; get qr,$ct/log/job/$word, => 'Log::Entry'; - get qr,$ct/submit, => 'Submit'; + get qr,$ct/log/src/$word\.$word, => 'Src'; get qr,$ct/pb/, => 'Pb'; get qr,$ct/pb/$word, => 'Pb::Entry'; + post qr,$ct/pb/$word/submit, => 'Submit'; + + post qr,/action/register, => 'Register'; + post qr,/action/passwd, => 'Passwd'; } 1;