]>
Commit | Line | Data |
---|---|---|
1 | package Gruntmaster::Page::Log::Entry; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | use parent qw/Exporter/; | |
7 | our @EXPORT_OK = qw/generate/; | |
8 | our $VERSION = '0.001'; | |
9 | ||
10 | use constant TITLE => 'Job <tmpl_var id>'; | |
11 | ||
12 | use Fcntl qw/:flock/; | |
13 | use HTML::Template::Compiled; | |
14 | use IO::File; | |
15 | use POSIX qw/strftime/; | |
16 | use YAML::Any qw/LoadFile/; | |
17 | use Gruntmaster::Page qw/header footer/; | |
18 | ||
19 | my %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> | |
28 | HTML | |
29 | ); | |
30 | ||
31 | $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; | |
32 | $templates{$_} .= footer $_ for keys %templates; | |
33 | ||
34 | sub generate{ | |
35 | my ($path, $lang) = @_; | |
36 | my $id = ($path =~ m,log/(.*)/index,)[0]; | |
37 | $path =~ s,/index\.html,,; | |
38 | my $template = $templates{$lang}; | |
39 | ||
40 | my $htc = HTML::Template::Compiled->new(scalarref => \$template); | |
41 | flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH; | |
42 | my $meta = LoadFile "$path/meta.yml"; | |
43 | ||
44 | my @tests = map { | |
45 | $_->{time} = sprintf "%.4fs", $_->{time}; | |
46 | $_ | |
47 | } @{$meta->{results}}; | |
48 | ||
49 | $htc->param(id => $id); | |
50 | $htc->param(tests => \@tests); | |
51 | $htc->output | |
52 | } | |
53 | ||
54 | 1 |