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.13 by root, Sun Aug 31 09:03:31 2008 UTC

13use base "Pod::POM::View"; 13use base "Pod::POM::View";
14 14
15sub asxml($) { 15sub asxml($) {
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;
20
21 $_
22}
23
24sub flatten($) {
25 local $_ = $_[0];
26
27 s/<[^>]+>//g;
28 s/^\s+//;
29 s/\s+$//;
30 s/\s+/ /g;
21 31
22 $_ 32 $_
23} 33}
24 34
25*view_seq_file = 35*view_seq_file =
26*view_seq_code = 36*view_seq_code =
27*view_seq_bold = sub { "<b>$_[1]</b>" }; 37*view_seq_bold = sub { "B<$_[1]>" };
28*view_seq_italic = sub { "<i>$_[1]</i>" }; 38*view_seq_italic = sub { "I<$_[1]>" };
29*view_seq_zero = sub { }; 39*view_seq_zero = sub { };
30*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; 40*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text };
31*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 41*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
32 42
33sub view_seq_text { 43sub view_seq_text {
34 my $text = $_[1]; 44 my $text = $_[1];
35 $text =~ s/\s+/ /g; 45 $text =~ s/\s+/ /g;
36 ::asxml $text 46 asxml $text
37} 47}
38 48
39sub view_seq_link { 49sub view_seq_link {
40 my (undef, $link) = @_; 50 my (undef, $link) = @_;
41 51
42 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 52 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
43 53
44 if ($link =~ /http:/) { 54 if ($link =~ /http:/) {
45 "<u>" . (::asxml $link) . "</u>" 55 "U<" . (asxml $link) . ">"
46 } else { 56 } else {
47 () 57 ()
48 } 58 }
49} 59}
50 60
51sub view_item { 61sub view_item {
52 push @result, { 62 push @result, {
63 type => "item",
53 indent => $indent * 8, 64 indent => $indent * 8,
54 level => $level, 65 level => $level,
55 }; 66 };
56 my $title = $_[1]->title->present ($_[0]); 67 my $title = $_[1]->title->present ($_[0]);
57 $result[-1]{markup} = "$title\n" if length $title; 68 $result[-1]{markup} = $title if length $title;
58 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 69 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
59 local $level = $level + 1; 70 local $level = $level + 1;
60 $_[1]->content->present ($_[0]); 71 $_[1]->content->present ($_[0]);
61 () 72 ()
62} 73}
63 74
64sub view_verbatim { 75sub view_verbatim {
65 push @result, { 76 push @result, {
77 type => "verbatim",
66 indent => $indent * 16, 78 indent => $indent * 16,
67 level => $level, 79 level => $level,
68 markup => "<tt>" . (::asxml $_[1]) . "</tt>\n", 80 markup => $_[1],
69 }; 81 };
70 () 82 ()
71} 83}
72 84
73sub view_textblock { 85sub view_textblock {
74 push @result, { 86 push @result, {
75 indent => $indent * 16, 87 indent => $indent * 16,
76 level => $level, 88 level => $level,
77 markup => "$_[1]\n", 89 markup => flatten $_[1],
78 }; 90 };
79 () 91 ()
80} 92}
81 93
82sub view_head1 { 94sub view_head1 {
83 push @result, { 95 push @result, {
96 type => "head1",
84 indent => $indent * 16, 97 indent => $indent * 16,
85 level => $level, 98 level => $level,
86 }; 99 };
87 my $title = $_[1]->title->present ($_[0]); 100 my $title = $_[1]->title->present ($_[0]);
88 $result[-1]{markup} = "\n\n<h1>$title</h1>\n" if length $title; 101 $result[-1]{markup} = $title if length $title;
89 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 102 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
90 local $level = $level + 1; 103 local $level = $level + 1;
91 $_[1]->content->present ($_[0]); 104 $_[1]->content->present ($_[0]);
92 () 105 ()
93}; 106};
94 107
95sub view_head2 { 108sub view_head2 {
96 push @result, { 109 push @result, {
110 type => "head2",
97 indent => $indent * 16, 111 indent => $indent * 16,
98 level => $level, 112 level => $level,
99 }; 113 };
100 my $title = $_[1]->title->present ($_[0]); 114 my $title = $_[1]->title->present ($_[0]);
101 $result[-1]{markup} = "\n\n<h2>$title</h2>\n" if length $title; 115 $result[-1]{markup} = $title if length $title;
102 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 116 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
103 local $level = $level + 1; 117 local $level = $level + 1;
104 $_[1]->content->present ($_[0]); 118 $_[1]->content->present ($_[0]);
105 () 119 ()
106}; 120};
107 121
108sub view_head3 { 122sub view_head3 {
109 push @result, { 123 push @result, {
124 type => "head3",
110 indent => $indent * 16, 125 indent => $indent * 16,
111 level => $level, 126 level => $level,
112 }; 127 };
113 my $title = $_[1]->title->present ($_[0]); 128 my $title = $_[1]->title->present ($_[0]);
114 $result[-1]{markup} = "\n\n<h3>$title</h3>\n" if length $title; 129 $result[-1]{markup} = $title if length $title;
115 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 130 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
116 local $level = $level + 1; 131 local $level = $level + 1;
117 $_[1]->content->present ($_[0]); 132 $_[1]->content->present ($_[0]);
118 () 133 ()
119}; 134};
120 135
167 182
168sub load_pod($) { 183sub load_pod($) {
169 my ($path) = @_; 184 my ($path) = @_;
170 185
171 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], 186 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
172 1 => sub { 187 3 => sub {
173 my ($src) = @_; 188 my ($src) = @_;
189
174 fork_exec { 190 cf::fork_call {
175 my $pod = $src->[0]; 191 my $pod = $src->[0];
176 utf8::decode $pod; 192 utf8::decode $pod;
177 Coro::Storable::freeze pom_as_paragraphs Pod::POM->new->parse_text ($pod) 193 Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod))
178 } 194 }
179 }; 195 };
180} 196}
181 197
198# format as cfpod-style text
199sub as_cfpod($) {
200 my ($pars) = @_;
201
202 my $res;
203
204 for my $par (@$pars) {
205 if ($par->{type} =~ /^head\d+$/) {
206 $res .= "B<$par->{markup}>\n\n";
207 } elsif ($par->{type} eq "verbatim") {
208 $res .= "\n$par->{markup}\n\n";
209 } elsif ($par->{type} eq "item") {
210 $res .= "\n* I<$par->{markup}>\n\n";
211 } else {
212 $res .= "$par->{markup}\n\n";
213 }
214 }
215
216 $res
217}
218
1821; 2191;
183 220

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines