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.10 by root, Sat Sep 9 23:31:58 2006 UTC vs.
Revision 1.17 by root, Wed Apr 2 13:27:55 2008 UTC

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 $path = $1;
78 } else { 94 } else {
79 ::special link => $text, $link 95 ::special link => $text, $link
80 } 96 }
81} 97}
82 98
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" 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 { 99sub view_verbatim {
97 push @result, { 100 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 () 101 ()
103} 102}
104 103
105sub view_textblock { 104sub view_textblock {
106 push @result, { 105 push @result, [ $indent * 16, $level, "$_[1]\n" ];
107 indent => $indent * 16,
108 level => $level,
109 markup => "$_[1]\n",
110 };
111 () 106 ()
112} 107}
113 108
114sub view_head1 { 109sub view_head1 {
115 push @result, { 110 push @result, [ $indent * 16, $level ];
116 indent => $indent * 16,
117 level => $level,
118 };
119 my $title = $_[1]->title->present ($_[0]); 111 my $title = $_[1]->title->present ($_[0]);
120 $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;
121 $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];
122 local $level = $level + 1; 116 local $level = $level + 1;
123 $_[1]->content->present ($_[0]); 117 $_[1]->content->present ($_[0]);
124 () 118 ()
125}; 119};
126 120
127sub view_head2 { 121sub view_head2 {
128 push @result, { 122 push @result, [ $indent * 16, $level ];
129 indent => $indent * 16,
130 level => $level,
131 };
132 my $title = $_[1]->title->present ($_[0]); 123 my $title = $_[1]->title->present ($_[0]);
133 $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;
134 $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];
135 local $level = $level + 1; 128 local $level = $level + 1;
136 $_[1]->content->present ($_[0]); 129 $_[1]->content->present ($_[0]);
137 () 130 ()
138}; 131};
139 132
140sub view_head3 { 133sub view_head3 {
141 push @result, { 134 push @result, [ $indent * 16, $level ];
142 indent => $indent * 16,
143 level => $level,
144 };
145 my $title = $_[1]->title->present ($_[0]); 135 my $title = $_[1]->title->present ($_[0]);
146 $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;
147 $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];
148 local $level = $level + 1; 140 local $level = $level + 1;
149 $_[1]->content->present ($_[0]); 141 $_[1]->content->present ($_[0]);
150 () 142 ()
151}; 143};
152 144
153sub view_over { 145sub view_over {
154 local $indent = $indent + $_[1]->indent; 146 local $indent = $indent + $_[1]->indent;
155 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;
156 $_[1]->content->present ($_[0]); 160 $_[1]->content->present ($_[0]);
157 () 161 ()
158} 162}
159 163
160sub view_for { 164sub view_for {
161 if ($_[1]->format eq "image") { 165 if ($_[1]->format eq "image") {
162 push @result, { 166 push @result, [
163 indent => $indent * 16, 167 $indent * 16,
164 level => $level, 168 $level,
165 markup => (::special image => "pod/" . $_->text), 169 (::special image => "pod/" . $_->text),
166 }; 170 ];
167 } 171 }
168 () 172 ()
169} 173}
170 174
171sub view_begin { 175sub view_begin {
182 186
183sub as_paragraphs($) { 187sub as_paragraphs($) {
184 my ($pom) = @_; 188 my ($pom) = @_;
185 189
186 local $indent = 0; 190 local $indent = 0;
187 local $level = 1; 191 local $level = 2;
188 local @result = ( { } ); 192 local @result = ( [] );
189 193
190 $pom->present ("AsParagraphs"); 194 $pom->present ("AsParagraphs");
191 195
192 [grep $_->{index} || exists $_->{markup}, @result] 196 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
193} 197}
194 198
195############################################################################# 199#############################################################################
196 200
197my %wiki; 201my %wiki;
198 202
199sub add_node($) { 203sub add_node($) {
200 my ($node) = @_; 204 my ($node) = @_;
201 205
202 for (@{ $node->{kw} || {} }) { 206 for (@{ $node->[N_KW] || {} }) {
203 push @{$wiki{lc $_}}, $node; 207 push @{$wiki{lc $_}}, $node;
204 } 208 }
205} 209}
206 210
207my $root = { 211my $root;
208 kw => ["pod"], 212$root->[N_KW] = ["Documents", "pod"];
209}; 213$root->[N_DOC] = [[0, 0, ::special link => "All Documents", "pod/*"]];
210 214
211for my $path (@ARGV) { 215for my $path (@ARGV) {
212 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname"; 216 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
213 my $base = $1; 217 my $base = $1;
214 my $pom = Pod::POM->new->parse_text (do { 218 my $pom = Pod::POM->new->parse_text (do {
218 <$pod> 222 <$pod>
219 }); 223 });
220 224
221 my $para = as_paragraphs $pom; 225 my $para = as_paragraphs $pom;
222 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
223 my @parent = ( 234 my @parent = ($pod);
224 { parent => $root, kw => [$base], doc => $para, par => 0, level => 0 },
225 );
226 add_node $parent[-1];
227 235
228 for my $idx (0 .. $#$para) { 236 for my $idx (0 .. $#$para) {
229 my $par = $para->[$idx]; 237 my $par = $para->[$idx];
230 238
231 while ($parent[-1]{level} >= $par->{level}) { 239 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
232 pop @parent; 240 pop @parent;
233 } 241 }
234 242
235 if ($par->{index}) { 243 if ($par->[P_INDEX]) {
236 my $node = { 244 my $node;
237 kw => $par->{index}, 245 $node->[N_PARENT] = $parent[-1];
238 parent => $parent[-1], 246 $node->[N_PAR] = $idx;
239 doc => $para, 247 $node->[N_LEVEL] = $par->[P_LEVEL];
240 par => $idx, 248 $node->[N_KW] = $par->[P_INDEX];
241 level => $par->{level}, 249 $node->[N_DOC] = $para;
242 };
243 push @parent, $node; 250 push @parent, $node;
244 add_node $node; 251 add_node $node;
245 } 252 }
246 } 253 }
254
255 add_node $pod;
247} 256}
257
258add_node $root;
248 259
249Storable::nstore \%wiki, "docwiki.pst"; 260Storable::nstore \%wiki, "docwiki.pst";
250 261

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines