]> iEval git - plack-app-gruntmaster.git/blobdiff - lib/Gruntmaster/Page/Log/Entry.pm
Centralize template cooking and introduce reloadable templates
[plack-app-gruntmaster.git] / lib / Gruntmaster / Page / Log / Entry.pm
index 4dd13baaef7eeb54fdd4952cdef894e857a778a6..8fed9a19fb6aa3b28730a900c07d088ef511eb19 100644 (file)
@@ -7,17 +7,13 @@ use parent qw/Exporter/;
 our @EXPORT_OK = qw/generate/;
 our $VERSION = '0.001';
 
-use constant TITLE => 'Job <tmpl_var id>';
-
-use Fcntl qw/:flock/;
 use HTML::Template::Compiled;
-use IO::File;
 use POSIX qw/strftime/;
-use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page qw/header footer/;
+use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
+use Gruntmaster::Data qw/job_results/;
 
-my %templates = (
-  en => <<'HTML',
+my %orig_templates = (
+       en => <<'HTML',
 <table border>
 <thead>
 <tr><th>Test number<th>Result<th>Time
@@ -28,27 +24,24 @@ my %templates = (
 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{
-  my ($path, $lang) = @_;
-  my $id = ($path =~ m,log/(.*)/index,)[0];
-  $path =~ s,/index\.html,,;
-  my $template = $templates{$lang};
-
-  my $htc = HTML::Template::Compiled->new(scalarref => \$template);
-  flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
-  my $meta = LoadFile "$path/meta.yml";
-
-  my @tests = map {
-       $_->{time} = sprintf "%.4fs", $_->{time};
-       $_
-  } @{$meta->{results}};
-
-  $htc->param(id => $id);
-  $htc->param(tests => \@tests);
-  $htc->output
+       %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;
+
+       my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
+
+       my @tests = map {
+               $_->{time} = sprintf "%.4fs", $_->{time};
+               $_
+       } @{job_results $id};
+
+       $htc->param(id => $id);
+       $htc->param(tests => \@tests);
+       $htc->output
 }
 
 1
This page took 0.0229 seconds and 4 git commands to generate.