The attached patch resolves various issues:
* it adds a force_inline_js function akin to the existing
force_inline_css function
* it adds a strict DOCTYPE to the resulting html
* under XHTML, id attributes are not allowed to be empty. Those on the
<tr class="test-run" were empty. resolved by commenting out the
attribute. This didn't seem to cause any issues (all the tests pass).
* Under TT, [% IF test.parse_errors %] tests true if parse_errors is an
empty array. This has been replaced by [% IF tests.parse_errors.size > 0 %]
* fixed various other XHTML violations (either by adding missing
elements or by adding non-breaking spaces)
* also fixed the s/incline_js/inline_js/ bug
Subject: | TAP-Formatter-HTML-0.06.patch |
diff -ur TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML/default_report.tt2 TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML/default_report.tt2
--- TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML/default_report.tt2 2008-08-26 15:58:14.000000000 +0100
+++ TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML/default_report.tt2 2008-12-05 10:49:55.000000000 +0000
@@ -1,3 +1,5 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
[%#
TAP-Formatter-HTML: TT2 Template
Copyright (c) 2008 Steve Purkis. All rights reserved.
@@ -40,10 +42,12 @@
</div>
<div id="menu">
+ <ul>
<li>
<span id="show-all"><a href="#" title="show all tests">show all</a></span>
<span id="show-failed"><a href="#" title="show failed tests only">show failed</a></span>
</li>
+ </ul>
</div>
<div id="detail">
@@ -60,7 +64,7 @@
[%- FOREACH test IN report.tests %]
<tr class="test-run [% test.test_status -%]
[%- IF test.severity %][% ' severity-' _ test.severity %][% END -%]
- [%- IF test.todo_passed %] todo-passed[% END %]" id="[% test.html_id %]">
+ [%- IF test.todo_passed %] todo-passed[% END %]"><!-- id="[% test.html_id %]">-->
<td class="file c">
<a class="file" href="#" title="Test [% IF test.has_problems %]failed![% ELSE %]ok.[% END %]
[% IF test.num_parse_errors %] [% test.num_parse_errors %] parse error(s)!
@@ -84,7 +88,7 @@
[%- SET max_tests = test.tests_run IF test.tests_run AND test.tests_run > max_tests %]
<table class="TS">[%# TS=Test Summary. Note: use a table to caulculate widths automatically %]
<tr>
- [%- IF test.tests_run AND test.tests_run > 0 -%]
+ [% IF test.tests_run AND test.tests_run > 0 -%]
[%- SET current_test = 0 -%]
[%- FOREACH result IN test.results -%]
[%- IF result.is_test %]
@@ -107,7 +111,7 @@
</tr>
</table>
<div class="test-detail">
- [%- IF test.parse_errors %]
+ [%- IF test.parse_errors.size > 0 %]
<ul class="parse-errors">
[%- FOREACH e IN test.parse_errors %]
<li>Parse error: [% e %]</li>
@@ -118,7 +122,7 @@
[%- FOREACH result IN test.results %]
<li [% IF result.is_test %]id="[% result.html_id %]" [% END -%]class="[% result.css_type -%]
[%- IF result.is_test %][% ' ' _ result.short_test_status -%][%- END -%]
- [%- IF result.is_unplanned %] unp[% END -%]">[% result.raw | html -%]
+ [%- IF result.is_unplanned %] unp[% END -%]">[% result.raw | html -%]
[%- IF result.is_unplanned %]<em> (unplanned!)</em>[% END -%]
[%- IF result.todo_passed %]<em> (unexpectedly succeeded!)</em>[% END %]</li>
[%- END -%]
diff -ur TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML.pm TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML.pm
--- TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML.pm 2008-08-26 15:58:14.000000000 +0100
+++ TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML.pm 2008-12-05 10:49:40.000000000 +0000
@@ -30,7 +30,8 @@
# you can use your own customized templates too:
$fmt->template('custom.tt2')
->template_processor( Template->new )
- ->force_inline_css(0);
+ ->force_inline_css(0)
+ ->force_inline_js(0);
=cut
@@ -53,7 +54,7 @@
use base qw( TAP::Base );
use accessors qw( verbosity stdout escape_output tests session_class sessions
template_processor template html html_id_iterator minify
- css_uris js_uris inline_css inline_js abs_file_paths force_inline_css );
+ css_uris js_uris inline_css inline_js abs_file_paths force_inline_css force_inline_js );
use constant default_session_class => 'TAP::Formatter::HTML::Session';
use constant default_template => 'TAP/Formatter/HTML/default_report.tt2';
@@ -98,6 +99,7 @@
->abs_file_paths( 1 )
->abs_file_paths( 1 )
->force_inline_css( 1 )
+ ->force_inline_js( 1 )
->session_class( $self->default_session_class )
->template_processor( $self->default_template_processor )
->template( $self->default_template )
@@ -198,12 +200,13 @@
$self->check_uris;
$self->slurp_css if $self->force_inline_css;
+ $self->slurp_js if $self->force_inline_js;
my $params = {
report => $r,
js_uris => $self->js_uris,
css_uris => $self->css_uris,
- incline_js => $self->inline_js,
+ inline_js => $self->inline_js,
inline_css => $self->inline_css,
formatter => { class => ref( $self ),
version => $self->VERSION },
@@ -364,6 +367,34 @@
$self->inline_css( $inline_css );
}
+sub slurp_js {
+ my ($self) = shift;
+ $self->info("slurping js files inline");
+
+ my $inline_js = $self->inline_js || '';
+ foreach my $uri (@{ $self->js_uris }) {
+ my $scheme = $uri->scheme;
+ if ($scheme && $scheme eq 'file') {
+ my $path = $uri->path;
+ if (-e $path) {
+ if (open my $fh, $path) {
+ local $/ = undef;
+ $inline_js .= <$fh>;
+ } else {
+ $self->log("Warning: couldn't open $path: $!");
+ }
+ } else {
+ $self->log("Warning: couldn't read $path: file does not exist!");
+ }
+ } else {
+ $self->log("Warning: can't include $uri inline: not a file uri");
+ }
+ }
+
+ $self->inline_js( $inline_js );
+}
+
+
sub log {
my $self = shift;
push @_, "\n" unless grep {/\n/} @_;
@@ -583,6 +614,13 @@
sending the output around - that way you don't have to send a CSS file too.
Defaults to I<1>.
+=head3 force_inline_js( [ $boolean ] )
+
+If set, the formatter will attempt to slurp in any I<file> javascript URI's listed in
+L</js_uris>, and append them to L</inline_js>. This is handy if you'll be
+sending the output around - that way you don't have to send javascript files too.
+Defaults to I<1>.
+
=head2 $html = $fmt->summary( $aggregator )
C<summary> produces a summary report after all tests are run. C<$aggregator>
@@ -597,7 +635,7 @@
report => %test_report
js_uris => @js_uris
css_uris => @js_uris
- incline_js => $inline_js
+ inline_js => $inline_js
inline_css => $inline_css
formatter => %formatter_info