Commit | Line | Data |
b3ef54ec |
1 | #!/usr/bin/env perl |
2 | |
3 | use strict; |
4 | use warnings; |
35f7648e |
5 | use Carp; |
b3ef54ec |
6 | use Pod::Xhtml; |
cbc85b7f |
7 | use File::Copy; |
de71a5b8 |
8 | use File::Spec::Functions qw(rel2abs splitpath splitdir catpath catdir catfile canonpath); |
4e1ad99d |
9 | |
de71a5b8 |
10 | my $input_path = 'C:/SDL_perl/lib/pods'; |
35f7648e |
11 | $input_path = $ARGV[0] if $ARGV[0]; |
4e1ad99d |
12 | |
de71a5b8 |
13 | my ($volume, $dirs) = splitpath(rel2abs(__FILE__)); |
14 | my @directories = splitdir(canonpath($dirs)); |
15 | pop(@directories); |
16 | my $parent_dir = catpath($volume, catdir(@directories)); |
cbc85b7f |
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); |
de71a5b8 |
20 | my %module_names = (); |
9f2a2b91 |
21 | my %thumbnails = (); |
b3ef54ec |
22 | my $fh; |
23 | |
24 | read_file($input_path); |
25 | |
26 | # creating index file |
cbc85b7f |
27 | open($fh, '>', File::Spec->catfile($pages_path, 'documentation.html-inc')); |
b3ef54ec |
28 | binmode($fh, ":utf8"); |
9f2a2b91 |
29 | print($fh "<div class=\"pod\">\n<h1>Documentation (latest development branch)</h1><table>"); |
b3ef54ec |
30 | for my $module_name (sort keys %module_names) |
31 | { |
9f2a2b91 |
32 | my $icon = sprintf('<img src="assets/bubble-%d-mini.png" alt="thumb" />', int((rand() * 7) + 1)); |
33 | my $name = $module_name; |
34 | my $desc = ''; |
35 | |
36 | if($module_name =~ /^([^\-]+)\-(.+)$/) |
37 | { |
38 | $name = $1; |
39 | $desc = $2; |
40 | } |
41 | |
42 | if(defined $thumbnails{$module_name}) |
43 | { |
44 | $icon = sprintf('<img src="assets/%s" alt="thumb" />', $thumbnails{$module_name}); |
45 | } |
46 | |
47 | printf($fh '<tr><td>%s</td><td><a href="%s">%s</a></td><td>%s</td></tr>', |
48 | $icon, $module_names{$module_name}, $name, $desc); |
b3ef54ec |
49 | } |
9f2a2b91 |
50 | print($fh "</table></div>\n"); |
b3ef54ec |
51 | close($fh); |
52 | |
53 | sub read_file |
54 | { |
55 | my $path = shift; |
56 | my @files = <$path/*>; |
57 | |
58 | foreach(@files) |
59 | { |
60 | read_file($_) if(-d $_); |
b3ef54ec |
61 | if($_ =~ /\.pod$/i) |
62 | { |
9f2a2b91 |
63 | my $file_name = $_; |
64 | $file_name =~ s/^$input_path\/*//; |
65 | my $module_name = $file_name; |
66 | $module_name =~ s/\//::/g; |
67 | $module_name =~ s/(\.pm|\.pod)$//i; |
68 | $file_name =~ s/\//-/g; |
69 | $file_name =~ s/(\.pm|\.pod)$/.html-inc/i; |
70 | my $file_path = $file_name; |
71 | $file_path =~ s/\-inc$//; |
72 | $file_name = File::Spec->catfile($pages_path, $file_name); |
73 | $parser->parse_from_file($_); #, $file_name); |
74 | |
75 | $module_name .= " - $1" if $parser->asString =~ /<div id="NAME_CONTENT">\s*<p>\s*[^<>\-]+\-([^<>]+)\s*<\/p>\s*<\/div>/; |
76 | |
77 | $module_names{$module_name} = $file_path; |
78 | |
79 | # handling images |
cbc85b7f |
80 | my $image_path = $_; |
81 | $image_path =~ s/\.pod$//; |
82 | my @images = <$image_path*>; |
83 | |
84 | my $image_html = ''; |
85 | |
86 | foreach my $image_file (@images) |
87 | { |
9f2a2b91 |
88 | if($image_file =~ /^($image_path)(_\w+){0,1}\.(jpg|jpeg|png|gif)$/) |
cbc85b7f |
89 | { |
90 | my (undef, undef, $image_file_name) = splitpath($image_file); |
91 | |
9f2a2b91 |
92 | if($image_file_name =~ /_thumb\.(jpg|jpeg|png|gif)$/) |
93 | { |
94 | $thumbnails{$module_name} = $image_file_name; |
95 | } |
96 | else |
97 | { |
98 | $image_html .= sprintf('<a href="assets/%s" target="_blank">' |
99 | . '<img src="assets/%s" style="height: 160px" alt="%s"/>' |
100 | . '</a>', $image_file_name, $image_file_name, $image_file_name); |
101 | } |
102 | |
cbc85b7f |
103 | copy($image_file, File::Spec->catfile($assets_path, $image_file_name)); |
104 | } |
105 | } |
106 | |
cbc85b7f |
107 | # modifying the html-snippet and insert the images |
108 | my $html = $parser->asString; |
109 | $html =~ s/<!-- INDEX END -->/<!-- INDEX END -->$image_html<hr \/>/ if $image_html; |
110 | |
111 | open($fh, '>', $file_name); |
112 | binmode($fh, ":utf8"); |
113 | print($fh $html); |
114 | close($fh); |
b3ef54ec |
115 | } |
116 | } |
117 | } |