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