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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines