X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FPb.pm;h=8e4a40886e26d329c6a113d84e97ed209ecd6f19;hb=0b282e58119cc0dbce678ef56eab20cc352557b5;hp=617112a539c99a73a3361e8a4e429914f7078754;hpb=832cb45e325364ca1de645a2256efa69284fcf06;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Pb.pm b/lib/Gruntmaster/Page/Pb.pm index 617112a..8e4a408 100644 --- a/lib/Gruntmaster/Page/Pb.pm +++ b/lib/Gruntmaster/Page/Pb.pm @@ -3,43 +3,57 @@ 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'; +use constant TEMPLATES => { + en => <<'HTML', + +

Beginner

+ + +

Easy

+ + +

Medium

+ -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/; +

Hard

+ -my %templates = ( - en => <<'HTML', + +
HTML -); - -$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} } } <$path/*/meta.yml>; - $htc->param(problems => \@problems); - $htc->output +}; + +sub _generate{ + my ($self, $htc, $path, $lang) = @_; + + $path =~ m,^(?:ct/([^/]+)/)?pb/index.html$,; + local $Gruntmaster::Data::contest = $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); } 1