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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines