]> iEval git - plack-app-gruntmaster.git/blame - lib/Gruntmaster/Page/Log/Entry.pm
Move header / footer to a separate module and update MANIFEST
[plack-app-gruntmaster.git] / lib / Gruntmaster / Page / Log / Entry.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page::Log::Entry;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
10use constant TITLE => 'Job <tmpl_var id>';
11
12use Fcntl qw/:flock/;
13use HTML::Template::Compiled;
14use IO::File;
15use POSIX qw/strftime/;
16use YAML::Any qw/LoadFile/;
832cb45e 17use Gruntmaster::Page::Common qw/header footer/;
42546e6c
MG
18
19my %templates = (
20 en => <<'HTML',
21<table border>
22<thead>
23<tr><th>Test number<th>Result<th>Time
24<tbody>
25<tmpl_loop tests><tr><td><tmpl_var id><td class="r<tmpl_var result>"><tmpl_var result_text><td><tmpl_var time>
26</tmpl_loop>
27</table>
28HTML
29);
30
31$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
32$templates{$_} .= footer $_ for keys %templates;
33
34sub generate{
35 my ($path, $lang) = @_;
c259ad15 36 my $id = ($path =~ m,log/(.*)/index,)[0];
fe78f0c1 37 $path =~ s,/index\.html,,;
42546e6c
MG
38 my $template = $templates{$lang};
39
40 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
fe78f0c1
MG
41 flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
42 my $meta = LoadFile "$path/meta.yml";
42546e6c
MG
43
44 my @tests = map {
45 $_->{time} = sprintf "%.4fs", $_->{time};
46 $_
47 } @{$meta->{results}};
48
fe78f0c1 49 $htc->param(id => $id);
42546e6c
MG
50 $htc->param(tests => \@tests);
51 $htc->output
52}
53
541
This page took 0.023002 seconds and 4 git commands to generate.