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 = (); |
bfdd9c2e |
22 | my %files = (); |
b3ef54ec |
23 | my $fh; |
24 | |
25 | read_file($input_path); |
26 | |
27 | # creating index file |
cbc85b7f |
28 | open($fh, '>', File::Spec->catfile($pages_path, 'documentation.html-inc')); |
b3ef54ec |
29 | binmode($fh, ":utf8"); |
bfdd9c2e |
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) |
b3ef54ec |
34 | { |
bfdd9c2e |
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)); |
38 | |
39 | my @matches = ( $files{$key}{'section'} =~ m/\w+/xg ); |
9f2a2b91 |
40 | |
bfdd9c2e |
41 | if($last_section ne $files{$key}{'section'}) |
9f2a2b91 |
42 | { |
bfdd9c2e |
43 | print ($fh '</table>') if $last_section; |
44 | print ($fh '<br />') if $last_section && !$#matches; |
33a96b1f |
45 | printf($fh '<table style="margin-left: %dpx; margin-top: 5px"><tr><td colspan="3"><strong style="font-size: 14px">%s</strong></td></tr>', |
bfdd9c2e |
46 | $#matches * 30, pop(@matches)); |
47 | $last_section = $files{$key}{'section'}; |
9f2a2b91 |
48 | } |
49 | |
50 | printf($fh '<tr><td>%s</td><td><a href="%s">%s</a></td><td>%s</td></tr>', |
bfdd9c2e |
51 | $icon, $files{$key}{'path'}, $files{$key}{'name'}, $files{$key}{'desc'}); |
b3ef54ec |
52 | } |
9f2a2b91 |
53 | print($fh "</table></div>\n"); |
b3ef54ec |
54 | close($fh); |
55 | |
56 | sub read_file |
57 | { |
58 | my $path = shift; |
59 | my @files = <$path/*>; |
60 | |
61 | foreach(@files) |
62 | { |
63 | read_file($_) if(-d $_); |
b3ef54ec |
64 | if($_ =~ /\.pod$/i) |
65 | { |
bfdd9c2e |
66 | my $key = ''; |
9f2a2b91 |
67 | my $file_name = $_; |
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); |
78 | |
9f2a2b91 |
79 | |
bfdd9c2e |
80 | |
81 | $key = $parser->asString =~ /<div id="CATEGORY_CONTENT">\s*<p>\s*([^<>]+)\s*<\/p>\s*<\/div>/ |
82 | ? "$1 $_" |
83 | : "UNCATEGORIZED/$_"; |
60f74f6f |
84 | $key = " $key" if $key =~ /^Core/; |
bfdd9c2e |
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>/ |
88 | ? $1 |
89 | : ''; |
90 | $files{$key}{'section'} = $parser->asString =~ /<div id="CATEGORY_CONTENT">\s*<p>\s*([^<>]+)\s*<\/p>\s*<\/div>/ |
91 | ? $1 |
92 | : 'UNCATEGORIZED'; |
9f2a2b91 |
93 | |
94 | # handling images |
cbc85b7f |
95 | my $image_path = $_; |
96 | $image_path =~ s/\.pod$//; |
97 | my @images = <$image_path*>; |
98 | |
99 | my $image_html = ''; |
100 | |
101 | foreach my $image_file (@images) |
102 | { |
9f2a2b91 |
103 | if($image_file =~ /^($image_path)(_\w+){0,1}\.(jpg|jpeg|png|gif)$/) |
cbc85b7f |
104 | { |
105 | my (undef, undef, $image_file_name) = splitpath($image_file); |
106 | |
9f2a2b91 |
107 | if($image_file_name =~ /_thumb\.(jpg|jpeg|png|gif)$/) |
108 | { |
bfdd9c2e |
109 | $files{$key}{'thumb'} = $image_file_name; |
9f2a2b91 |
110 | } |
111 | else |
112 | { |
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); |
116 | } |
117 | |
cbc85b7f |
118 | copy($image_file, File::Spec->catfile($assets_path, $image_file_name)); |
119 | } |
120 | } |
121 | |
cbc85b7f |
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; |
125 | |
126 | open($fh, '>', $file_name); |
127 | binmode($fh, ":utf8"); |
128 | print($fh $html); |
129 | close($fh); |
b3ef54ec |
130 | } |
131 | } |
132 | } |