8 use File::Spec::Functions qw(rel2abs splitpath splitdir catpath catdir catfile canonpath);
10 my $input_path = 'C:/SDL_perl/lib/pods';
11 $input_path = $ARGV[0] if $ARGV[0];
13 my ($volume, $dirs) = splitpath(rel2abs(__FILE__));
14 my @directories = splitdir(canonpath($dirs));
16 my $parent_dir = catpath($volume, catdir(@directories));
17 my $pages_path = catdir($parent_dir, 'pages');
18 my $assets_path = catdir($parent_dir, 'htdocs/assets');
19 my $parser = Pod::Xhtml->new(FragmentOnly => 1, StringMode => 1);
20 my %module_names = ();
25 read_file($input_path);
28 open($fh, '>', File::Spec->catfile($pages_path, 'documentation.html-inc'));
29 binmode($fh, ":utf8");
30 print($fh "<div class=\"pod\">\n<h1>Documentation (latest development branch)</h1>");
31 my $last_section = '';
32 #for my $module_name (sort keys %module_names)
33 for my $key (sort keys %files)
35 my $icon = defined $files{$key}{'thumb'}
36 ? sprintf('<img src="assets/%s" alt="thumb" />', $files{$key}{'thumb'})
37 : sprintf('<img src="assets/bubble-%d-mini.png" alt="thumb" />', int((rand() * 7) + 1));
39 my @matches = ( $files{$key}{'section'} =~ m/\w+/xg );
41 if($last_section ne $files{$key}{'section'})
43 print ($fh '</table>') if $last_section;
44 print ($fh '<br />') if $last_section && !$#matches;
45 printf($fh '<table style="padding-left: %dpx; padding-top: 5px"><tr><td colspan="3"><strong style="font-size: 14px">%s</strong></td></tr>',
46 $#matches * 30, pop(@matches));
47 $last_section = $files{$key}{'section'};
50 printf($fh '<tr><td>%s</td><td><a href="%s">%s</a></td><td>%s</td></tr>',
51 $icon, $files{$key}{'path'}, $files{$key}{'name'}, $files{$key}{'desc'});
53 print($fh "</table></div>\n");
59 my @files = <$path/*>;
63 read_file($_) if(-d $_);
68 $file_name =~ s/^$input_path\/*//;
69 my $module_name = $file_name;
70 $module_name =~ s/\//::/g;
71 $module_name =~ s/(\.pm|\.pod)$//i;
72 $file_name =~ s/\//-/g;
73 $file_name =~ s/(\.pm|\.pod)$/.html-inc/i;
74 my $file_path = $file_name;
75 $file_path =~ s/\-inc$//;
76 $file_name = File::Spec->catfile($pages_path, $file_name);
77 $parser->parse_from_file($_); #, $file_name);
81 $key = $parser->asString =~ /<div id="CATEGORY_CONTENT">\s*<p>\s*([^<>]+)\s*<\/p>\s*<\/div>/
84 $key = " $key" if $key =~ /^Core/;
85 $files{$key}{'path'} = $file_path;
86 $files{$key}{'name'} = $module_name;
87 $files{$key}{'desc'} = $parser->asString =~ /<div id="NAME_CONTENT">\s*<p>\s*[^<>\-]+\-([^<>]+)\s*<\/p>\s*<\/div>/
90 $files{$key}{'section'} = $parser->asString =~ /<div id="CATEGORY_CONTENT">\s*<p>\s*([^<>]+)\s*<\/p>\s*<\/div>/
96 $image_path =~ s/\.pod$//;
97 my @images = <$image_path*>;
101 foreach my $image_file (@images)
103 if($image_file =~ /^($image_path)(_\w+){0,1}\.(jpg|jpeg|png|gif)$/)
105 my (undef, undef, $image_file_name) = splitpath($image_file);
107 if($image_file_name =~ /_thumb\.(jpg|jpeg|png|gif)$/)
109 $files{$key}{'thumb'} = $image_file_name;
113 $image_html .= sprintf('<a href="assets/%s" target="_blank">'
114 . '<img src="assets/%s" style="height: 160px" alt="%s"/>'
115 . '</a>', $image_file_name, $image_file_name, $image_file_name);
118 copy($image_file, File::Spec->catfile($assets_path, $image_file_name));
122 # modifying the html-snippet and insert the images
123 my $html = $parser->asString;
124 $html =~ s/<!-- INDEX END -->/<!-- INDEX END -->$image_html<hr \/>/ if $image_html;
126 open($fh, '>', $file_name);
127 binmode($fh, ":utf8");