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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines