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