]> iEval git - plack-app-gruntmaster.git/blobdiff - lib/Gruntmaster/Page/Submit.pm
Centralize template cooking and introduce reloadable templates
[plack-app-gruntmaster.git] / lib / Gruntmaster / Page / Submit.pm
index e6f44deebfcee2e889a78cd2f5d613b5ffec5da8..7e4d1634d27ca6ef328cc530b4e095db02c4a976 100644 (file)
@@ -8,16 +8,13 @@ our @EXPORT_OK = qw/generate/;
 our $VERSION = '0.001';
 
 use constant FORMATS => [qw/CPP/];
-use constant TITLE => 'Submit job';
 
-use Fcntl qw/:flock/;
 use HTML::Template::Compiled;
-use IO::File;
-use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
+use Gruntmaster::Data qw/problem_name problems/;
 
-my %templates = (
-  en => <<'HTML',
+my %orig_templates = (
+       en => <<'HTML',
 <form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data">
 <label>Problem:<br>
 <select name="problem" required>
@@ -36,21 +33,16 @@ my %templates = (
 HTML
 );
 
-$templates{$_}  = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, submit => 'Submit job';
 
 sub generate{
-  my $template = $templates{$_[1]};
-  my $htc = HTML::Template::Compiled->new(scalarref => \$template);
-  IO::File->new('>meta.yml')->close unless -f 'meta.yml';
-  flock my $metafh = IO::File->new('<meta.yml'), LOCK_SH;
-  my @problems = map {
-       my $meta = LoadFile $_;
-       my $id = (m,^pb/(.*)/meta.yml$,)[0];
-       +{ id => $id, name => $meta->{name} } } <pb/*/meta.yml>;
-  $htc->param(problems => \@problems);
-  $htc->param(formats => FORMATS);
-  $htc->output
+       %templates = cook_templates %orig_templates, submit => 'Submit job' if reload_templates;
+
+       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
+       my @problems = map +{ id => $_, name => problem_name }, problems;
+       $htc->param(problems => \@problems);
+       $htc->param(formats => FORMATS);
+       $htc->output
 }
 
 1
This page took 0.017498 seconds and 4 git commands to generate.