ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pod2wiki
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pod2wiki (file contents):
Revision 1.13 by root, Sun Mar 30 04:59:43 2008 UTC vs.
Revision 1.20 by root, Mon Jun 21 22:51:58 2010 UTC

1#! perl 1#! perl
2 2
3# convert given .pod files to wiki style 3# convert given .pod files to wiki style
4 4
5# base path of arch tree, only used for new arch graphics 5# base path of arch tree, only used for new arch graphics
6my $ARCH = "/root/devel/cvs/cf.schmorp.de/arch"; 6my $ARCH = "/root/src/cf.schmorp.de/arch";
7 7
8use strict; 8use strict;
9 9
10use Storable; 10use Storable;
11use Pod::POM; 11use Pod::POM;
77} 77}
78 78
79sub view_seq_link { 79sub view_seq_link {
80 my (undef, $link) = @_; 80 my (undef, $link) = @_;
81 81
82 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 82 $link =~ s/^(.*)\|//
83 or $link =~ /([^\/]*)$/;
84
85 my $text = $1;
83 86
84 if ($link =~ /http:/) { 87 if ($link =~ /http:/) {
85 "<u>" . (::asxml $link) . "</u>" 88 "<u>" . (::asxml $link) . "</u>"
86 } elsif ($link =~ /^\$ARCH\/(.+)$/) { 89 } elsif ($link =~ /^\$ARCH\/(.+\....)$/) {
87 my $path = $1; 90 my $file = $1;
88 (my $base = $path) =~ s/.*\///; 91
89 -f "$ARCH/$path" && system "rsync -av -c \Q$ARCH/$path\E \Qresources/arch/$base"; 92 unless (-f "resources/arch/$file.png") {
93 print "ARCHIMG $file is missing, trying to supply... ";
94 my ($path) = split /\x00/, qx<find \Q$ARCH\E -name \Q$file.64x64.png*\E -print0>;
95 -f $path or die "$file: could not find arch image";
96 print "$path\n";
97 system "rsync -a \Q$path\E resources/arch/\Q$file.png"
98 and die "rsync failed: $?";
99 system "cvs add -kb resources/arch/\Q$file.png"
100 and ((unlink "resources/arch/$file.png"), die "cvs add failed: $?");
101 }
102
90 ::special image => "arch/$base", 1; 103 ::special image => "arch/$file.png", 1;
91 } else { 104 } else {
92 ::special link => $text, $link 105 ::special link => $text, $link
93 } 106 }
94} 107}
95 108
104} 117}
105 118
106sub view_head1 { 119sub view_head1 {
107 push @result, [ $indent * 16, $level ]; 120 push @result, [ $indent * 16, $level ];
108 my $title = $_[1]->title->present ($_[0]); 121 my $title = $_[1]->title->present ($_[0]);
109 $result[-1][P_MARKUP] = "\n\n<span foreground='#ffff00' size='x-large'>$title</span>\n" if length $title; 122 $result[-1][P_MARKUP] = ::special h1 => $title if length $title;
110 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; 123 $title = ::flatten $title;
124 unshift @{ $result[-1][P_INDEX] }, $title
125 if !$result[-1][P_INDEX];
111 local $level = $level + 1; 126 local $level = $level + 1;
112 $_[1]->content->present ($_[0]); 127 $_[1]->content->present ($_[0]);
113 () 128 ()
114}; 129};
115 130
116sub view_head2 { 131sub view_head2 {
117 push @result, [ $indent * 16, $level ]; 132 push @result, [ $indent * 16, $level ];
118 my $title = $_[1]->title->present ($_[0]); 133 my $title = $_[1]->title->present ($_[0]);
119 $result[-1][P_MARKUP] = "\n\n<span foreground='#ccccff' size='large'>$title</span>\n" if length $title; 134 $result[-1][P_MARKUP] = ::special h2 => $title if length $title;
120 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; 135 $title = ::flatten $title;
136 unshift @{ $result[-1][P_INDEX] }, $title
137 if !$result[-1][P_INDEX];
121 local $level = $level + 1; 138 local $level = $level + 1;
122 $_[1]->content->present ($_[0]); 139 $_[1]->content->present ($_[0]);
123 () 140 ()
124}; 141};
125 142
126sub view_head3 { 143sub view_head3 {
127 push @result, [ $indent * 16, $level ]; 144 push @result, [ $indent * 16, $level ];
128 my $title = $_[1]->title->present ($_[0]); 145 my $title = $_[1]->title->present ($_[0]);
129 $result[-1][P_MARKUP] = "\n\n<span size='large'>$title</span>\n" if length $title; 146 $result[-1][P_MARKUP] = ::special h3 => $title if length $title;
130 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; 147 $title = ::flatten $title;
148 unshift @{ $result[-1][P_INDEX] || [] }, $title
149 if !$result[-1][P_INDEX];
131 local $level = $level + 1; 150 local $level = $level + 1;
132 $_[1]->content->present ($_[0]); 151 $_[1]->content->present ($_[0]);
133 () 152 ()
134}; 153};
135 154
142 161
143sub view_item { 162sub view_item {
144 push @result, [ $indent * 8, $level ]; 163 push @result, [ $indent * 8, $level ];
145 my $title = $_[1]->title->present ($_[0]); 164 my $title = $_[1]->title->present ($_[0]);
146 $result[-1][P_MARKUP] = "$title\n" if length $title; 165 $result[-1][P_MARKUP] = "$title\n" if length $title;
147 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; 166 $title = ::flatten $title;
167 unshift @{ $result[-1][P_INDEX] || [] }, $title
168 if !$result[-1][P_INDEX];
148 local $level = $level + 1; 169 local $level = $level + 1;
149 $_[1]->content->present ($_[0]); 170 $_[1]->content->present ($_[0]);
150 () 171 ()
151} 172}
152 173
185 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result] 206 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
186} 207}
187 208
188############################################################################# 209#############################################################################
189 210
211$| = 1;
212
190my %wiki; 213my %wiki;
191 214
192sub add_node($) { 215sub add_node($) {
193 my ($node) = @_; 216 my ($node) = @_;
194 217
195 for (@{ $node->[N_KW] || {} }) { 218 for (@{ $node->[N_KW] || {} }) {
196 push @{$wiki{lc $_}}, $node; 219 push @{$wiki{$_}}, $node;
197 } 220 }
198} 221}
199 222
200my $root; 223my $root;
201$root->[N_KW] = ["pod"]; 224$root->[N_KW] = ["Documents", "pod"];
225$root->[N_DOC] = [[0, 0, ::special link => "All Documents", "pod/*"]];
202 226
203for my $path (@ARGV) { 227for my $path (@ARGV) {
204 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname"; 228 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
205 my $base = $1; 229 my $base = $1;
206 my $pom = Pod::POM->new->parse_text (do { 230 my $pom = Pod::POM->new->parse_text (do {
207 local $/; 231 local $/;
208 open my $pod, "<:utf8", $path 232 open my $pod, "<:perlio", $path
209 or die "$path: $!"; 233 or die "$path: $!";
210 <$pod> 234 <$pod>
211 }); 235 });
212 236
213 my $para = as_paragraphs $pom; 237 my $para = as_paragraphs $pom;
218 $pod->[N_LEVEL] = 1; 242 $pod->[N_LEVEL] = 1;
219 $pod->[N_KW] = [$base]; 243 $pod->[N_KW] = [$base];
220 $pod->[N_DOC] = $para; 244 $pod->[N_DOC] = $para;
221 245
222 my @parent = ($pod); 246 my @parent = ($pod);
223 add_node $pod;
224 247
225 for my $idx (0 .. $#$para) { 248 for my $idx (0 .. $#$para) {
226 my $par = $para->[$idx]; 249 my $par = $para->[$idx];
227 250
228 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) { 251 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
238 $node->[N_DOC] = $para; 261 $node->[N_DOC] = $para;
239 push @parent, $node; 262 push @parent, $node;
240 add_node $node; 263 add_node $node;
241 } 264 }
242 } 265 }
266
267 add_node $pod;
243} 268}
269
270add_node $root;
244 271
245Storable::nstore \%wiki, "docwiki.pst"; 272Storable::nstore \%wiki, "docwiki.pst";
246 273
247add_node $root;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines