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.8 by root, Mon Aug 14 18:46:08 2006 UTC vs.
Revision 1.19 by root, Mon May 5 17:07:13 2008 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;
46package AsParagraphs; 46package AsParagraphs;
47 47
48use strict; 48use strict;
49 49
50use base "Pod::POM::View"; 50use base "Pod::POM::View";
51
52# nodes (order must stay as it is)
53sub N_PARENT (){ 0 }
54sub N_PAR (){ 1 }
55sub N_LEVEL (){ 2 }
56sub N_KW (){ 3 }
57sub N_DOC (){ 4 }
58
59# paragraphs (order must stay as it is)
60sub P_INDENT (){ 0 }
61sub P_LEVEL (){ 1 }
62sub P_MARKUP (){ 2 }
63sub P_INDEX (){ 3 }
51 64
52*view_seq_file = 65*view_seq_file =
53*view_seq_code = 66*view_seq_code =
54*view_seq_bold = sub { "<b>$_[1]</b>" }; 67*view_seq_bold = sub { "<b>$_[1]</b>" };
55*view_seq_italic = sub { "<i>$_[1]</i>" }; 68*view_seq_italic = sub { "<i>$_[1]</i>" };
56*view_seq_zero = sub { }; 69*view_seq_zero = sub { };
57*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /&#160;/g; $text }; 70*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /&#160;/g; $text };
58*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 71*view_seq_index = sub { push @{ $result[-1][P_INDEX] }, $_[1]; "" };
59 72
60sub view_seq_text { 73sub view_seq_text {
61 my $text = $_[1]; 74 my $text = $_[1];
62 $text =~ s/\s+/ /g; 75 $text =~ s/\s+/ /g;
63 ::asxml $text 76 ::asxml $text
64} 77}
65 78
66sub view_seq_link { 79sub view_seq_link {
67 my (undef, $link) = @_; 80 my (undef, $link) = @_;
68 81
69 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 82 $link =~ s/^(.*)\|//
83 or $link =~ /([^\/]*)$/;
84
85 my $text = $1;
70 86
71 if ($link =~ /http:/) { 87 if ($link =~ /http:/) {
72 "<u>" . (::asxml $link) . "</u>" 88 "<u>" . (::asxml $link) . "</u>"
73 } elsif ($link =~ /^\$ARCH\/(.+)$/) { 89 } elsif ($link =~ /^\$ARCH\/(.+\....)$/) {
74 my $path = $1; 90 my $file = $1;
75 (my $base = $path) =~ s/.*\///; 91
76 -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
77 ::special image => "arch/$base", 1; 103 ::special image => "arch/$file.png", 1;
78 } else { 104 } else {
79 ::special link => $text, $link 105 ::special link => $text, $link
80 } 106 }
81} 107}
82 108
83sub view_item {
84 push @result, {
85 indent => $indent * 8,
86 level => $level,
87 };
88 my $title = $_[1]->title->present ($_[0]);
89 $result[-1]{markup} = "$title\n\n" if length $title;
90 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
91 local $level = $level + 1;
92 $_[1]->content->present ($_[0]);
93 ()
94}
95
96sub view_verbatim { 109sub view_verbatim {
97 push @result, { 110 push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ];
98 indent => $indent * 16,
99 level => $level,
100 markup => "<tt>" . (::asxml $_[1]) . "</tt>\n",
101 };
102 () 111 ()
103} 112}
104 113
105sub view_textblock { 114sub view_textblock {
106 push @result, { 115 push @result, [ $indent * 16, $level, "$_[1]\n" ];
107 indent => $indent * 16,
108 level => $level,
109 markup => "$_[1]\n",
110 };
111 () 116 ()
112} 117}
113 118
114sub view_head1 { 119sub view_head1 {
115 push @result, { 120 push @result, [ $indent * 16, $level ];
116 indent => $indent * 16,
117 level => $level,
118 };
119 my $title = $_[1]->title->present ($_[0]); 121 my $title = $_[1]->title->present ($_[0]);
120 $result[-1]{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;
121 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 123 $title = ::flatten $title;
124 unshift @{ $result[-1][P_INDEX] }, $title
125 if !$result[-1][P_INDEX];
122 local $level = $level + 1; 126 local $level = $level + 1;
123 $_[1]->content->present ($_[0]); 127 $_[1]->content->present ($_[0]);
124 () 128 ()
125}; 129};
126 130
127sub view_head2 { 131sub view_head2 {
128 push @result, { 132 push @result, [ $indent * 16, $level ];
129 indent => $indent * 16,
130 level => $level,
131 };
132 my $title = $_[1]->title->present ($_[0]); 133 my $title = $_[1]->title->present ($_[0]);
133 $result[-1]{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;
134 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 135 $title = ::flatten $title;
136 unshift @{ $result[-1][P_INDEX] }, $title
137 if !$result[-1][P_INDEX];
135 local $level = $level + 1; 138 local $level = $level + 1;
136 $_[1]->content->present ($_[0]); 139 $_[1]->content->present ($_[0]);
137 () 140 ()
138}; 141};
139 142
140sub view_head3 { 143sub view_head3 {
141 push @result, { 144 push @result, [ $indent * 16, $level ];
142 indent => $indent * 16,
143 level => $level,
144 };
145 my $title = $_[1]->title->present ($_[0]); 145 my $title = $_[1]->title->present ($_[0]);
146 $result[-1]{markup} = "\n\n<span size='large'>$title</span>\n" if length $title; 146 $result[-1][P_MARKUP] = ::special h3 => $title if length $title;
147 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 147 $title = ::flatten $title;
148 unshift @{ $result[-1][P_INDEX] || [] }, $title
149 if !$result[-1][P_INDEX];
148 local $level = $level + 1; 150 local $level = $level + 1;
149 $_[1]->content->present ($_[0]); 151 $_[1]->content->present ($_[0]);
150 () 152 ()
151}; 153};
152 154
153sub view_over { 155sub view_over {
154 local $indent = $indent + $_[1]->indent; 156 local $indent = $indent + $_[1]->indent;
155 push @result, { indent => $indent }; 157 push @result, [ $indent, $level ];
158 $_[1]->content->present ($_[0]);
159 ()
160}
161
162sub view_item {
163 push @result, [ $indent * 8, $level ];
164 my $title = $_[1]->title->present ($_[0]);
165 $result[-1][P_MARKUP] = "$title\n" if length $title;
166 $title = ::flatten $title;
167 unshift @{ $result[-1][P_INDEX] || [] }, $title
168 if !$result[-1][P_INDEX];
169 local $level = $level + 1;
156 $_[1]->content->present ($_[0]); 170 $_[1]->content->present ($_[0]);
157 () 171 ()
158} 172}
159 173
160sub view_for { 174sub view_for {
161 if ($_[1]->format eq "image") { 175 if ($_[1]->format eq "image") {
162 push @result, { 176 push @result, [
163 indent => $indent * 16, 177 $indent * 16,
164 level => $level, 178 $level,
165 markup => (::special image => "pod/" . $_->text), 179 (::special image => "pod/" . $_->text),
166 }; 180 ];
167 } 181 }
182 ()
183}
184
185sub view_begin {
168 () 186 ()
169} 187}
170 188
171sub view { 189sub view {
172 my ($self, $type, $item) = @_; 190 my ($self, $type, $item) = @_;
178 196
179sub as_paragraphs($) { 197sub as_paragraphs($) {
180 my ($pom) = @_; 198 my ($pom) = @_;
181 199
182 local $indent = 0; 200 local $indent = 0;
183 local $level = 1; 201 local $level = 2;
184 local @result = ( { } ); 202 local @result = ( [] );
185 203
186 $pom->present ("AsParagraphs"); 204 $pom->present ("AsParagraphs");
187 205
188 [grep $_->{index} || exists $_->{markup}, @result] 206 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
189} 207}
190 208
191############################################################################# 209#############################################################################
210
211$| = 1;
192 212
193my %wiki; 213my %wiki;
194 214
195sub add_node($) { 215sub add_node($) {
196 my ($node) = @_; 216 my ($node) = @_;
197 217
198 for (@{ $node->{kw} || {} }) { 218 for (@{ $node->[N_KW] || {} }) {
199 push @{$wiki{lc $_}}, $node; 219 push @{$wiki{$_}}, $node;
200 } 220 }
201} 221}
202 222
203my $root = { 223my $root;
204 kw => ["pod"], 224$root->[N_KW] = ["Documents", "pod"];
205}; 225$root->[N_DOC] = [[0, 0, ::special link => "All Documents", "pod/*"]];
206 226
207for my $path (@ARGV) { 227for my $path (@ARGV) {
208 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname"; 228 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
209 my $base = $1; 229 my $base = $1;
210 my $pom = Pod::POM->new->parse_text (do { 230 my $pom = Pod::POM->new->parse_text (do {
214 <$pod> 234 <$pod>
215 }); 235 });
216 236
217 my $para = as_paragraphs $pom; 237 my $para = as_paragraphs $pom;
218 238
239 my $pod;
240 $pod->[N_PARENT] = $root;
241 $pod->[N_PAR] = 0;
242 $pod->[N_LEVEL] = 1;
243 $pod->[N_KW] = [$base];
244 $pod->[N_DOC] = $para;
245
219 my @parent = ( 246 my @parent = ($pod);
220 { parent => $root, kw => [$base], doc => $para, par => 0, level => 0 },
221 );
222 add_node $parent[-1];
223 247
224 for my $idx (0 .. $#$para) { 248 for my $idx (0 .. $#$para) {
225 my $par = $para->[$idx]; 249 my $par = $para->[$idx];
226 250
227 while ($parent[-1]{level} >= $par->{level}) { 251 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
228 pop @parent; 252 pop @parent;
229 } 253 }
230 254
231 if ($par->{index}) { 255 if ($par->[P_INDEX]) {
232 my $node = { 256 my $node;
233 kw => $par->{index}, 257 $node->[N_PARENT] = $parent[-1];
234 parent => $parent[-1], 258 $node->[N_PAR] = $idx;
235 doc => $para, 259 $node->[N_LEVEL] = $par->[P_LEVEL];
236 par => $idx, 260 $node->[N_KW] = $par->[P_INDEX];
237 level => $par->{level}, 261 $node->[N_DOC] = $para;
238 };
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines