]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Pb/Entry.pm
Centralize template cooking and introduce reloadable templates
[gruntmaster-page.git] / lib / Gruntmaster / Page / Pb / Entry.pm
1 package Gruntmaster::Page::Pb::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 HTML::Template::Compiled;
11 use POSIX qw/strftime/;
12 use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
13 use Gruntmaster::Data qw/contest_start contest_end problem_name problem_statement/;
14
15 use constant FORMATS => [qw/CPP/];
16
17 my %orig_templates = (
18 en => <<'HTML',
19 <tmpl_var statement>
20
21 <tmpl_if cansubmit>
22 <h1>Submit solution</h1>
23 <form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data">
24 <input type="hidden" name="problem" value="<tmpl_var id>">
25 <tmpl_if_defined contest><input type="hidden" name="contest" value="<tmpl_var contest>"></tmpl_if_defined>
26 <label>File: <input name="prog" required type="file"></label>
27
28 <label>File format: <select name="prog_format" required>
29 <tmpl_loop formats><option value="<tmpl_var _>"><tmpl_var _></option>
30 </tmpl_loop></select></label>
31
32 <input type="submit" value="Submit job">
33 </form>
34 </tmpl_if>
35 HTML
36 );
37
38 my %templates = cook_templates %orig_templates, pb_entry => '<tmpl_var name>';
39
40 sub generate{
41 %templates = cook_templates %orig_templates, pb_entry => '<tmpl_var name>' if reload_templates;
42 $_[0] =~ m,(?:ct/([^/])+/)?pb/(\w+)\.html$,;
43
44 my ($contest, $id) = ($1, $2);
45 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
46
47 $htc->param(cansubmit => 1);
48 if (defined $contest) {
49 $htc->param(cansubmit => time >= contest_start $contest && time <= contest_end $contest);
50 $htc->param(contest => $contest);
51 }
52 $htc->param(formats => FORMATS);
53 $htc->param(id => $id);
54 local $Gruntmaster::Data::contest = $contest if $contest;
55 $htc->param(name => problem_name $id);
56 $htc->param(statement => problem_statement $id);
57 $htc->output
58 }
59
60 1
This page took 0.0488 seconds and 5 git commands to generate.