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.4 by root, Sun Aug 13 19:47:06 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
4
5# base path of arch tree, only used for new arch graphics
6my $ARCH = "/root/src/cf.schmorp.de/arch";
7
8use strict;
9
3use Storable; 10use Storable;
4
5# convert given .pod files to wiki style
6
7use strict;
8
9use Pod::POM; 11use Pod::POM;
10 12
11our @result; 13our @result;
12our $indent; 14our $indent;
13our $level; 15our $level;
35 s/\s+/ /g; 37 s/\s+/ /g;
36 38
37 $_ 39 $_
38} 40}
39 41
42sub special {
43 $MA_BEG . (join $MA_SEP, @_) . $MA_END
44}
45
40package AsParagraphs; 46package AsParagraphs;
41 47
42use strict; 48use strict;
43 49
44use 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 }
45 64
46*view_seq_file = 65*view_seq_file =
47*view_seq_code = 66*view_seq_code =
48*view_seq_bold = sub { "<b>$_[1]</b>" }; 67*view_seq_bold = sub { "<b>$_[1]</b>" };
49*view_seq_italic = sub { "<i>$_[1]</i>" }; 68*view_seq_italic = sub { "<i>$_[1]</i>" };
50*view_seq_zero = sub { }; 69*view_seq_zero = sub { };
51*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 };
52*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 71*view_seq_index = sub { push @{ $result[-1][P_INDEX] }, $_[1]; "" };
53 72
54sub view_seq_text { 73sub view_seq_text {
55 my $text = $_[1]; 74 my $text = $_[1];
56 $text =~ s/\s+/ /g; 75 $text =~ s/\s+/ /g;
57 ::asxml $text 76 ::asxml $text
58} 77}
59 78
60sub view_seq_link { 79sub view_seq_link {
61 my (undef, $link) = @_; 80 my (undef, $link) = @_;
62 81
63 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 82 $link =~ s/^(.*)\|//
83 or $link =~ /([^\/]*)$/;
84
85 my $text = $1;
64 86
65 if ($link =~ /http:/) { 87 if ($link =~ /http:/) {
66 "<u>" . (::asxml $link) . "</u>" 88 "<u>" . (::asxml $link) . "</u>"
89 } elsif ($link =~ /^\$ARCH\/(.+\....)$/) {
90 my $file = $1;
91
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
103 ::special image => "arch/$file.png", 1;
67 } else { 104 } else {
68 "${MA_BEG}link$MA_SEP$text$MA_SEP$link$MA_END" 105 ::special link => $text, $link
69 }
70}
71
72sub view_item {
73 push @result, {
74 indent => $indent * 8,
75 level => $level,
76 }; 106 }
77 my $title = $_[1]->title->present ($_[0]);
78 $result[-1]{markup} = "$title\n\n" if length $title;
79 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
80 local $level = $level + 1;
81 $_[1]->content->present ($_[0]);
82 ()
83} 107}
84 108
85sub view_verbatim { 109sub view_verbatim {
86 push @result, { 110 push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ];
87 indent => $indent * 16,
88 level => $level,
89 markup => "<tt>" . (::asxml $_[1]) . "</tt>\n",
90 };
91 () 111 ()
92} 112}
93 113
94sub view_textblock { 114sub view_textblock {
95 push @result, { 115 push @result, [ $indent * 16, $level, "$_[1]\n" ];
96 indent => $indent * 16,
97 level => $level,
98 markup => "$_[1]\n",
99 };
100 () 116 ()
101} 117}
102 118
103sub view_head1 { 119sub view_head1 {
104 push @result, { 120 push @result, [ $indent * 16, $level ];
105 indent => $indent * 16,
106 level => $level,
107 };
108 my $title = $_[1]->title->present ($_[0]); 121 my $title = $_[1]->title->present ($_[0]);
109 $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;
110 $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];
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, { 132 push @result, [ $indent * 16, $level ];
118 indent => $indent * 16,
119 level => $level,
120 };
121 my $title = $_[1]->title->present ($_[0]); 133 my $title = $_[1]->title->present ($_[0]);
122 $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;
123 $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];
124 local $level = $level + 1; 138 local $level = $level + 1;
125 $_[1]->content->present ($_[0]); 139 $_[1]->content->present ($_[0]);
126 () 140 ()
127}; 141};
128 142
129sub view_head3 { 143sub view_head3 {
130 push @result, { 144 push @result, [ $indent * 16, $level ];
131 indent => $indent * 16,
132 level => $level,
133 };
134 my $title = $_[1]->title->present ($_[0]); 145 my $title = $_[1]->title->present ($_[0]);
135 $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;
136 $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];
137 local $level = $level + 1; 150 local $level = $level + 1;
138 $_[1]->content->present ($_[0]); 151 $_[1]->content->present ($_[0]);
139 () 152 ()
140}; 153};
141 154
142sub view_over { 155sub view_over {
143 local $indent = $indent + $_[1]->indent; 156 local $indent = $indent + $_[1]->indent;
144 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;
145 $_[1]->content->present ($_[0]); 170 $_[1]->content->present ($_[0]);
146 () 171 ()
147} 172}
148 173
149sub view_for { 174sub view_for {
150 if ($_[1]->format eq "image") { 175 if ($_[1]->format eq "image") {
151 push @result, { 176 push @result, [
152 indent => $indent * 16, 177 $indent * 16,
153 level => $level, 178 $level,
154 markup => "${MA_BEG}image${MA_SEP}pod/" . $_->text . $MA_END, 179 (::special image => "pod/" . $_->text),
155 }; 180 ];
156 } 181 }
182 ()
183}
184
185sub view_begin {
157 () 186 ()
158} 187}
159 188
160sub view { 189sub view {
161 my ($self, $type, $item) = @_; 190 my ($self, $type, $item) = @_;
167 196
168sub as_paragraphs($) { 197sub as_paragraphs($) {
169 my ($pom) = @_; 198 my ($pom) = @_;
170 199
171 local $indent = 0; 200 local $indent = 0;
172 local $level = 1; 201 local $level = 2;
173 local @result = ( { } ); 202 local @result = ( [] );
174 203
175 $pom->present ("AsParagraphs"); 204 $pom->present ("AsParagraphs");
176 205
177 [grep $_->{index} || exists $_->{markup}, @result] 206 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
178} 207}
179 208
180############################################################################# 209#############################################################################
210
211$| = 1;
181 212
182my %wiki; 213my %wiki;
183 214
184sub add_node($) { 215sub add_node($) {
185 my ($node) = @_; 216 my ($node) = @_;
186 217
187 for (@{ $node->{kw} || {} }) { 218 for (@{ $node->[N_KW] || {} }) {
188 push @{$wiki{$_}}, $node; 219 push @{$wiki{$_}}, $node;
189 } 220 }
190} 221}
191 222
192my $root = { 223my $root;
193 kw => ["pod"], 224$root->[N_KW] = ["Documents", "pod"];
194}; 225$root->[N_DOC] = [[0, 0, ::special link => "All Documents", "pod/*"]];
195 226
196for my $path (@ARGV) { 227for my $path (@ARGV) {
197 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname"; 228 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
198 my $base = $1; 229 my $base = $1;
199 my $pom = Pod::POM->new->parse_text (do { 230 my $pom = Pod::POM->new->parse_text (do {
203 <$pod> 234 <$pod>
204 }); 235 });
205 236
206 my $para = as_paragraphs $pom; 237 my $para = as_paragraphs $pom;
207 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
208 my @parent = ( 246 my @parent = ($pod);
209 { parent => $root, kw => [$base], doc => $para, par => 0, level => 0 },
210 );
211 add_node $parent[-1];
212 247
213 for my $idx (0 .. $#$para) { 248 for my $idx (0 .. $#$para) {
214 my $par = $para->[$idx]; 249 my $par = $para->[$idx];
215 250
216 while ($parent[-1]{level} >= $par->{level}) { 251 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
217 pop @parent; 252 pop @parent;
218 } 253 }
219 254
220 if ($par->{index}) { 255 if ($par->[P_INDEX]) {
221 my $node = { 256 my $node;
222 kw => $par->{index}, 257 $node->[N_PARENT] = $parent[-1];
223 parent => $parent[-1], 258 $node->[N_PAR] = $idx;
224 doc => $para, 259 $node->[N_LEVEL] = $par->[P_LEVEL];
225 par => $idx, 260 $node->[N_KW] = $par->[P_INDEX];
226 level => $par->{level}, 261 $node->[N_DOC] = $para;
227 };
228 push @parent, $node; 262 push @parent, $node;
229 add_node $node; 263 add_node $node;
230 } 264 }
231 } 265 }
266
267 add_node $pod;
232} 268}
269
270add_node $root;
233 271
234Storable::nstore \%wiki, "docwiki.pst"; 272Storable::nstore \%wiki, "docwiki.pst";
235 273

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines