]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Pb.pm
Add standings
[gruntmaster-page.git] / lib / Gruntmaster / Page / Pb.pm
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/;
16 use YAML::Any qw/LoadFile/;
17 use Gruntmaster::Page::Common qw/header footer/;
18
19 my %templates = (
20 en => <<'HTML',
21 <h2>Beginner</h2>
22 <ul>
23 <tmpl_loop beginner><li><a href="<tmpl_var id>"><tmpl_var name></a>
24 </tmpl_loop></ul>
25
26 <h2>Easy</h2>
27 <ul>
28 <tmpl_loop easy><li><a href="<tmpl_var id>"><tmpl_var name></a>
29 </tmpl_loop></ul>
30
31 <h2>Medium</h2>
32 <ul>
33 <tmpl_loop medium><li><a href="<tmpl_var id>"><tmpl_var name></a>
34 </tmpl_loop></ul>
35
36 <h2>Hard</h2>
37 <ul>
38 <tmpl_loop hard><li><a href="<tmpl_var id>"><tmpl_var name></a>
39 </tmpl_loop></ul>
40 HTML
41 );
42
43 $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
44 $templates{$_} .= footer $_ for keys %templates;
45
46 sub generate{
47 my ($path, $lang) = @_;
48 $path =~ s,/index\.html$,,;
49 my $template = $templates{$lang};
50 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
51 IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
52 flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
53 my @problems = sort { $b->{name} cmp $a->{name} } map {
54 my $meta = LoadFile $_;
55 my $id = (m,^$path/(.*)/meta.yml$,)[0];
56 +{ id => $id, name => $meta->{name}, level => $meta->{level} } } <$path/*/meta.yml>;
57 for my $d(qw/beginner easy medium advanced hard/) {
58 $htc->param($d => [grep {$_->{level} eq $d} @problems]);
59 }
60 $htc->output
61 }
62
63 1
This page took 0.044049 seconds and 5 git commands to generate.