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