X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FLog%2FEntry.pm;h=8fed9a19fb6aa3b28730a900c07d088ef511eb19;hb=2b0036ac8e077cc20cf9db6ff8dad4091ab50cb3;hp=4dd13baaef7eeb54fdd4952cdef894e857a778a6;hpb=c259ad15c1e3ed8f643fda85c5c4f432aac2d6ef;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Log/Entry.pm b/lib/Gruntmaster/Page/Log/Entry.pm index 4dd13ba..8fed9a1 100644 --- a/lib/Gruntmaster/Page/Log/Entry.pm +++ b/lib/Gruntmaster/Page/Log/Entry.pm @@ -7,17 +7,13 @@ use parent qw/Exporter/; our @EXPORT_OK = qw/generate/; our $VERSION = '0.001'; -use constant TITLE => 'Job '; - -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',
Test numberResultTime @@ -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 '; 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 ' 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