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.20 by root, Wed Oct 21 00:44:39 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines