ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pod2wiki
Revision: 1.16
Committed: Sun Mar 30 13:02:27 2008 UTC (16 years, 1 month ago) by root
Branch: MAIN
Changes since 1.15: +14 -5 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 elmex 1.7 my $ARCH = "/root/devel/cvs/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.4 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
83    
84 root 1.3 if ($link =~ /http:/) {
85     "<u>" . (::asxml $link) . "</u>"
86 root 1.5 } elsif ($link =~ /^\$ARCH\/(.+)$/) {
87     my $path = $1;
88     (my $base = $path) =~ s/.*\///;
89 root 1.6 -f "$ARCH/$path" && system "rsync -av -c \Q$ARCH/$path\E \Qresources/arch/$base";
90 root 1.8 ::special image => "arch/$base", 1;
91 root 1.3 } else {
92 root 1.8 ::special link => $text, $link
93 root 1.3 }
94 root 1.1 }
95    
96     sub view_verbatim {
97 root 1.11 push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ];
98 root 1.1 ()
99     }
100    
101     sub view_textblock {
102 root 1.11 push @result, [ $indent * 16, $level, "$_[1]\n" ];
103 root 1.1 ()
104     }
105    
106     sub view_head1 {
107 root 1.11 push @result, [ $indent * 16, $level ];
108 root 1.1 my $title = $_[1]->title->present ($_[0]);
109 root 1.15 $result[-1][P_MARKUP] = ::special h1 => $title if length $title;
110 root 1.16 $title = ::flatten $title;
111     unshift @{ $result[-1][P_INDEX] }, $title
112     if !$result[-1][P_INDEX];
113 root 1.1 local $level = $level + 1;
114     $_[1]->content->present ($_[0]);
115     ()
116     };
117    
118     sub view_head2 {
119 root 1.11 push @result, [ $indent * 16, $level ];
120 root 1.1 my $title = $_[1]->title->present ($_[0]);
121 root 1.15 $result[-1][P_MARKUP] = ::special h2 => $title if length $title;
122 root 1.16 $title = ::flatten $title;
123     unshift @{ $result[-1][P_INDEX] }, $title
124     if !$result[-1][P_INDEX];
125 root 1.1 local $level = $level + 1;
126     $_[1]->content->present ($_[0]);
127     ()
128     };
129    
130     sub view_head3 {
131 root 1.11 push @result, [ $indent * 16, $level ];
132 root 1.1 my $title = $_[1]->title->present ($_[0]);
133 root 1.15 $result[-1][P_MARKUP] = ::special h3 => $title if length $title;
134 root 1.16 $title = ::flatten $title;
135     unshift @{ $result[-1][P_INDEX] || [] }, $title
136     if !$result[-1][P_INDEX];
137 root 1.1 local $level = $level + 1;
138     $_[1]->content->present ($_[0]);
139     ()
140     };
141    
142     sub view_over {
143     local $indent = $indent + $_[1]->indent;
144 root 1.11 push @result, [ $indent, $level ];
145 root 1.12 $_[1]->content->present ($_[0]);
146     ()
147     }
148    
149     sub view_item {
150     push @result, [ $indent * 8, $level ];
151     my $title = $_[1]->title->present ($_[0]);
152     $result[-1][P_MARKUP] = "$title\n" if length $title;
153 root 1.16 $title = ::flatten $title;
154     unshift @{ $result[-1][P_INDEX] || [] }, $title
155     if !$result[-1][P_INDEX];
156 root 1.11 local $level = $level + 1;
157 root 1.1 $_[1]->content->present ($_[0]);
158     ()
159     }
160    
161     sub view_for {
162     if ($_[1]->format eq "image") {
163 root 1.11 push @result, [
164     $indent * 16,
165     $level,
166     (::special image => "pod/" . $_->text),
167     ];
168 root 1.1 }
169     ()
170     }
171    
172 root 1.10 sub view_begin {
173     ()
174     }
175    
176 root 1.1 sub view {
177     my ($self, $type, $item) = @_;
178    
179     $item->content->present ($self);
180     }
181    
182     #############################################################################
183    
184     sub as_paragraphs($) {
185     my ($pom) = @_;
186    
187     local $indent = 0;
188 root 1.11 local $level = 2;
189     local @result = ( [] );
190 root 1.1
191     $pom->present ("AsParagraphs");
192    
193 root 1.11 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
194 root 1.1 }
195    
196     #############################################################################
197    
198     my %wiki;
199    
200     sub add_node($) {
201     my ($node) = @_;
202    
203 root 1.12 for (@{ $node->[N_KW] || {} }) {
204 root 1.5 push @{$wiki{lc $_}}, $node;
205 root 1.1 }
206     }
207    
208 root 1.12 my $root;
209 root 1.16 $root->[N_KW] = ["Documents", "pod"];
210     $root->[N_DOC] = [[0, 0, ::special link => "All Documents", "pod/*"]];
211 root 1.1
212     for my $path (@ARGV) {
213     $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
214     my $base = $1;
215     my $pom = Pod::POM->new->parse_text (do {
216     local $/;
217     open my $pod, "<:utf8", $path
218     or die "$path: $!";
219     <$pod>
220     });
221    
222     my $para = as_paragraphs $pom;
223    
224 root 1.12 my $pod;
225     $pod->[N_PARENT] = $root;
226     $pod->[N_PAR] = 0;
227     $pod->[N_LEVEL] = 1;
228     $pod->[N_KW] = [$base];
229     $pod->[N_DOC] = $para;
230    
231     my @parent = ($pod);
232 root 1.1
233     for my $idx (0 .. $#$para) {
234     my $par = $para->[$idx];
235    
236 root 1.12 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
237 root 1.1 pop @parent;
238     }
239    
240 root 1.11 if ($par->[P_INDEX]) {
241 root 1.12 my $node;
242     $node->[N_PARENT] = $parent[-1];
243     $node->[N_PAR] = $idx;
244     $node->[N_LEVEL] = $par->[P_LEVEL];
245     $node->[N_KW] = $par->[P_INDEX];
246     $node->[N_DOC] = $para;
247 root 1.1 push @parent, $node;
248     add_node $node;
249     }
250     }
251 root 1.14
252     add_node $pod;
253 root 1.1 }
254    
255 root 1.14 add_node $root;
256    
257 root 1.1 Storable::nstore \%wiki, "docwiki.pst";
258