]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Pb.pm
Close form element in Pb::Entry
[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
10use constant TITLE => 'Problems';
11
12use Fcntl qw/:flock/;
13use HTML::Template::Compiled;
14use IO::File;
15use POSIX qw/strftime/;
16use YAML::Any qw/LoadFile/;
832cb45e 17use Gruntmaster::Page::Common qw/header footer/;
42546e6c
MG
18
19my %templates = (
20 en => <<'HTML',
96f80a63 21<tmpl_if levels>
9be91908 22<h2>Beginner</h2>
42546e6c 23<ul>
9be91908
MG
24<tmpl_loop beginner><li><a href="<tmpl_var id>"><tmpl_var name></a>
25</tmpl_loop></ul>
26
27<h2>Easy</h2>
28<ul>
29<tmpl_loop easy><li><a href="<tmpl_var id>"><tmpl_var name></a>
30</tmpl_loop></ul>
31
32<h2>Medium</h2>
33<ul>
34<tmpl_loop medium><li><a href="<tmpl_var id>"><tmpl_var name></a>
35</tmpl_loop></ul>
36
9be91908
MG
37<h2>Hard</h2>
38<ul>
39<tmpl_loop hard><li><a href="<tmpl_var id>"><tmpl_var name></a>
42546e6c 40</tmpl_loop></ul>
96f80a63
MG
41
42<tmpl_else>
43<ul>
44<tmpl_loop problems><li><a href="<tmpl_var id>"><tmpl_var name></a>
45</tmpl_loop></ul>
46</tmpl_if>
42546e6c
MG
47HTML
48);
49
50$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
51$templates{$_} .= footer $_ for keys %templates;
52
53sub generate{
fe78f0c1
MG
54 my ($path, $lang) = @_;
55 $path =~ s,/index\.html$,,;
56 my $template = $templates{$lang};
42546e6c 57 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
fe78f0c1
MG
58 IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
59 flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
42546e6c
MG
60 my @problems = sort { $b->{name} cmp $a->{name} } map {
61 my $meta = LoadFile $_;
fe78f0c1 62 my $id = (m,^$path/(.*)/meta.yml$,)[0];
9be91908
MG
63 +{ id => $id, name => $meta->{name}, level => $meta->{level} } } <$path/*/meta.yml>;
64 for my $d(qw/beginner easy medium advanced hard/) {
96f80a63 65 $htc->param($d => [grep {$_->{level} and $_->{level} eq $d} @problems]);
9be91908 66 }
96f80a63
MG
67 $htc->param(levels => grep { $_->{level} } @problems);
68 $htc->param(problems => \@problems);
42546e6c
MG
69 $htc->output
70}
71
721
This page took 0.020899 seconds and 4 git commands to generate.