]>
Commit | Line | Data |
---|---|---|
42546e6c MG |
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 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 qw/header footer/; | |
18 | ||
19 | use constant FORMATS => [qw/CPP/]; | |
20 | use constant TITLE => '<tmpl_var name>'; | |
21 | ||
22 | my %templates = ( | |
23 | en => <<'HTML', | |
24 | <tmpl_var statement> | |
25 | ||
26 | <h1>Submit solution</h1> | |
27 | <form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data"> | |
28 | <input type="hidden" name="problem" value="<tmpl_var id>"> | |
29 | <label>File: <input name="prog" required type="file"></label> | |
30 | ||
31 | <label>File format: <select name="prog_format" required> | |
32 | <tmpl_loop formats><option value="<tmpl_var _>"><tmpl_var _></option> | |
33 | </tmpl_loop></select></label> | |
34 | ||
35 | <input type="submit" value="Submit job"> | |
36 | HTML | |
37 | ); | |
38 | ||
39 | $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; | |
40 | $templates{$_} .= footer $_ for keys %templates; | |
41 | ||
42 | sub generate{ | |
43 | my ($path, $lang) = @_; | |
44 | $path = ($path =~ m,pb/(.*)/index,)[0]; | |
45 | my $template = $templates{$_[1]}; | |
46 | my $htc = HTML::Template::Compiled->new(scalarref => \$template); | |
47 | flock my $metafh = IO::File->new("<pb/$path/meta.yml"), LOCK_SH; | |
48 | my $meta = LoadFile "pb/$path/meta.yml"; | |
49 | ||
50 | $htc->param(formats => FORMATS); | |
51 | $htc->param(id => $path); | |
52 | $htc->param(name => $meta->{name}); | |
53 | $htc->param(statement => scalar slurp "pb/$path/statement.$lang"); | |
54 | $htc->output | |
55 | } | |
56 | ||
57 | 1 |