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