diff _doc/make.pl @ 66:f47f93534005

Documentation
author wizard
date Thu, 18 Mar 2010 17:58:33 +0300
parents 2840c4c85db8
children 2f31ecabe9ea
line wrap: on
line diff
--- a/_doc/make.pl	Tue Mar 16 17:36:13 2010 +0300
+++ b/_doc/make.pl	Thu Mar 18 17:58:33 2010 +0300
@@ -32,7 +32,7 @@
     open my $hPod, "<:encoding(cp1251)", $fname or die "Failed to open $fname for input: $!";
     open my $hOut, ">:encoding(utf-8)", $fnameOut or die "Failed to open $fnameOut for output: $!";
     
-    my $parser = Pod::POM->new( );
+    my $parser = Pod::POM->new();
     
     my $pom = $parser->parse_file($hPod);
     
@@ -75,7 +75,7 @@
 		foreach my $itemKey (sort keys %{$index->{items}}) {
 			my $item = $index->{items}{$itemKey};
 			print $hout "<li>";
-			print $hout "<a href='$item->{url}'>" if $item->{url};
+			print $hout "<a target='content' href='$item->{url}'>" if $item->{url};
 			print $hout $item->{name};
 			print $hout "</a>" if $item->{url};
 			build_index($hout,$item) if $item->{items};
@@ -91,7 +91,7 @@
 
 process_dir($LibDir);
 
-open my $hout, ">:encoding(utf-8)", "$OutDir/index.html" or die "failed to open index.html for output: $!";
+open my $hout, ">:encoding(utf-8)", "$OutDir/toc.html" or die "failed to open toc.html for output: $!";
 
 print $hout <<HEADER;
 <html>
@@ -109,9 +109,28 @@
 </html>
 FOOTER
 
+undef $hout;
+
+open $hout, ">:encoding(utf-8)","$OutDir/index.html" or die "failed to open index.html for output: $!";
+
+print $hout <<FRAMES;
+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
+<title>IMPL reference</title>
+</head>
+<frameset cols="30%,*">
+	<frame name="toc" src="toc.html"/>
+	<frame name="content" src="about:blank"/>
+</frameset>
+</html>
+FRAMES
+
 package PodViewHTML;
 use base qw(Pod::POM::View::HTML);
 
+use IPC::Open2;
+
 sub view_pod {
     my ($self, $pod) = @_;
     return "<html>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
@@ -121,7 +140,7 @@
 }
 sub view_begin {
 	my ($self,$begin) = @_;
-	$begin->format =~ /code/i ? return "<pre>\n".escape_html(join ("",$begin->text()))."</pre>\n" : return $self->SUPER::view_begin($begin); 
+	return code_highlight(join ("",$begin->content()),$begin->format);
 }
 
 sub escape_html {
@@ -169,3 +188,50 @@
 sub view_seq_code {
 	goto &view_seq_link;
 }
+
+sub view_code {
+	my ($self,$code) = @_;
+	
+	return code_highlight($code);
+}
+
+sub code_highlight {
+	my ($text,$format) = @_;
+	
+	if ($format) {
+		$format =~ s/code//i;
+		$format =~ s/\s+//g;
+	}
+	
+	$format ||= 'perl';
+	
+	return "<pre>".escape_html($text)."</pre>\n" if $format =~ /^text$/i;
+	
+	
+	
+	my ($hin,$hout);
+	local $/ = undef;
+	my $pid = eval { open2(
+		$hin, $hout, highlight => (
+			'--syntax' => $format,
+			'--html',
+			'--fragment',
+			'--inline-css',
+			'--enclose-pre'
+		)
+	) } or return "<pre>".escape_html($text)."</pre>\n";
+	
+	binmode $hout, ':encoding(utf8)';
+	binmode $hin, ':encoding(utf8)';
+	
+	print $hout $text;
+	
+	undef $hout;
+	
+	my $fragment = <$hin>;
+	
+	undef $hin;
+	
+	return $fragment;
+	
+}