]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Ct/Entry.pm
Centralize template cooking and introduce reloadable templates
[gruntmaster-page.git] / lib / Gruntmaster / Page / Ct / Entry.pm
index 725e3e9ef9aaf222dfb3973612142fe5764d67e4..bba2991c6e8a13d5fbeebbd473cbd440cb2806a4 100644 (file)
@@ -7,19 +7,13 @@ use parent qw/Exporter/;
 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 YAML::Any qw/LoadFile/;
-use File::Basename qw/fileparse/;
-use File::Slurp qw/slurp/;
-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/;
 
-use constant TITLE => '<tmpl_var name>';
-
-my %templates = (
-  en => <<'HTML',
+my %orig_templates = (
+       en => <<'HTML',
 Contest start time: <tmpl_var start><br>
 Contest end time: <tmpl_var end><p>
 
@@ -29,23 +23,21 @@ 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{
-  my ($path, $lang) = @_;
-  $path = ($path =~ m,ct/(.*)/index,)[0];
-  my $template = $templates{$lang};
-  my $htc = HTML::Template::Compiled->new(scalarref => \$template);
-  flock my $metafh = IO::File->new("<ct/$path/meta.yml"), LOCK_SH;
-  my $meta = LoadFile "ct/$path/meta.yml";
-
-  $htc->param(id => $path);
-  $htc->param(name => $meta->{name});
-  $htc->param(start => strftime '%c', localtime $meta->{start});
-  $htc->param(end => strftime '%c', localtime $meta->{end});
-  $htc->param(started => time >= $meta->{start});
-  $htc->output
+       %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};
+       my $htc = HTML::Template::Compiled->new(scalarref => \$template);
+
+       $htc->param(id => $path);
+       $htc->param(name => contest_name $path);
+       $htc->param(start => strftime '%c', contest_start);
+       $htc->param(end => strftime '%c', contest_end);
+       $htc->param(started => time >= contest_start);
+       $htc->output
 }
 
 1
This page took 0.021267 seconds and 4 git commands to generate.