Mercurial > pub > Impl
comparison _doc/make.pl @ 66:f47f93534005
Documentation
author | wizard |
---|---|
date | Thu, 18 Mar 2010 17:58:33 +0300 |
parents | 2840c4c85db8 |
children | 2f31ecabe9ea |
comparison
equal
deleted
inserted
replaced
65:2840c4c85db8 | 66:f47f93534005 |
---|---|
30 } | 30 } |
31 | 31 |
32 open my $hPod, "<:encoding(cp1251)", $fname or die "Failed to open $fname for input: $!"; | 32 open my $hPod, "<:encoding(cp1251)", $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 |
35 my $parser = Pod::POM->new( ); | 35 my $parser = Pod::POM->new(); |
36 | 36 |
37 my $pom = $parser->parse_file($hPod); | 37 my $pom = $parser->parse_file($hPod); |
38 | 38 |
39 $level = @path; | 39 $level = @path; |
40 | 40 |
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 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 } |
89 `rm -r html`; | 89 `rm -r html`; |
90 mkdir 'html' unless -d 'html'; | 90 mkdir 'html' unless -d 'html'; |
91 | 91 |
92 process_dir($LibDir); | 92 process_dir($LibDir); |
93 | 93 |
94 open my $hout, ">:encoding(utf-8)", "$OutDir/index.html" or die "failed to open index.html for output: $!"; | 94 open my $hout, ">:encoding(utf-8)", "$OutDir/toc.html" or die "failed to open toc.html for output: $!"; |
95 | 95 |
96 print $hout <<HEADER; | 96 print $hout <<HEADER; |
97 <html> | 97 <html> |
98 <head> | 98 <head> |
99 <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> | 99 <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> |
107 print $hout <<FOOTER; | 107 print $hout <<FOOTER; |
108 </body> | 108 </body> |
109 </html> | 109 </html> |
110 FOOTER | 110 FOOTER |
111 | 111 |
112 undef $hout; | |
113 | |
114 open $hout, ">:encoding(utf-8)","$OutDir/index.html" or die "failed to open index.html for output: $!"; | |
115 | |
116 print $hout <<FRAMES; | |
117 <html> | |
118 <head> | |
119 <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> | |
120 <title>IMPL reference</title> | |
121 </head> | |
122 <frameset cols="30%,*"> | |
123 <frame name="toc" src="toc.html"/> | |
124 <frame name="content" src="about:blank"/> | |
125 </frameset> | |
126 </html> | |
127 FRAMES | |
128 | |
112 package PodViewHTML; | 129 package PodViewHTML; |
113 use base qw(Pod::POM::View::HTML); | 130 use base qw(Pod::POM::View::HTML); |
131 | |
132 use IPC::Open2; | |
114 | 133 |
115 sub view_pod { | 134 sub view_pod { |
116 my ($self, $pod) = @_; | 135 my ($self, $pod) = @_; |
117 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\" /> |
118 \n<body bgcolor=\"#ffffff\">\n" | 137 \n<body bgcolor=\"#ffffff\">\n" |
119 . $pod->content->present($self) | 138 . $pod->content->present($self) |
120 . "</body>\n</html>\n"; | 139 . "</body>\n</html>\n"; |
121 } | 140 } |
122 sub view_begin { | 141 sub view_begin { |
123 my ($self,$begin) = @_; | 142 my ($self,$begin) = @_; |
124 $begin->format =~ /code/i ? return "<pre>\n".escape_html(join ("",$begin->text()))."</pre>\n" : return $self->SUPER::view_begin($begin); | 143 return code_highlight(join ("",$begin->content()),$begin->format); |
125 } | 144 } |
126 | 145 |
127 sub escape_html { | 146 sub escape_html { |
128 my %esc = ( | 147 my %esc = ( |
129 '&' => '&', | 148 '&' => '&', |
167 } | 186 } |
168 | 187 |
169 sub view_seq_code { | 188 sub view_seq_code { |
170 goto &view_seq_link; | 189 goto &view_seq_link; |
171 } | 190 } |
191 | |
192 sub view_code { | |
193 my ($self,$code) = @_; | |
194 | |
195 return code_highlight($code); | |
196 } | |
197 | |
198 sub code_highlight { | |
199 my ($text,$format) = @_; | |
200 | |
201 if ($format) { | |
202 $format =~ s/code//i; | |
203 $format =~ s/\s+//g; | |
204 } | |
205 | |
206 $format ||= 'perl'; | |
207 | |
208 return "<pre>".escape_html($text)."</pre>\n" if $format =~ /^text$/i; | |
209 | |
210 | |
211 | |
212 my ($hin,$hout); | |
213 local $/ = undef; | |
214 my $pid = eval { open2( | |
215 $hin, $hout, highlight => ( | |
216 '--syntax' => $format, | |
217 '--html', | |
218 '--fragment', | |
219 '--inline-css', | |
220 '--enclose-pre' | |
221 ) | |
222 ) } or return "<pre>".escape_html($text)."</pre>\n"; | |
223 | |
224 binmode $hout, ':encoding(utf8)'; | |
225 binmode $hin, ':encoding(utf8)'; | |
226 | |
227 print $hout $text; | |
228 | |
229 undef $hout; | |
230 | |
231 my $fragment = <$hin>; | |
232 | |
233 undef $hin; | |
234 | |
235 return $fragment; | |
236 | |
237 } |