]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Ct/Entry.pm
Add contest/multispace support
[gruntmaster-page.git] / lib / Gruntmaster / Page / Ct / Entry.pm
CommitLineData
fe78f0c1
MG
1package Gruntmaster::Page::Ct::Entry;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
10use Fcntl qw/:flock/;
11use HTML::Template::Compiled;
12use IO::File;
13use POSIX qw/strftime/;
14use YAML::Any qw/LoadFile/;
15use File::Basename qw/fileparse/;
16use File::Slurp qw/slurp/;
17use Gruntmaster::Page qw/header footer/;
18
19use constant TITLE => '<tmpl_var name>';
20
21my %templates = (
22 en => <<'HTML',
23Contest start time: <tmpl_var start><br>
24Contest 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>
29HTML
30);
31
32$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
33$templates{$_} .= footer $_ for keys %templates;
34
35sub 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
511
This page took 0.018043 seconds and 4 git commands to generate.