| 1 | package Smolder::TAPHTMLMatrix; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use Carp qw/croak/; | ||
| 5 | use File::Spec::Functions qw(catdir catfile tmpdir); | ||
| 6 | use File::Path; | ||
| 7 | use URI::file; | ||
| 8 | use Template; | ||
| 9 | use Smolder::Conf qw(TemplateDir); | ||
| 10 | use Smolder::Control; | ||
| 11 | use Template::Plugin::Cycle; | ||
| 12 | |||
| 13 | our $TMPL = Template->new( | ||
| 14 | COMPILE_DIR => tmpdir(), | ||
| 15 | COMPILE_EXT => '.ttc', | ||
| 16 | INCLUDE_PATH => TemplateDir, | ||
| 17 | FILTERS => { | ||
| 18 | pass_fail_color => \&Smolder::Util::pass_fail_color, | ||
| 19 | format_time => \&Smolder::Util::format_time, | ||
| 20 | }, | ||
| 21 | ); | ||
| 22 | |||
| 23 | # use Smolder::Control's version | ||
| 24 | sub static_url { | ||
| 25 | return Smolder::Control->static_url(shift); | ||
| 26 | } | ||
| 27 | |||
| 28 | sub new { | ||
| 29 | my ($pkg, %args) = @_; | ||
| 30 | my $self = bless(\%args, $pkg); | ||
| 31 | return $self; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub report { shift->{smoke_report} } | ||
| 35 | sub results { shift->{test_results} } | ||
| 36 | |||
| 37 | sub generate_html { | ||
| 38 | my $self = shift; | ||
| 39 | |||
| 40 | # where are we saving the results | ||
| 41 | my $dir = catdir($self->report->data_dir, 'html'); | ||
| 42 | unless (-d $dir) { | ||
| 43 | mkpath($dir) or croak "Could not create directory '$dir'! $!"; | ||
| 44 | } | ||
| 45 | my $file = catfile($dir, 'report.html'); | ||
| 46 | |||
| 47 | my $meta = $self->{meta} || {}; | ||
| 48 | my $extra_props = $meta->{extra_properties} || {}; | ||
| 49 | |||
| 50 | # process the full report | ||
| 51 | my $odd_even = Template::Plugin::Cycle->new(qw(odd even)); | ||
| 52 | $TMPL->process( | ||
| 53 | 'TAP/full_report.tmpl', | ||
| 54 | { | ||
| 55 | report => $self->report, | ||
| 56 | results => $self->results, | ||
| 57 | odd_even => $odd_even, | ||
| 58 | url_base => Smolder::Util::url_base(), | ||
| 59 | extra_properties => $extra_props, | ||
| 60 | }, | ||
| 61 | $file, | ||
| 62 | ) or croak $TMPL->error; | ||
| 63 | |||
| 64 | # now generate the HTML for each individual file | ||
| 65 | my $count = 0; | ||
| 66 | foreach my $test (@{$self->results}) { | ||
| 67 | my $save_file = catfile($dir, $count . '.html'); | ||
| 68 | $TMPL->process( | ||
| 69 | 'TAP/individual_test.tmpl', | ||
| 70 | { | ||
| 71 | report => $self->report, | ||
| 72 | test_file => $test->{label}, | ||
| 73 | tests => $test->{tests}, | ||
| 74 | odd_even => $odd_even, | ||
| 75 | url_base => Smolder::Util::url_base(), | ||
| 76 | is_muted => $test->{is_muted}, | ||
| 77 | }, | ||
| 78 | $save_file, | ||
| 79 | ) or croak "Problem processing template file '$file': ", $TMPL->error; | ||
| 80 | $count++; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | __END__ |