]> iEval git - plack-app-gruntmaster.git/blobdiff - lib/Gruntmaster/Page/Pb.pm
Split problem list into levels
[plack-app-gruntmaster.git] / lib / Gruntmaster / Page / Pb.pm
index efe7d26a42d986dbde5dc51b9add82aca7b91c24..a2cccff504516d7c90969a00977c2be54a584ec8 100644 (file)
@@ -14,12 +14,33 @@ use HTML::Template::Compiled;
 use IO::File;
 use POSIX qw/strftime/;
 use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page qw/header footer/;
+use Gruntmaster::Page::Common qw/header footer/;
 
 my %templates = (
   en => <<'HTML',
+<h2>Beginner</h2>
 <ul>
-<tmpl_loop problems><li><a href="<tmpl_var id>"><tmpl_var name></a>
+<tmpl_loop beginner><li><a href="<tmpl_var id>"><tmpl_var name></a>
+</tmpl_loop></ul>
+
+<h2>Easy</h2>
+<ul>
+<tmpl_loop easy><li><a href="<tmpl_var id>"><tmpl_var name></a>
+</tmpl_loop></ul>
+
+<h2>Medium</h2>
+<ul>
+<tmpl_loop medium><li><a href="<tmpl_var id>"><tmpl_var name></a>
+</tmpl_loop></ul>
+
+<h2>Advanced</h2>
+<ul>
+<tmpl_loop advanced><li><a href="<tmpl_var id>"><tmpl_var name></a>
+</tmpl_loop></ul>
+
+<h2>Hard</h2>
+<ul>
+<tmpl_loop hard><li><a href="<tmpl_var id>"><tmpl_var name></a>
 </tmpl_loop></ul>
 HTML
 );
@@ -28,15 +49,19 @@ $templates{$_}  = header($_, TITLE) . $templates{$_} for keys %templates;
 $templates{$_} .= footer $_ for keys %templates;
 
 sub generate{
-  my $template = $templates{$_[1]};
+  my ($path, $lang) = @_;
+  $path =~ s,/index\.html$,,;
+  my $template = $templates{$lang};
   my $htc = HTML::Template::Compiled->new(scalarref => \$template);
-  IO::File->new('>pb/meta.yml')->close unless -f 'pb/meta.yml';
-  flock my $metafh = IO::File->new('<pb/meta.yml'), LOCK_SH;
+  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,^pb/(.*)/meta.yml$,)[0];
-       +{ id => $id, name => $meta->{name} } } <pb/*/meta.yml>;
-  $htc->param(problems => \@problems);
+       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
 }
 
This page took 0.023536 seconds and 4 git commands to generate.