]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Pb.pm
Add example test suite
[gruntmaster-page.git] / lib / Gruntmaster / Page / Pb.pm
index efe7d26a42d986dbde5dc51b9add82aca7b91c24..ba78869c5f763fbafcc40a1c187379117f37df1a 100644 (file)
@@ -3,41 +3,25 @@ package Gruntmaster::Page::Pb;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base pb => 'Problems';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use constant TITLE => 'Problems';
+sub _generate{
+       my ($self, $htc, $lang, $env, $ct) = @_;
+       debug $env => "language is '$lang' and contest is '$ct'";
+       local $Gruntmaster::Data::contest = $ct if $ct;
 
-use Fcntl qw/:flock/;
-use HTML::Template::Compiled;
-use IO::File;
-use POSIX qw/strftime/;
-use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page qw/header footer/;
+       my @problems = sort { $b->{name} cmp $a->{name} } map +{
+               id    => $_,
+               name  => problem_name,
+               level => problem_level}, problems;
 
-my %templates = (
-  en => <<'HTML',
-<ul>
-<tmpl_loop problems><li><a href="<tmpl_var id>"><tmpl_var name></a>
-</tmpl_loop></ul>
-HTML
-);
-
-$templates{$_}  = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
-
-sub generate{
-  my $template = $templates{$_[1]};
-  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;
-  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);
-  $htc->output
+       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);
 }
 
 1
This page took 0.016433 seconds and 4 git commands to generate.