| 1 | package JSTAPd::Contents; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use FindBin; | ||
| 5 | |||
| 6 | sub suite { $_[0]->{suite} } | ||
| 7 | |||
| 8 | sub new { | ||
| 9 | my($class, $name, $path) = @_; | ||
| 10 | |||
| 11 | my $self = bless { | ||
| 12 | name => $name, | ||
| 13 | path => $path, | ||
| 14 | suite => undef, | ||
| 15 | }, $class; | ||
| 16 | $self->parse if $path =~ /\.t$/; | ||
| 17 | $self; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub slurp { $_[0]->{slurp} ||= $_[0]->{path}->slurp } | ||
| 21 | |||
| 22 | my $ANON_CLASS_COUNT = 0; | ||
| 23 | |||
| 24 | sub parse { | ||
| 25 | my $self = shift; | ||
| 26 | |||
| 27 | my $script = $self->slurp; | ||
| 28 | my $package = join '::', __PACKAGE__, 'AnonClass', 'Num'.($ANON_CLASS_COUNT++); | ||
| 29 | my $code = " | ||
| 30 | # line 1 $package.pm | ||
| 31 | package $package; ## | ||
| 32 | BEGIN{ \$$package\::IN_THE_PARSE = 1 }; | ||
| 33 | # line 1 $self->{path} | ||
| 34 | $script; | ||
| 35 | # line 5 $package.pm | ||
| 36 | sub path { '$self->{path}' } | ||
| 37 | sub name { '$self->{name}' } | ||
| 38 | JSTAPd::Suite::export(__PACKAGE__); | ||
| 39 | 1;"; | ||
| 40 | do { | ||
| 41 | local $FindBin::Bin = $self->{path}->dir; | ||
| 42 | eval $code; ## no critic | ||
| 43 | }; | ||
| 44 | $@ and die $@; | ||
| 45 | $self->{suite} = $package->new; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub header { | ||
| 49 | my($self, %args) = @_; | ||
| 50 | my $script = $self->suite->client_script; | ||
| 51 | |||
| 52 | return sprintf <<'HTML', $args{jstapd_prefix}, $args{jstapd_prefix}, $args{jstapd_prefix}, $args{session}, $args{path}, $self->suite->tests, ($args{include} || 'nop()'), $script; | ||
| 53 | <script type="text/javascript" src="/%s/share/js/jstapd.js"></script> | ||
| 54 | <script type="text/javascript" src="/%s/share/js/jstapd.deferred.js"></script> | ||
| 55 | <script type="text/javascript"> | ||
| 56 | (function(){ | ||
| 57 | JSTAPd.jstapd_prefix = '/%s__api/'; | ||
| 58 | JSTAPd.session = '%s'; | ||
| 59 | JSTAPd.path = '%s'; | ||
| 60 | JSTAPd.tap_tests = %s; | ||
| 61 | |||
| 62 | window.onload = function(){ | ||
| 63 | jstapDeferred.next(function(){ | ||
| 64 | // lib load | ||
| 65 | return jstapDeferred.next(function(){}). | ||
| 66 | %s | ||
| 67 | ; | ||
| 68 | }). | ||
| 69 | next(function(){ | ||
| 70 | // run test | ||
| 71 | %s | ||
| 72 | }). | ||
| 73 | wait_finish(). | ||
| 74 | next(function(){ | ||
| 75 | // done | ||
| 76 | tap_done(''); | ||
| 77 | }); | ||
| 78 | } | ||
| 79 | })(); | ||
| 80 | </script> | ||
| 81 | HTML | ||
| 82 | } | ||
| 83 | |||
| 84 | sub build_html { | ||
| 85 | my($self, $head, $body) = @_; | ||
| 86 | my $index = $self->slurp; | ||
| 87 | $body = sprintf '<div id="jstap_users_body_container">%s</div>', $body; | ||
| 88 | $index =~ s/\$HEAD/$head/g; | ||
| 89 | $index =~ s{\$BODY}{$body<div id="jstap_tap_result_container"></div>}g; | ||
| 90 | $index; | ||
| 91 | } | ||
| 92 | |||
| 93 | sub build_index { | ||
| 94 | my($class, %args) = @_; | ||
| 95 | _default_index(%args); | ||
| 96 | } | ||
| 97 | |||
| 98 | sub _default_index { | ||
| 99 | my %args = @_; | ||
| 100 | |||
| 101 | return sprintf <<'HTML', $args{jstapd_prefix}, $args{jstapd_prefix}, $args{jstapd_prefix}, $args{jstapd_prefix}, ($args{run_once} ? 'true' : 'false'), ($args{auto_open} ? 'true' : 'false'); | ||
| 102 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| 103 | <html> | ||
| 104 | <head> | ||
| 105 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 106 | <meta http-equiv="content-script-type" content="text/javascript"> | ||
| 107 | <title>JSTAPd main index</title> | ||
| 108 | <script type="text/javascript" src="/%s/share/js/jstapd.js"></script> | ||
| 109 | <script type="text/javascript" src="/%s/share/js/jstapd.index.js"></script> | ||
| 110 | <script type="text/javascript"> | ||
| 111 | JSTAPd.jstapd_prefix = '/%s__api/'; | ||
| 112 | JSTAPd.contents_prefix = '/%s/contents/'; | ||
| 113 | JSTAPd.session = ''; | ||
| 114 | JSTAPd.path = ''; | ||
| 115 | JSTAPd.run_once = %s; | ||
| 116 | JSTAPd.auto_open = %s; | ||
| 117 | </script> | ||
| 118 | </head> | ||
| 119 | <body id="body"> | ||
| 120 | <div><a href="./share/">./share/</a> | <a href="./contents/">./contents/</a></div> | ||
| 121 | <div>Test Files: <span id="test_files_success">0</span>/<span id="test_files">0</span></div> | ||
| 122 | <div>Test Plans: <span id="test_plans_success">0</span>/<span id="test_plans">0</span></div> | ||
| 123 | <div id="results" style="border: 1px solid red; margin: 10px"></div> | ||
| 124 | <input type="button" id="make-test" value="make test"/> | ||
| 125 | </body> | ||
| 126 | </html> | ||
| 127 | HTML | ||
| 128 | } | ||
| 129 | |||
| 130 | 1; | ||
| 131 | |||
| 132 | __END__ |