Debian Codegraph @

t/scan/print.t

raw
1 use strict;
2 use warnings;
3 use FindBin;
4 use lib "$FindBin::Bin/../../";
5 use t::scan::Util;
6
7 test(<<'TEST'); # DAMI/Alien-GvaScript-1.44/GvaScript_Builder.pm
8 sub generate_js { # concatenates sources below into "GvaScript.js"
9 my ($self) = @_;
10 require "lib/Alien/GvaScript.pm";
11
12 my @sources = qw/protoExtensions event keyMap
13 treeNavigator choiceList autoCompleter
14 customButtons paginator grid
15 repeat form/;
16 my $dest = "lib/Alien/GvaScript/lib/GvaScript.js";
17 chmod 0777, $dest;
18 open my $dest_fh, ">$dest" or die "open >$dest : $!";
19
20 print $dest_fh <<__EOJS__;
21 /*-------------------------------------------------------------------------*
22 * GvaScript - Javascript framework born in Geneva.
23 *
24 * Authors: Laurent Dami <laurent.d...\@etat.ge.ch>
25 * Mona Remlawi
26 * Jean-Christophe Durand
27 * Sebastien Cuendet
28
29 * LICENSE
30 * This library is free software, you can redistribute it and/or modify
31 * it under the same terms as Perl's artistic license.
32 *
33 *--------------------------------------------------------------------------*/
34
35 var GvaScript = {
36 Version: '$Alien::GvaScript::VERSION',
37 REQUIRED_PROTOTYPE: '1.7',
38 load: function() {
39 function convertVersionString(versionString) {
40 var v = versionString.replace(/_.*|\\./g, '');
41 v = parseInt(v + '0'.times(4-v.length));
42 return versionString.indexOf('_') > -1 ? v-1 : v;
43 }
44 if((typeof Prototype=='undefined') ||
45 (typeof Element == 'undefined') ||
46 (typeof Element.Methods=='undefined') ||
47 (convertVersionString(Prototype.Version) <
48 convertVersionString(GvaScript.REQUIRED_PROTOTYPE)))
49 throw("GvaScript requires the Prototype JavaScript framework >= " +
50 GvaScript.REQUIRED_PROTOTYPE);
51 }
52 };
53
54 GvaScript.load();
55 __EOJS__
56
57 foreach my $sourcefile (@sources) {
58 open my $fh, "src/$sourcefile.js" or die $!;
59 print $dest_fh "\n//----------$sourcefile.js\n", <$fh>;
60 }
61 }
62
63 sub generate_html {# regenerate html doc from pod sources
64 my ($self) = @_;
65
66 require Pod::POM;
67 require Pod::POM::View::HTML;
68
69 my @podfiles = glob ("lib/Alien/GvaScript/*.pod");
70 my $parser = new Pod::POM;
71
72 foreach my $podfile (@podfiles) {
73 my $pom = $parser->parse($podfile) or die $parser->error;
74 $podfile =~ m[^lib/Alien/GvaScript/(.*)\.pod];
75 my $htmlfile = "doc/html/$1.html";
76 print STDERR "converting $podfile ==> $htmlfile\n";
77 open my $fh, ">$htmlfile" or die "open >$htmlfile: $!";
78 print $fh Pod::POM::View::HTML::GvaScript->print($pom);
79 close $fh;
80 }
81 return 1;
82 }
83
84 sub generate_googlewiki {# regenerate wiki doc from pod sources
85 my ($self) = @_;
86
87 require Pod::Simple::Wiki;
88 require Pod::Simple::Wiki::Googlecode;
89
90 # destination for wiki files
91 my $dir = "blib/wiki";
92 -d $dir or mkdir $dir or die "mkdir $dir: $!";
93
94 # list of source files
95 my @podfiles = glob ("lib/Alien/GvaScript/*.pod");
96
97 # convert each file
98 foreach my $podfile (@podfiles) {
99
100 my $parser = Pod::Simple::Wiki->new('googlecode');
101 $podfile =~ m[^lib/Alien/GvaScript/(.*)\.pod];
102 my $wikifile = "$dir/$1.wiki";
103 open my $fh, ">$wikifile" or die "open >$wikifile: $!";
104 print STDERR "converting $podfile ==> $wikifile\n";
105
106 $parser->output_fh($fh);
107 $parser->parse_file($podfile);
108 }
109
110 return 1;
111 }
112
113
114
115 1;
116
117
118 #======================================================================
119 package Pod::POM::View::HTML::GvaScript;
120 #======================================================================
121 use strict;
122 use warnings;
123
124 use base 'Pod::POM::View::HTML';
125
126 sub _title_to_id {
127 my $title = shift;
128 $title =~ s/<.*?>//g; # no tags
129 $title =~ s/\W+/_/g;
130 return $title;
131 }
132
133
134 sub view_pod {
135 my ($self, $pod) = @_;
136
137 my $doc_title = ($pod->head1)[0]->content->present($self);
138 $doc_title =~ s/<.*?>//g; # no tags
139 my ($name, $description) = split /\s+-\s+/, $doc_title;
140
141 my $content = $pod->content->present($self);
142 my $toc = $self->make_toc($pod, 0);
143
144 return <<__EOHTML__
145 <html>
146 <head>
147 <script src="../../lib/Alien/GvaScript/lib/prototype.js"></script>
148 <script src="../../lib/Alien/GvaScript/lib/GvaScript.js"></script>
149 <link href="GvaScript_doc.css" rel="stylesheet" type="text/css">
150 <script>
151 document.observe('dom:loaded', function() { new GvaScript.TreeNavigator('TN_tree'); });
152 function jumpto_href(event) {
153 var label = event.controller.label(event.target);
154 if (label && label.tagName == "A") {
155 label.focus();
156 return Event.stopNone;
157 }
158 }
159 </script>
160 </head>
161 <body>
162 <div id='TN_tree'>
163 <div class="TN_node">
164 <h1 class="TN_label">$name</h1>
165 <div class="TN_content">
166 <p><em>$description</em></p>
167 <div class="TN_node" onPing="jumpto_href">
168 <h3 class="TN_label">Table of contents</h3>
169 <div class="TN_content">
170 $toc
171 </div>
172 </div>
173 <hr/>
174 </div>
175 </div>
176 $content
177 </div>
178 </body>
179 </html>
180 __EOHTML__
181
182 }
183
184 # installing same method for view_head1, view_head2, etc.
185 BEGIN {
186 for my $num (1..6) {
187 no strict 'refs';
188 *{"view_head$num"} = sub {
189 my ($self, $item) = @_;
190 my $title = $item->title->present($self);
191 my $id = _title_to_id($title);
192 my $content = $item->content->present($self);
193 my $h_num = $num + 1;
194 return <<__EOHTML__
195 <div class="TN_node" id="$id">
196 <h$h_num class="TN_label">$title</h$h_num>
197 <div class="TN_content">
198 $content
199 </div>
200 </div>
201 __EOHTML__
202 }
203 }
204 }
205
206
207 sub make_toc_orig {
208 my ($self, $item, $level) = @_;
209
210 my @nodes;
211 my $method = "head" . ($level + 1);
212 my $sub_items = $item->$method;
213
214 foreach my $sub_item (@$sub_items) {
215 my $title = $sub_item->title->present($self);
216 my $id = _title_to_id($title);
217
218 my $node_html = qq{<a toc_node="$id">$title</a>}
219 . $self->make_toc($sub_item, $level + 1);
220 push @nodes, $node_html;
221 }
222 my $html = join "", map {"<li>$_</li>"} @nodes;
223 return $html ? "<ul>$html</ul>" : "";
224 }
225
226 sub make_toc {
227 my ($self, $item, $level) = @_;
228
229 my @nodes;
230 my $method = "head" . ($level + 1);
231 my $sub_items = $item->$method;
232
233 foreach my $sub_item (@$sub_items) {
234 my $title = $sub_item->title->present($self);
235 my $id = _title_to_id($title);
236
237 my $node_content = $self->make_toc($sub_item, $level + 1);
238 my $class = $node_content ? "TN_node" : "TN_leaf";
239 my $node_html = <<__EOHTML__;
240 <div class="$class">
241 <a class="TN_label" href="#$id">$title</a>
242 <div class="TN_content">$node_content</div>
243 </div>
244 __EOHTML__
245
246 push @nodes, $node_html;
247 }
248 my $html = join "", @nodes;
249 return $html;
250 }
251
252 1;
253 TEST
254
255 done_testing;