X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FPb.pm;h=18b47bf894710cb8449ba68910592c7a1a266004;hb=4aa8ba862bf3a79362df73c3d1e8707e8135af23;hp=a3902c23676ed296a9e1173105bd7fec3a0d2780;hpb=5bbf0128012c09c78462ee49b874f968385b0978;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Pb.pm b/lib/Gruntmaster/Page/Pb.pm index a3902c2..18b47bf 100644 --- a/lib/Gruntmaster/Page/Pb.pm +++ b/lib/Gruntmaster/Page/Pb.pm @@ -7,57 +7,62 @@ use parent qw/Exporter/; our @EXPORT_OK = qw/generate/; our $VERSION = '0.001'; -use constant TITLE => 'Problems'; - 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::Page::Common qw/cook_templates reload_templates/; +use Gruntmaster::Data qw/problem_name problem_level problems/; -my %templates = ( +my %orig_templates = ( en => <<'HTML', +

Beginner

Easy

Medium

Hard

+ + + +
HTML ); -$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; -$templates{$_} .= footer $_ for keys %templates; +my %templates = cook_templates %orig_templates, pb => 'Problems'; 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 + %templates = cook_templates %orig_templates, pb => 'Problems' if reload_templates; + $_[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