]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Pb.pm
Move header / footer to a separate module and update MANIFEST
[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',
21<ul>
22<tmpl_loop problems><li><a href="<tmpl_var id>"><tmpl_var name></a>
23</tmpl_loop></ul>
24HTML
25);
26
27$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
28$templates{$_} .= footer $_ for keys %templates;
29
30sub generate{
fe78f0c1
MG
31 my ($path, $lang) = @_;
32 $path =~ s,/index\.html$,,;
33 my $template = $templates{$lang};
42546e6c 34 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
fe78f0c1
MG
35 IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
36 flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
42546e6c
MG
37 my @problems = sort { $b->{name} cmp $a->{name} } map {
38 my $meta = LoadFile $_;
fe78f0c1
MG
39 my $id = (m,^$path/(.*)/meta.yml$,)[0];
40 +{ id => $id, name => $meta->{name} } } <$path/*/meta.yml>;
42546e6c
MG
41 $htc->param(problems => \@problems);
42 $htc->output
43}
44
451
This page took 0.021013 seconds and 4 git commands to generate.