]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Ct/Entry.pm
Move header / footer to a separate module and update MANIFEST
[gruntmaster-page.git] / lib / Gruntmaster / Page / Ct / Entry.pm
1 package Gruntmaster::Page::Ct::Entry;
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 Fcntl qw/:flock/;
11 use HTML::Template::Compiled;
12 use IO::File;
13 use POSIX qw/strftime/;
14 use YAML::Any qw/LoadFile/;
15 use File::Basename qw/fileparse/;
16 use File::Slurp qw/slurp/;
17 use Gruntmaster::Page::Common qw/header footer/;
18
19 use constant TITLE => '<tmpl_var name>';
20
21 my %templates = (
22 en => <<'HTML',
23 Contest start time: <tmpl_var start><br>
24 Contest end time: <tmpl_var end><p>
25
26 <tmpl_if started><a href="pb/">Problems</a><br>
27 <a href="log/">Job log</a><br>
28 <a href="st/">Standings</a></tmpl_if>
29 HTML
30 );
31
32 $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
33 $templates{$_} .= footer $_ for keys %templates;
34
35 sub generate{
36 my ($path, $lang) = @_;
37 $path = ($path =~ m,ct/(.*)/index,)[0];
38 my $template = $templates{$lang};
39 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
40 flock my $metafh = IO::File->new("<ct/$path/meta.yml"), LOCK_SH;
41 my $meta = LoadFile "ct/$path/meta.yml";
42
43 $htc->param(id => $path);
44 $htc->param(name => $meta->{name});
45 $htc->param(start => strftime '%c', localtime $meta->{start});
46 $htc->param(end => strftime '%c', localtime $meta->{end});
47 $htc->param(started => time >= $meta->{start});
48 $htc->output
49 }
50
51 1
This page took 0.039305 seconds and 5 git commands to generate.