ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf/pod.pm
(Generate patch)

Comparing deliantra/server/lib/cf/pod.pm (file contents):
Revision 1.5 by root, Wed Apr 18 17:32:07 2007 UTC vs.
Revision 1.14 by root, Sat Sep 6 20:06:10 2008 UTC

10 10
11use strict; 11use strict;
12 12
13use base "Pod::POM::View"; 13use base "Pod::POM::View";
14 14
15sub asxml($) { 15sub aspod($) {
16 local $_ = $_[0]; 16 local $_ = $_[0];
17 17
18 s/&/&/g;
19 s/>/>/g;
20 s/</&lt;/g; 18 s/</E<lt>/g;
19 s/>/E<gt>/g;
21 20
22 $_ 21 $_
23} 22}
24 23
25sub flatten($) { 24sub flatten($) {
26 local $_ = $_[0]; 25 local $_ = $_[0];
27 26
28 s/<[^>]+>//g;
29 s/^\s+//; 27 s/^\s+//;
30 s/\s+$//; 28 s/\s+$//;
31 s/\s+/ /g; 29 s/\s+/ /g;
32 30
33 $_ 31 $_
34} 32}
35 33
36*view_seq_file = 34*view_seq_file = sub { "B<$_[1]>" };
37*view_seq_code = 35*view_seq_code = sub { "B<$_[1]>" };
38*view_seq_bold = sub { "<b>$_[1]</b>" }; 36*view_seq_bold = sub { "B<$_[1]>" };
39*view_seq_italic = sub { "<i>$_[1]</i>" }; 37*view_seq_italic = sub { "I<$_[1]>" };
40*view_seq_zero = sub { }; 38*view_seq_zero = sub { "Z<>" };
41*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; 39*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text };
42*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 40*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
43 41
44sub view_seq_text { 42sub view_seq_text {
45 my $text = $_[1]; 43 my $text = $_[1];
46 $text =~ s/\s+/ /g; 44 $text =~ s/\s+/ /g;
47 asxml $text 45 aspod $text
48} 46}
49 47
50sub view_seq_link { 48sub view_seq_link {
51 my (undef, $link) = @_; 49 my (undef, $link) = @_;
52 50
53 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 51 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
54 52
55 if ($link =~ /http:/) { 53 if ($link =~ /http:/) {
56 "<u>" . (asxml $link) . "</u>" 54 "U<" . (asxml $link) . ">"
57 } else { 55 } else {
58 () 56 ()
59 } 57 }
60} 58}
61 59
76sub view_verbatim { 74sub view_verbatim {
77 push @result, { 75 push @result, {
78 type => "verbatim", 76 type => "verbatim",
79 indent => $indent * 16, 77 indent => $indent * 16,
80 level => $level, 78 level => $level,
81 markup => asxml $_[1], 79 markup => $_[1],
82 }; 80 };
83 () 81 ()
84} 82}
85 83
86sub view_textblock { 84sub view_textblock {
87 push @result, { 85 push @result, {
88 indent => $indent * 16, 86 indent => $indent * 16,
89 level => $level, 87 level => $level,
90 markup => "$_[1]\n", 88 markup => flatten $_[1],
91 }; 89 };
92 () 90 ()
93} 91}
94 92
95sub view_head1 { 93sub view_head1 {
183 181
184sub load_pod($) { 182sub load_pod($) {
185 my ($path) = @_; 183 my ($path) = @_;
186 184
187 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], 185 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
188 1 => sub { 186 4 => sub {
189 my ($src) = @_; 187 my ($src) = @_;
188
190 cf::fork_call { 189 cf::fork_call {
191 my $pod = $src->[0]; 190 my $pod = $src->[0];
192 utf8::decode $pod; 191 utf8::decode $pod;
193 Coro::Storable::freeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) 192 Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod))
194 } 193 }
195 }; 194 };
196} 195}
197 196
197# format as cfpod-style text
198sub as_cfpod($) {
199 my ($pars) = @_;
200
201 my $res;
202
203 for my $par (@$pars) {
204 if ($par->{type} =~ /^head\d+$/) {
205 $res .= "B<$par->{markup}>\n\n";
206 } elsif ($par->{type} eq "verbatim") {
207 $res .= "\n$par->{markup}\n\n";
208 } elsif ($par->{type} eq "item") {
209 $res .= "\n* I<$par->{markup}>\n\n";
210 } else {
211 $res .= "$par->{markup}\n\n";
212 }
213 }
214
215 $res
216}
217
1981; 2181;
199 219

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines