our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Account';
-
use HTML::Template::Compiled;
-use Gruntmaster::Page::Common qw/header footer patch_templates/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<div id="result"></div>
HTML
);
-patch_templates %templates, 'account';
-
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, account => 'Account';
sub generate{
+ %templates = cook_templates %orig_templates, account => 'Account' if reload_templates;
HTML::Template::Compiled->new(scalarref => \$templates{$_[1]})->output
}
use strict;
use warnings;
use parent qw/Exporter/;
-our @EXPORT_OK = qw/header footer patch_templates/;
+our @EXPORT_OK = qw/header footer cook_templates reload_templates/;
use File::Slurp qw/read_file/;
-my %header_templates = (
+my %orig_header_templates = (
en => <<'HTML',
<!DOCTYPE html>
<title>TITLE_GOES_HERE</title>
HTML
);
-my %footer_templates = (
+my %orig_footer_templates = (
en => <<'HTML',
<footer>
HTML
);
-sub patch_templates (\%$){
+sub patch_templates {
my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return;
my ($templates, $name) = @_;
+ my %out = %$templates;
for (<$root/$name*>) {
m/\.(.+)$/;
- $templates->{$1} = read_file $_
+ $out{$1} = read_file $_
}
+
+ %out
}
-patch_templates %header_templates, 'header';
-patch_templates %footer_templates, 'footer';
+my %header_templates = patch_templates \%orig_header_templates, 'header';
+my %footer_templates = patch_templates \%orig_footer_templates, 'footer';
+
+sub reload_templates () { $ENV{GRUNTMASTER_RELOAD_TEMPLATES} }
sub header{
my ($language, $title) = @_;
+ %header_templates = patch_templates \%orig_header_templates, 'header' if reload_templates;
$header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
}
sub footer{
+ %footer_templates = patch_templates \%orig_footer_templates, 'footer' if reload_templates;
$footer_templates{$_[0]};
}
+sub cook_templates (\%@) {
+ my ($templates, $name, $title) = @_;
+
+ my %out = patch_templates $templates, $name;
+ $out{$_} = header ($_, $title) . $out{$_} for keys %out;
+ $out{$_} .= footer $_ for keys %out;
+
+ %out
+}
+
1;
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Contests';
-
use HTML::Template::Compiled;
use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
use Gruntmaster::Data qw/contest_name contest_start contest_end contest_owner/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<tmpl_if running>
<h1>Running contests</h1>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, ct => 'Contests';
sub generate{
+ %templates = cook_templates %orig_templates, ct => 'Contests' if reload_template;
my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
my (@running, @pending, @finished);
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => '<tmpl_var name>';
-
use HTML::Template::Compiled;
use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
use Gruntmaster::Data qw/contest_name contest_start contest_end/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
Contest start time: <tmpl_var start><br>
Contest end time: <tmpl_var end><p>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, ct_entry => '<tmpl_var name>';
sub generate{
+ %templates = cook_templates %orig_templates, ct_entry => '<tmpl_var name>' if reload_templates;
my ($path, $lang) = @_;
$path = ($path =~ m,ct/(.*)/index,)[0];
my $template = $templates{$lang};
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Gruntmaster 6000';
-
use HTML::Template::Compiled;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, index => 'Gruntmaster 6000';
sub generate{
+ %templates = cook_templates %orig_templates, index => 'Gruntmaster 6000' if reload_templates;
HTML::Template::Compiled->new(scalarref => \$templates{$_[1]})->output
}
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Learn';
-
use HTML::Template::Compiled;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
Install interactive-perl-tutorial from your nearest CPAN mirror. Run <code>cpan App::InteractivePerlTutorial</code>.
<p>You can also get the source from <a href="http://git.ieval.ro/?p=app-interactiveperltutorial.git">git.ieval.ro</a>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, learn => 'Learn';
sub generate{
+ %templates = cook_templates %orig_templates, learn => 'Learn' if reload_templates;
HTML::Template::Compiled->new(scalarref => \$templates{$_[1]})->output;
}
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Job log';
use constant PAGE_SIZE => 10;
use constant FORMAT_EXTENSION => {
use HTML::Template::Compiled;
use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
use Gruntmaster::Data qw/jobcard job_date job_extension job_filesize problem_name job_private job_problem job_result job_result_text job_user/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<table border>
<thead>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, log => 'Job log';
sub generate{
+ %templates = cook_templates %orig_templates, log => 'Job log' if reload_templates;
$_[0] =~ m,^(?:ct/([^/]+)/)?log/(\w+)\.html$,;
local $Gruntmaster::Data::contest = $1;
my $pages = jobcard / PAGE_SIZE;
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Job <tmpl_var id>';
-
use HTML::Template::Compiled;
use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
use Gruntmaster::Data qw/job_results/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<table border>
<thead>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, log_entry => 'Job <tmpl_var id>';
sub generate{
+ %templates = cook_templates %orig_templates, log_entry => 'Job <tmpl_var id>' if reload_templates;
$_[0] =~ m,^(?:ct/([^/]+)/)?log/job/([^/]+)\.html$,;
local $Gruntmaster::Data::contest = $1;
my $id = $2;
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Problems';
-
use Fcntl qw/:flock/;
use HTML::Template::Compiled;
use IO::File;
use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
use Gruntmaster::Data qw/problem_name problem_level problems/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<tmpl_if levels>
<h2>Beginner</h2>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, pb => 'Problems';
sub generate{
+ %templates = cook_templates %orig_templates, pb => 'Problems' if reload_templates;
$_[0] =~ m,^(?:ct/([^/]+)/)?pb/index.html$,;
local $Gruntmaster::Data::contest = $1;
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use Fcntl qw/:flock/;
use HTML::Template::Compiled;
-use IO::File;
use POSIX qw/strftime/;
-use File::Basename qw/fileparse/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
use Gruntmaster::Data qw/contest_start contest_end problem_name problem_statement/;
use constant FORMATS => [qw/CPP/];
-use constant TITLE => '<tmpl_var name>';
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<tmpl_var statement>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, pb_entry => '<tmpl_var name>';
sub generate{
+ %templates = cook_templates %orig_templates, pb_entry => '<tmpl_var name>' if reload_templates;
$_[0] =~ m,(?:ct/([^/])+/)?pb/(\w+)\.html$,;
my ($contest, $id) = ($1, $2);
our @EXPORT_OK = qw/generate/;
our $VERSION = '0.001';
-use constant TITLE => 'Standings';
-
use HTML::Template::Compiled;
use List::Util qw/sum/;
use POSIX qw/strftime/;
-use Gruntmaster::Page::Common qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
use Gruntmaster::Data qw/problems jobcard job_result_text job_result job_problem job_user/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<table border>
<thead>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, st => 'Standings';
sub generate{
+ %templates = cook_templates %orig_templates, st => 'Standings' if reload_templates;
local $Gruntmaster::Data::contest = ($_[0] =~ m,^ct/([^/]+)/,)[0];
my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
our $VERSION = '0.001';
use constant FORMATS => [qw/CPP/];
-use constant TITLE => 'Submit job';
-use Fcntl qw/:flock/;
use HTML::Template::Compiled;
-use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page::Common qw/header footer/;
-use Gruntmaster::Data qw//;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
+use Gruntmaster::Data qw/problem_name problems/;
-my %templates = (
+my %orig_templates = (
en => <<'HTML',
<form action="https://gm.ieval.ro/action/submit" method="POST" enctype="multipart/form-data">
<label>Problem:<br>
HTML
);
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+my %templates = cook_templates %orig_templates, submit => 'Submit job';
sub generate{
+ %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);