]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Pb.pm
Add user list and user pages
[gruntmaster-page.git] / lib / Gruntmaster / Page / Pb.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page::Pb;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
42546e6c
MG
10use Fcntl qw/:flock/;
11use HTML::Template::Compiled;
12use IO::File;
13use POSIX qw/strftime/;
2b0036ac 14use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
cd9af27e 15use Gruntmaster::Data qw/problem_name problem_level problems/;
42546e6c 16
2b0036ac 17my %orig_templates = (
42546e6c 18 en => <<'HTML',
96f80a63 19<tmpl_if levels>
9be91908 20<h2>Beginner</h2>
42546e6c 21<ul>
3da9c3c2 22<tmpl_loop beginner><li><a href="<tmpl_var id>.var"><tmpl_var name></a>
9be91908
MG
23</tmpl_loop></ul>
24
25<h2>Easy</h2>
26<ul>
3da9c3c2 27<tmpl_loop easy><li><a href="<tmpl_var id>.var"><tmpl_var name></a>
9be91908
MG
28</tmpl_loop></ul>
29
30<h2>Medium</h2>
31<ul>
3da9c3c2 32<tmpl_loop medium><li><a href="<tmpl_var id>.var"><tmpl_var name></a>
9be91908
MG
33</tmpl_loop></ul>
34
9be91908
MG
35<h2>Hard</h2>
36<ul>
3da9c3c2 37<tmpl_loop hard><li><a href="<tmpl_var id>.var"><tmpl_var name></a>
42546e6c 38</tmpl_loop></ul>
96f80a63
MG
39
40<tmpl_else>
41<ul>
3da9c3c2 42<tmpl_loop problems><li><a href="<tmpl_var id>.var"><tmpl_var name></a>
96f80a63
MG
43</tmpl_loop></ul>
44</tmpl_if>
42546e6c
MG
45HTML
46);
47
2b0036ac 48my %templates = cook_templates %orig_templates, pb => 'Problems';
42546e6c
MG
49
50sub generate{
2b0036ac 51 %templates = cook_templates %orig_templates, pb => 'Problems' if reload_templates;
cd9af27e
MG
52 $_[0] =~ m,^(?:ct/([^/]+)/)?pb/index.html$,;
53 local $Gruntmaster::Data::contest = $1;
54
55 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
56 my @problems = sort { $b->{name} cmp $a->{name} } map +{
57 id => $_,
58 name => problem_name,
59 level => problem_level}, problems;
60 for my $d (qw/beginner easy medium advanced hard/) {
61 $htc->param($d => [grep {$_->{level} and $_->{level} eq $d} @problems]);
62 }
63 $htc->param(levels => grep { $_->{level} } @problems);
64 $htc->param(problems => \@problems);
65 $htc->output
42546e6c
MG
66}
67
681
This page took 0.026409 seconds and 4 git commands to generate.