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.4 by root, Wed Apr 18 15:28:18 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
25*view_seq_file = 24sub flatten($) {
26*view_seq_code = 25 local $_ = $_[0];
26
27 s/^\s+//;
28 s/\s+$//;
29 s/\s+/ /g;
30
31 $_
32}
33
34*view_seq_file = sub { "B<$_[1]>" };
35*view_seq_code = sub { "B<$_[1]>" };
27*view_seq_bold = sub { "<b>$_[1]</b>" }; 36*view_seq_bold = sub { "B<$_[1]>" };
28*view_seq_italic = sub { "<i>$_[1]</i>" }; 37*view_seq_italic = sub { "I<$_[1]>" };
29*view_seq_zero = sub { }; 38*view_seq_zero = sub { "Z<>" };
30*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 };
31*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 40*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
32 41
33sub view_seq_text { 42sub view_seq_text {
34 my $text = $_[1]; 43 my $text = $_[1];
35 $text =~ s/\s+/ /g; 44 $text =~ s/\s+/ /g;
36 ::asxml $text 45 aspod $text
37} 46}
38 47
39sub view_seq_link { 48sub view_seq_link {
40 my (undef, $link) = @_; 49 my (undef, $link) = @_;
41 50
42 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 51 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
43 52
44 if ($link =~ /http:/) { 53 if ($link =~ /http:/) {
45 "<u>" . (::asxml $link) . "</u>" 54 "U<" . (asxml $link) . ">"
46 } else { 55 } else {
47 () 56 ()
48 } 57 }
49} 58}
50 59
51sub view_item { 60sub view_item {
52 push @result, { 61 push @result, {
62 type => "item",
53 indent => $indent * 8, 63 indent => $indent * 8,
54 level => $level, 64 level => $level,
55 }; 65 };
56 my $title = $_[1]->title->present ($_[0]); 66 my $title = $_[1]->title->present ($_[0]);
57 $result[-1]{markup} = "$title\n" if length $title; 67 $result[-1]{markup} = $title if length $title;
58 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 68 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
59 local $level = $level + 1; 69 local $level = $level + 1;
60 $_[1]->content->present ($_[0]); 70 $_[1]->content->present ($_[0]);
61 () 71 ()
62} 72}
63 73
64sub view_verbatim { 74sub view_verbatim {
65 push @result, { 75 push @result, {
76 type => "verbatim",
66 indent => $indent * 16, 77 indent => $indent * 16,
67 level => $level, 78 level => $level,
68 markup => "<tt>" . (::asxml $_[1]) . "</tt>\n", 79 markup => $_[1],
69 }; 80 };
70 () 81 ()
71} 82}
72 83
73sub view_textblock { 84sub view_textblock {
74 push @result, { 85 push @result, {
75 indent => $indent * 16, 86 indent => $indent * 16,
76 level => $level, 87 level => $level,
77 markup => "$_[1]\n", 88 markup => flatten $_[1],
78 }; 89 };
79 () 90 ()
80} 91}
81 92
82sub view_head1 { 93sub view_head1 {
83 push @result, { 94 push @result, {
95 type => "head1",
84 indent => $indent * 16, 96 indent => $indent * 16,
85 level => $level, 97 level => $level,
86 }; 98 };
87 my $title = $_[1]->title->present ($_[0]); 99 my $title = $_[1]->title->present ($_[0]);
88 $result[-1]{markup} = "\n\n<h1>$title</h1>\n" if length $title; 100 $result[-1]{markup} = $title if length $title;
89 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 101 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
90 local $level = $level + 1; 102 local $level = $level + 1;
91 $_[1]->content->present ($_[0]); 103 $_[1]->content->present ($_[0]);
92 () 104 ()
93}; 105};
94 106
95sub view_head2 { 107sub view_head2 {
96 push @result, { 108 push @result, {
109 type => "head2",
97 indent => $indent * 16, 110 indent => $indent * 16,
98 level => $level, 111 level => $level,
99 }; 112 };
100 my $title = $_[1]->title->present ($_[0]); 113 my $title = $_[1]->title->present ($_[0]);
101 $result[-1]{markup} = "\n\n<h2>$title</h2>\n" if length $title; 114 $result[-1]{markup} = $title if length $title;
102 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 115 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
103 local $level = $level + 1; 116 local $level = $level + 1;
104 $_[1]->content->present ($_[0]); 117 $_[1]->content->present ($_[0]);
105 () 118 ()
106}; 119};
107 120
108sub view_head3 { 121sub view_head3 {
109 push @result, { 122 push @result, {
123 type => "head3",
110 indent => $indent * 16, 124 indent => $indent * 16,
111 level => $level, 125 level => $level,
112 }; 126 };
113 my $title = $_[1]->title->present ($_[0]); 127 my $title = $_[1]->title->present ($_[0]);
114 $result[-1]{markup} = "\n\n<h3>$title</h3>\n" if length $title; 128 $result[-1]{markup} = $title if length $title;
115 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 129 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
116 local $level = $level + 1; 130 local $level = $level + 1;
117 $_[1]->content->present ($_[0]); 131 $_[1]->content->present ($_[0]);
118 () 132 ()
119}; 133};
120 134
167 181
168sub load_pod($) { 182sub load_pod($) {
169 my ($path) = @_; 183 my ($path) = @_;
170 184
171 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], 185 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
172 1 => sub { 186 4 => sub {
173 my ($src) = @_; 187 my ($src) = @_;
188
174 fork_exec { 189 cf::fork_call {
175 my $pod = $src->[0]; 190 my $pod = $src->[0];
176 utf8::decode $pod; 191 utf8::decode $pod;
177 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))
178 } 193 }
179 }; 194 };
180} 195}
181 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
1821; 2181;
183 219

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines