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.15 by root, Sun Sep 7 23:02:40 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines