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.2 by root, Sun Aug 13 03:20:56 2006 UTC vs.
Revision 1.12 by root, Tue Mar 25 02:12:36 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;
16
17my $MA_BEG = "\x{fcd0}";
18my $MA_SEP = "\x{fcd1}";
19my $MA_END = "\x{fcd2}";
14 20
15sub asxml($) { 21sub asxml($) {
16 local $_ = $_[0]; 22 local $_ = $_[0];
17 23
18 s/&/&/g; 24 s/&/&/g;
31 s/\s+/ /g; 37 s/\s+/ /g;
32 38
33 $_ 39 $_
34} 40}
35 41
42sub special {
43 $MA_BEG . (join $MA_SEP, @_) . $MA_END
44}
45
36package AsParagraphs; 46package AsParagraphs;
37 47
38use strict; 48use strict;
39 49
40use 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 }
41 64
42*view_seq_file = 65*view_seq_file =
43*view_seq_code = 66*view_seq_code =
44*view_seq_bold = sub { "<b>$_[1]</b>" }; 67*view_seq_bold = sub { "<b>$_[1]</b>" };
45*view_seq_italic = sub { "<i>$_[1]</i>" }; 68*view_seq_italic = sub { "<i>$_[1]</i>" };
46*view_seq_zero = sub { }; 69*view_seq_zero = sub { };
47*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 };
48*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 71*view_seq_index = sub { push @{ $result[-1][P_INDEX] }, $_[1]; "" };
49 72
50sub view_seq_text { 73sub view_seq_text {
51 my $text = $_[1]; 74 my $text = $_[1];
52 $text =~ s/\s+/ /g; 75 $text =~ s/\s+/ /g;
53 ::asxml $text 76 ::asxml $text
54} 77}
55 78
56sub view_seq_link { 79sub view_seq_link {
57 my (undef, $link) = @_; 80 my (undef, $link) = @_;
58 81
59 # TODO: 82 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
60 # http://...
61 # ref
62 # pod/ref
63 83
84 if ($link =~ /http:/) {
64 "<u>" . (::asxml $_[1]) . "</u>"; 85 "<u>" . (::asxml $link) . "</u>"
65} 86 } elsif ($link =~ /^\$ARCH\/(.+)$/) {
66 87 my $path = $1;
67sub view_item { 88 (my $base = $path) =~ s/.*\///;
68 push @result, { 89 -f "$ARCH/$path" && system "rsync -av -c \Q$ARCH/$path\E \Qresources/arch/$base";
69 indent => $indent * 8, 90 ::special image => "arch/$base", 1;
70 level => $level, 91 } else {
92 ::special link => $text, $link
71 }; 93 }
72 my $title = $_[1]->title->present ($_[0]);
73 $result[-1]{markup} = "$title\n\n" if length $title;
74 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
75 local $level = $level + 1;
76 $_[1]->content->present ($_[0]);
77 ()
78} 94}
79 95
80sub view_verbatim { 96sub view_verbatim {
81 push @result, { 97 push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ];
82 indent => $indent * 16,
83 level => $level,
84 markup => "<tt>" . (::asxml $_[1]) . "</tt>\n",
85 };
86 () 98 ()
87} 99}
88 100
89sub view_textblock { 101sub view_textblock {
90 push @result, { 102 push @result, [ $indent * 16, $level, "$_[1]\n" ];
91 indent => $indent * 16,
92 level => $level,
93 markup => "$_[1]\n",
94 };
95 () 103 ()
96} 104}
97 105
98sub view_head1 { 106sub view_head1 {
99 push @result, { 107 push @result, [ $indent * 16, $level ];
100 indent => $indent * 16,
101 level => $level,
102 };
103 my $title = $_[1]->title->present ($_[0]); 108 my $title = $_[1]->title->present ($_[0]);
104 $result[-1]{markup} = "\n\n<span foreground='#ffff00' size='x-large'>$title</span>\n" if length $title; 109 $result[-1][P_MARKUP] = "\n\n<span foreground='#ffff00' size='x-large'>$title</span>\n" if length $title;
105 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 110 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
106 local $level = $level + 1; 111 local $level = $level + 1;
107 $_[1]->content->present ($_[0]); 112 $_[1]->content->present ($_[0]);
108 () 113 ()
109}; 114};
110 115
111sub view_head2 { 116sub view_head2 {
112 push @result, { 117 push @result, [ $indent * 16, $level ];
113 indent => $indent * 16,
114 level => $level,
115 };
116 my $title = $_[1]->title->present ($_[0]); 118 my $title = $_[1]->title->present ($_[0]);
117 $result[-1]{markup} = "\n\n<span foreground='#ccccff' size='large'>$title</span>\n" if length $title; 119 $result[-1][P_MARKUP] = "\n\n<span foreground='#ccccff' size='large'>$title</span>\n" if length $title;
118 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 120 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
119 local $level = $level + 1; 121 local $level = $level + 1;
120 $_[1]->content->present ($_[0]); 122 $_[1]->content->present ($_[0]);
121 () 123 ()
122}; 124};
123 125
124sub view_head3 { 126sub view_head3 {
125 push @result, { 127 push @result, [ $indent * 16, $level ];
126 indent => $indent * 16,
127 level => $level,
128 };
129 my $title = $_[1]->title->present ($_[0]); 128 my $title = $_[1]->title->present ($_[0]);
130 $result[-1]{markup} = "\n\n<span size='large'>$title</span>\n" if length $title; 129 $result[-1][P_MARKUP] = "\n\n<span size='large'>$title</span>\n" if length $title;
131 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 130 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
132 local $level = $level + 1; 131 local $level = $level + 1;
133 $_[1]->content->present ($_[0]); 132 $_[1]->content->present ($_[0]);
134 () 133 ()
135}; 134};
136 135
137sub view_over { 136sub view_over {
138 local $indent = $indent + $_[1]->indent; 137 local $indent = $indent + $_[1]->indent;
139 push @result, { indent => $indent }; 138 push @result, [ $indent, $level ];
139 $_[1]->content->present ($_[0]);
140 ()
141}
142
143sub view_item {
144 push @result, [ $indent * 8, $level ];
145 my $title = $_[1]->title->present ($_[0]);
146 $result[-1][P_MARKUP] = "$title\n" if length $title;
147 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
148 local $level = $level + 1;
140 $_[1]->content->present ($_[0]); 149 $_[1]->content->present ($_[0]);
141 () 150 ()
142} 151}
143 152
144sub view_for { 153sub view_for {
145 if ($_[1]->format eq "image") { 154 if ($_[1]->format eq "image") {
146 push @result, { 155 push @result, [
147 indent => $indent * 16, 156 $indent * 16,
148 level => $level, 157 $level,
149 markup => "\x{fffc}", 158 (::special image => "pod/" . $_->text),
150 widget => [["CFPlus::UI::Image" => path => "pod/" . $_[1]->text]],
151 }; 159 ];
152 } 160 }
161 ()
162}
163
164sub view_begin {
153 () 165 ()
154} 166}
155 167
156sub view { 168sub view {
157 my ($self, $type, $item) = @_; 169 my ($self, $type, $item) = @_;
163 175
164sub as_paragraphs($) { 176sub as_paragraphs($) {
165 my ($pom) = @_; 177 my ($pom) = @_;
166 178
167 local $indent = 0; 179 local $indent = 0;
168 local $level = 1; 180 local $level = 2;
169 local @result = ( { } ); 181 local @result = ( [] );
170 182
171 $pom->present ("AsParagraphs"); 183 $pom->present ("AsParagraphs");
172 184
173 [grep $_->{index} || exists $_->{markup}, @result] 185 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
174} 186}
175 187
176############################################################################# 188#############################################################################
177 189
178my %wiki; 190my %wiki;
179 191
180sub add_node($) { 192sub add_node($) {
181 my ($node) = @_; 193 my ($node) = @_;
182 194
183 for (@{ $node->{kw} || {} }) { 195 for (@{ $node->[N_KW] || {} }) {
184 push @{$wiki{$_}}, $node; 196 push @{$wiki{lc $_}}, $node;
185 } 197 }
186} 198}
187 199
188my $root = { 200my $root;
189 kw => ["pod"], 201$root->[N_KW] = ["pod"];
190};
191 202
192for my $path (@ARGV) { 203for my $path (@ARGV) {
193 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname"; 204 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
194 my $base = $1; 205 my $base = $1;
195 my $pom = Pod::POM->new->parse_text (do { 206 my $pom = Pod::POM->new->parse_text (do {
199 <$pod> 210 <$pod>
200 }); 211 });
201 212
202 my $para = as_paragraphs $pom; 213 my $para = as_paragraphs $pom;
203 214
215 my $pod;
216 $pod->[N_PARENT] = $root;
217 $pod->[N_PAR] = 0;
218 $pod->[N_LEVEL] = 1;
219 $pod->[N_KW] = [$base];
220 $pod->[N_DOC] = $para;
221
204 my @parent = ( 222 my @parent = ($pod);
205 { parent => $root, kw => [$base], doc => $para, par => 0, level => 0 },
206 );
207 add_node $parent[-1]; 223 add_node $parent[-1];
208 224
209 for my $idx (0 .. $#$para) { 225 for my $idx (0 .. $#$para) {
210 my $par = $para->[$idx]; 226 my $par = $para->[$idx];
211 227
212 while ($parent[-1]{level} >= $par->{level}) { 228 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
213 pop @parent; 229 pop @parent;
214 } 230 }
215 231
216 if ($par->{index}) { 232 if ($par->[P_INDEX]) {
217 my $node = { 233 my $node;
218 kw => $par->{index}, 234 $node->[N_PARENT] = $parent[-1];
219 parent => $parent[-1], 235 $node->[N_PAR] = $idx;
220 doc => $para, 236 $node->[N_LEVEL] = $par->[P_LEVEL];
221 par => $idx, 237 $node->[N_KW] = $par->[P_INDEX];
222 level => $par->{level}, 238 $node->[N_DOC] = $para;
223 };
224 push @parent, $node; 239 push @parent, $node;
225 add_node $node; 240 add_node $node;
226 } 241 }
227 } 242 }
228} 243}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines