annotate _doc/make.pl @ 64:259cd3df6e53

Doc generation Minor fixes
author wizard
date Mon, 15 Mar 2010 17:45:13 +0300
parents
children 2840c4c85db8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
64
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
1 #!/usr/bin/perl -w
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
2 use strict;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
3
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
4 use Pod::POM;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
5 use Pod::POM::View::HTML;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
6 use File::Spec;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
7
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
8 our $LibDir = '../Lib/IMPL';
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
9 our $OutDir = 'html';
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
10
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
11 our $index = { name => 'root' };
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
12
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
13 sub process_file {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
14 my ($fname,@path) = @_;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
15
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
16 (my $name = $path[$#path]) =~ s/\.pm$//;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
17
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
18 (my $fileUrl = File::Spec->catfile(@path)) =~ s/\.pm$/.html/i;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
19
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
20 $index->{items}{$name}{name} = $name;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
21 $index->{items}{$name}{url} = $fileUrl;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
22
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
23 (my $fnameOut = File::Spec->catfile($OutDir,@path)) =~ s/\.pm$/.html/i;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
24
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
25 my $dir =$OutDir;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
26 foreach my $part (@path[0..$#path-1]) {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
27 $dir = File::Spec->catdir($dir,$part);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
28 mkdir $dir unless -d $dir;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
29 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
30
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
31 open my $hPod, "<:encoding(cp1251)", $fname or die "Failed to open $fname for input: $!";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
32 open my $hOut, ">:encoding(utf-8)", $fnameOut or die "Failed to open $fnameOut for output: $!";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
33
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
34 my $parser = Pod::POM->new( );
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
35
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
36 my $pom = $parser->parse_file($hPod);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
37
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
38 print $hOut PodViewHTML->print($pom);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
39 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
40
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
41 sub process_dir {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
42 my ($dirname,@dirs) = @_;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
43
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
44 opendir my $hdir, $dirname or die "faield to open dir $dirname: $!";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
45
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
46 foreach my $entry (readdir $hdir) {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
47 next if grep $_ eq $entry, '.','..';
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
48
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
49 my $path = "$dirname/$entry";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
50
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
51 print "$path";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
52
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
53 if (-d $path) {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
54 print "\n";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
55 local $index = exists $index->{items}{$entry} ? $index->{items}{$entry} : ($index->{items}{$entry} = {name => $entry});
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
56 process_dir($path,@dirs,$entry);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
57 } elsif ($entry =~ /\.(pm|pod)$/) {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
58 print "\tprocessed\n";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
59 process_file($path,@dirs,$entry);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
60 } else {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
61 print "\tskipped\n";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
62 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
63 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
64 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
65
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
66 sub build_index {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
67 my ($hout,$index) = @_;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
68
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
69 print $hout "\n<ul>\n";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
70
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
71 if ($index->{items}) {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
72 foreach my $itemKey (sort keys %{$index->{items}}) {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
73 my $item = $index->{items}{$itemKey};
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
74 print $hout "<li>";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
75 print $hout "<a href='$item->{url}'>" if $item->{url};
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
76 print $hout $item->{name};
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
77 print $hout "</a>" if $item->{url};
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
78 build_index($hout,$item) if $item->{items};
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
79 print $hout "</li>\n";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
80 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
81 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
82
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
83 print $hout "</ul>\n";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
84 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
85
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
86 `rm -r html`;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
87 mkdir 'html' unless -d 'html';
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
88
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
89 process_dir($LibDir);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
90
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
91 open my $hout, ">:encoding(utf-8)", "$OutDir/index.html" or die "failed to open index.html for output: $!";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
92
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
93 print $hout <<HEADER;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
94 <html>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
95 <head>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
96 <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
97 <title>IMPL reference</title>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
98 </head>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
99 <body>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
100 HEADER
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
101
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
102 build_index($hout,$index);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
103
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
104 print $hout <<FOOTER;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
105 </body>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
106 </html>
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
107 FOOTER
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
108
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
109 package PodViewHTML;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
110 use base qw(Pod::POM::View::HTML);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
111
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
112 sub view_pod {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
113 my ($self, $pod) = @_;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
114 return "<html>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
115 \n<body bgcolor=\"#ffffff\">\n"
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
116 . $pod->content->present($self)
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
117 . "</body>\n</html>\n";
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
118 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
119 sub view_begin {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
120 my ($self,$begin) = @_;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
121 $begin->format =~ /code/i ? return "<pre>\n".join ("",$begin->text())."</pre>\n" : return $self->SUPER::view_begin($begin);
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
122 }
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
123
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
124 sub view_seq_link {
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
125 my ($self,$text) = @_;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
126
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
127 $text->text =~ /(?:(\w+)\s+)(\w+(?:\:\:\w+)*)/;
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
128
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
129
259cd3df6e53 Doc generation
wizard
parents:
diff changeset
130 }