Mercurial > pub > Impl
comparison _doc/make.pl @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | 47dac58691ee |
children | dacfe7c0311a |
comparison
equal
deleted
inserted
replaced
193:8e8401c0aea4 | 194:4d0e1962161c |
---|---|
23 | 23 |
24 (my $fnameOut = File::Spec->catfile($OutDir,@path)) =~ s/\.pm$/.html/i; | 24 (my $fnameOut = File::Spec->catfile($OutDir,@path)) =~ s/\.pm$/.html/i; |
25 | 25 |
26 my $dir =$OutDir; | 26 my $dir =$OutDir; |
27 foreach my $part (@path[0..$#path-1]) { | 27 foreach my $part (@path[0..$#path-1]) { |
28 $dir = File::Spec->catdir($dir,$part); | 28 $dir = File::Spec->catdir($dir,$part); |
29 mkdir $dir unless -d $dir; | 29 mkdir $dir unless -d $dir; |
30 } | 30 } |
31 | 31 |
32 open my $hPod, "<:encoding(utf-8)", $fname or die "Failed to open $fname for input: $!"; | 32 open my $hPod, "<:encoding(utf-8)", $fname or die "Failed to open $fname for input: $!"; |
33 open my $hOut, ">:encoding(utf-8)", $fnameOut or die "Failed to open $fnameOut for output: $!"; | 33 open my $hOut, ">:encoding(utf-8)", $fnameOut or die "Failed to open $fnameOut for output: $!"; |
34 | 34 |
45 my ($dirname,@dirs) = @_; | 45 my ($dirname,@dirs) = @_; |
46 | 46 |
47 opendir my $hdir, $dirname or die "faield to open dir $dirname: $!"; | 47 opendir my $hdir, $dirname or die "faield to open dir $dirname: $!"; |
48 | 48 |
49 foreach my $entry (readdir $hdir) { | 49 foreach my $entry (readdir $hdir) { |
50 next if grep $_ eq $entry, '.','..'; | 50 next if grep $_ eq $entry, '.','..'; |
51 | 51 |
52 my $path = "$dirname/$entry"; | 52 my $path = "$dirname/$entry"; |
53 | 53 |
54 print "$path"; | 54 print "$path"; |
55 | 55 |
56 if (-d $path) { | 56 if (-d $path) { |
57 print "\n"; | 57 print "\n"; |
58 local $index = exists $index->{items}{$entry} ? $index->{items}{$entry} : ($index->{items}{$entry} = {name => $entry}); | 58 local $index = exists $index->{items}{$entry} ? $index->{items}{$entry} : ($index->{items}{$entry} = {name => $entry}); |
59 process_dir($path,@dirs,$entry); | 59 process_dir($path,@dirs,$entry); |
60 } elsif ($entry =~ /\.(pm|pod)$/) { | 60 } elsif ($entry =~ /\.(pm|pod)$/) { |
61 print "\tprocessed\n"; | 61 print "\tprocessed\n"; |
62 process_file($path,@dirs,$entry); | 62 process_file($path,@dirs,$entry); |
63 } else { | 63 } else { |
64 print "\tskipped\n"; | 64 print "\tskipped\n"; |
65 } | 65 } |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 sub build_index { | 69 sub build_index { |
70 my ($hout,$index) = @_; | 70 my ($hout,$index) = @_; |
71 | 71 |
72 print $hout "\n<ul>\n"; | 72 print $hout "\n<ul>\n"; |
73 | 73 |
74 if ($index->{items}) { | 74 if ($index->{items}) { |
75 foreach my $itemKey (sort keys %{$index->{items}}) { | 75 foreach my $itemKey (sort keys %{$index->{items}}) { |
76 my $item = $index->{items}{$itemKey}; | 76 my $item = $index->{items}{$itemKey}; |
77 print $hout "<li>"; | 77 print $hout "<li>"; |
78 print $hout "<a target='content' href='$item->{url}'>" if $item->{url}; | 78 print $hout "<a target='content' href='$item->{url}'>" if $item->{url}; |
79 print $hout $item->{name}; | 79 print $hout $item->{name}; |
80 print $hout "</a>" if $item->{url}; | 80 print $hout "</a>" if $item->{url}; |
81 build_index($hout,$item) if $item->{items}; | 81 build_index($hout,$item) if $item->{items}; |
82 print $hout "</li>\n"; | 82 print $hout "</li>\n"; |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 print $hout "</ul>\n"; | 86 print $hout "</ul>\n"; |
87 } | 87 } |
88 | 88 |
89 `rm -r html`; | 89 `rm -r html`; |
90 mkdir 'html' unless -d 'html'; | 90 mkdir 'html' unless -d 'html'; |
91 | 91 |
118 <head> | 118 <head> |
119 <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> | 119 <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> |
120 <title>IMPL reference</title> | 120 <title>IMPL reference</title> |
121 </head> | 121 </head> |
122 <frameset cols="20%,*"> | 122 <frameset cols="20%,*"> |
123 <frame name="toc" src="toc.html"/> | 123 <frame name="toc" src="toc.html"/> |
124 <frame name="content" src="about:blank"/> | 124 <frame name="content" src="about:blank"/> |
125 </frameset> | 125 </frameset> |
126 </html> | 126 </html> |
127 FRAMES | 127 FRAMES |
128 | 128 |
129 package PodViewHTML; | 129 package PodViewHTML; |
133 | 133 |
134 sub view_pod { | 134 sub view_pod { |
135 my ($self, $pod) = @_; | 135 my ($self, $pod) = @_; |
136 return "<html>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /> | 136 return "<html>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /> |
137 \n<body bgcolor=\"#ffffff\">\n" | 137 \n<body bgcolor=\"#ffffff\">\n" |
138 . $pod->content->present($self) | 138 . $pod->content->present($self) |
139 . "</body>\n</html>\n"; | 139 . "</body>\n</html>\n"; |
140 } | 140 } |
141 sub view_begin { | 141 sub view_begin { |
142 my ($self,$begin) = @_; | 142 my ($self,$begin) = @_; |
143 return code_highlight(join ("",$begin->content()),$begin->format); | 143 return code_highlight(join ("",$begin->content()),$begin->format); |
144 } | 144 } |
145 | 145 |
146 sub escape_html { | 146 sub escape_html { |
147 my %esc = ( | 147 my %esc = ( |
148 '&' => '&', | 148 '&' => '&', |
149 '>' => '>', | 149 '>' => '>', |
150 '<' => '<' | 150 '<' => '<' |
151 ); | 151 ); |
152 | 152 |
153 (my $text = shift) =~ s/([&><])/$esc{$1}/gex; | 153 (my $text = shift) =~ s/([&><])/$esc{$1}/gex; |
154 | 154 |
155 return $text; | 155 return $text; |
156 } | 156 } |
157 | 157 |
158 sub view_seq_link { | 158 sub view_seq_link { |
159 my ($self,$text) = @_; | 159 my ($self,$text) = @_; |
160 | 160 |
161 $text =~ s/(\w+(?:\:\:\w+)+)/ | 161 $text =~ s/(\w+(?:\:\:\w+)+)/ |
162 if (my $url = $self->mk_filelink($1)) { | 162 if (my $url = $self->mk_filelink($1)) { |
163 "<a href='$url'>$1<\/a>"; | 163 "<a href='$url'>$1<\/a>"; |
164 } else { | 164 } else { |
165 $1; | 165 $1; |
166 } | 166 } |
167 /gex; | 167 /gex; |
168 | 168 |
169 return "<code>$text</code>"; | 169 return "<code>$text</code>"; |
170 } | 170 } |
171 | 171 |
172 sub mk_filelink { | 172 sub mk_filelink { |
173 my ($self,$package) = @_; | 173 my ($self,$package) = @_; |
174 | 174 |
175 return undef unless $package; | 175 return undef unless $package; |
176 | 176 |
177 my @path = split /::/, $package; | 177 my @path = split /::/, $package; |
178 | 178 |
179 if ($path[0] eq 'IMPL') { | 179 if ($path[0] eq 'IMPL') { |
180 shift @path; | 180 shift @path; |
181 if (-f File::Spec->catfile($LibDir,@path).".pm") { | 181 if (-f File::Spec->catfile($LibDir,@path).".pm") { |
182 return '../'x($level-1) . File::Spec->catfile(@path).'.html'; | 182 return '../'x($level-1) . File::Spec->catfile(@path).'.html'; |
183 } | 183 } |
184 } | 184 } |
185 return undef; | 185 return undef; |
186 } | 186 } |
187 | 187 |
188 sub view_seq_code { | 188 sub view_seq_code { |
189 goto &view_seq_link; | 189 goto &view_seq_link; |
190 } | 190 } |
191 | 191 |
192 sub view_code { | 192 sub view_code { |
193 my ($self,$code) = @_; | 193 my ($self,$code) = @_; |
194 | 194 |
195 return code_highlight($code); | 195 return code_highlight($code); |
196 } | 196 } |
197 | 197 |
198 sub code_highlight { | 198 sub code_highlight { |
199 my ($text,$format) = @_; | 199 my ($text,$format) = @_; |
200 | 200 |
201 if ($format) { | 201 if ($format) { |
202 $format =~ s/code//i; | 202 $format =~ s/code//i; |
203 $format =~ s/\s+//g; | 203 $format =~ s/\s+//g; |
204 } | 204 } |
205 | 205 |
206 $format ||= 'perl'; | 206 $format ||= 'perl'; |
207 | 207 |
208 return "<pre>".escape_html($text)."</pre>\n" if $format =~ /^text$/i; | 208 return "<pre>".escape_html($text)."</pre>\n" if $format =~ /^text$/i; |
209 | 209 |
210 | 210 |
211 | 211 |
212 my ($hin,$hout); | 212 my ($hin,$hout); |
213 local $/ = undef; | 213 local $/ = undef; |
214 my $pid = eval { open2( | 214 my $pid = eval { open2( |
215 $hin, $hout, 'source-highlight' => ( | 215 $hin, $hout, 'source-highlight' => ( |
216 '--src-lang' => $format, | 216 '--src-lang' => $format, |
217 ) | 217 ) |
218 ) } or return "<pre>".escape_html($text)."</pre>\n"; | 218 ) } or return "<pre>".escape_html($text)."</pre>\n"; |
219 | 219 |
220 binmode $hout, ':encoding(utf8)'; | 220 binmode $hout, ':encoding(utf8)'; |
221 binmode $hin, ':encoding(utf8)'; | 221 binmode $hin, ':encoding(utf8)'; |
222 | 222 |
223 print $hout $text; | 223 print $hout $text; |
224 | 224 |
225 undef $hout; | 225 undef $hout; |
226 | 226 |
227 my $fragment = <$hin>; | 227 my $fragment = <$hin>; |
228 | 228 |
229 undef $hin; | 229 undef $hin; |
230 | 230 |
231 return $fragment; | 231 return $fragment; |
232 | 232 |
233 } | 233 } |