]> iEval git - plack-app-gruntmaster.git/blobdiff - lib/Gruntmaster/Page/Pb.pm
Use Redis and reindent code
[plack-app-gruntmaster.git] / lib / Gruntmaster / Page / Pb.pm
index a2cccff504516d7c90969a00977c2be54a584ec8..170f03f42d2b020235fe1924c62a2f6f0a9db3d0 100644 (file)
@@ -13,11 +13,12 @@ use Fcntl qw/:flock/;
 use HTML::Template::Compiled;
 use IO::File;
 use POSIX qw/strftime/;
-use YAML::Any qw/LoadFile/;
 use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Data qw/problem_name problem_level problems/;
 
 my %templates = (
   en => <<'HTML',
+<tmpl_if levels>
 <h2>Beginner</h2>
 <ul>
 <tmpl_loop beginner><li><a href="<tmpl_var id>"><tmpl_var name></a>
@@ -33,15 +34,16 @@ my %templates = (
 <tmpl_loop medium><li><a href="<tmpl_var id>"><tmpl_var name></a>
 </tmpl_loop></ul>
 
-<h2>Advanced</h2>
+<h2>Hard</h2>
 <ul>
-<tmpl_loop advanced><li><a href="<tmpl_var id>"><tmpl_var name></a>
+<tmpl_loop hard><li><a href="<tmpl_var id>"><tmpl_var name></a>
 </tmpl_loop></ul>
 
-<h2>Hard</h2>
+<tmpl_else>
 <ul>
-<tmpl_loop hard><li><a href="<tmpl_var id>"><tmpl_var name></a>
+<tmpl_loop problems><li><a href="<tmpl_var id>"><tmpl_var name></a>
 </tmpl_loop></ul>
+</tmpl_if>
 HTML
 );
 
@@ -49,20 +51,20 @@ $templates{$_}  = header($_, TITLE) . $templates{$_} for keys %templates;
 $templates{$_} .= footer $_ for keys %templates;
 
 sub generate{
-  my ($path, $lang) = @_;
-  $path =~ s,/index\.html$,,;
-  my $template = $templates{$lang};
-  my $htc = HTML::Template::Compiled->new(scalarref => \$template);
-  IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
-  flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
-  my @problems = sort { $b->{name} cmp $a->{name} } map {
-       my $meta = LoadFile $_;
-       my $id = (m,^$path/(.*)/meta.yml$,)[0];
-       +{ id => $id, name => $meta->{name}, level => $meta->{level} } } <$path/*/meta.yml>;
-  for my $d(qw/beginner easy medium advanced hard/) {
-       $htc->param($d => [grep {$_->{level} eq $d} @problems]);
-  }
-  $htc->output
+       $_[0] =~ m,^(?:ct/([^/]+)/)?pb/index.html$,;
+       local $Gruntmaster::Data::contest = $1;
+
+       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
+       my @problems = sort { $b->{name} cmp $a->{name} } map +{
+               id    => $_,
+               name  => problem_name,
+               level => problem_level}, problems;
+       for my $d (qw/beginner easy medium advanced hard/) {
+               $htc->param($d => [grep {$_->{level} and $_->{level} eq $d} @problems]);
+       }
+       $htc->param(levels => grep { $_->{level} } @problems);
+       $htc->param(problems => \@problems);
+       $htc->output
 }
 
 1
This page took 0.027118 seconds and 4 git commands to generate.