ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pod2wiki
Revision: 1.20
Committed: Mon Jun 21 22:51:58 2010 UTC (13 years, 11 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.19: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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