tools
[sdlgit/SDL-Site.git] / tools / PM-Pod2html-snippet.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use File::Spec;
7 use Pod::Xhtml;
8
9 #system('git pull');
10
11 my $input_path   = 'C:/SDL_perl/lib/pods';
12 my $output_path  = 'F:/htdocs/SDL-Site/pages';
13 my $parser       = Pod::Xhtml->new(FragmentOnly => 1);
14 my %module_names = ();
15 my $fh;
16
17 read_file($input_path);
18
19 # creating index file
20 open($fh, '>', File::Spec->catfile($output_path, 'documentation.html-inc'));
21 binmode($fh, ":utf8");
22 print($fh "<div class=\"pod\">\n<h1>Documentation (latest development branch)</h1>");
23 for my $module_name (sort keys %module_names)
24 {
25         print($fh '<a href="' . $module_names{$module_name} . '">',
26                   $module_name, 
27                   '</a><br />'
28         );
29 }
30 print($fh "</div>\n");
31 close($fh);
32
33 sub read_file
34 {
35         my $path = shift;
36         my @files      = <$path/*>;
37
38         foreach(@files)
39         {
40                 read_file($_) if(-d $_);
41
42                 if($_ =~ /\.pod$/i)
43                 {
44                         my $file_name   = $_;
45                            $file_name   =~ s/^$input_path\/*//;
46                         my $module_name = $file_name;
47                            $module_name =~ s/\//::/g;
48                            $module_name =~ s/(\.pm|\.pod)$//i;
49                            $file_name   =~ s/\//-/g;
50                            $file_name   =~ s/(\.pm|\.pod)$/.html-inc/i;
51                         my $file_path   = $file_name;
52                            $file_path   =~ s/\-inc$//;
53                         $module_names{$module_name} = $file_path;
54                            $file_name   = File::Spec->catfile($output_path, $file_name);
55
56                         $parser->parse_from_file($_, $file_name);
57                 }
58         }
59 }