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.1 by root, Tue Mar 6 19:02:36 2007 UTC vs.
Revision 1.14 by root, Sat Sep 6 20:06:10 2008 UTC

1package cf::pod;
2
3use Pod::POM;
4
5our $indent;
6our $level;
7our @result;
8
9package cf::pod::AsParagraphs;
10
11use strict;
12
13use base "Pod::POM::View";
14
15sub aspod($) {
16 local $_ = $_[0];
17
18 s/</E<lt>/g;
19 s/>/E<gt>/g;
20
21 $_
22}
23
24sub flatten($) {
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]>" };
36*view_seq_bold = sub { "B<$_[1]>" };
37*view_seq_italic = sub { "I<$_[1]>" };
38*view_seq_zero = sub { "Z<>" };
39*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text };
40*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
41
42sub view_seq_text {
43 my $text = $_[1];
44 $text =~ s/\s+/ /g;
45 aspod $text
46}
47
48sub view_seq_link {
49 my (undef, $link) = @_;
50
51 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
52
53 if ($link =~ /http:/) {
54 "U<" . (asxml $link) . ">"
55 } else {
56 ()
57 }
58}
59
60sub view_item {
61 push @result, {
62 type => "item",
63 indent => $indent * 8,
64 level => $level,
65 };
66 my $title = $_[1]->title->present ($_[0]);
67 $result[-1]{markup} = $title if length $title;
68 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
69 local $level = $level + 1;
70 $_[1]->content->present ($_[0]);
71 ()
72}
73
74sub view_verbatim {
75 push @result, {
76 type => "verbatim",
77 indent => $indent * 16,
78 level => $level,
79 markup => $_[1],
80 };
81 ()
82}
83
84sub view_textblock {
85 push @result, {
86 indent => $indent * 16,
87 level => $level,
88 markup => flatten $_[1],
89 };
90 ()
91}
92
93sub view_head1 {
94 push @result, {
95 type => "head1",
96 indent => $indent * 16,
97 level => $level,
98 };
99 my $title = $_[1]->title->present ($_[0]);
100 $result[-1]{markup} = $title if length $title;
101 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
102 local $level = $level + 1;
103 $_[1]->content->present ($_[0]);
104 ()
105};
106
107sub view_head2 {
108 push @result, {
109 type => "head2",
110 indent => $indent * 16,
111 level => $level,
112 };
113 my $title = $_[1]->title->present ($_[0]);
114 $result[-1]{markup} = $title if length $title;
115 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
116 local $level = $level + 1;
117 $_[1]->content->present ($_[0]);
118 ()
119};
120
121sub view_head3 {
122 push @result, {
123 type => "head3",
124 indent => $indent * 16,
125 level => $level,
126 };
127 my $title = $_[1]->title->present ($_[0]);
128 $result[-1]{markup} = $title if length $title;
129 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
130 local $level = $level + 1;
131 $_[1]->content->present ($_[0]);
132 ()
133};
134
135sub view_over {
136 local $indent = $indent + $_[1]->indent;
137 push @result, { indent => $indent };
138 $_[1]->content->present ($_[0]);
139 ()
140}
141
142sub view_for {
143 if ($_[1]->format eq "image") {
144# push @result, {
145# indent => $indent * 16,
146# level => $level,
147# markup => (::special image => "pod/" . $_->text),
148# };
149 }
150 ()
151}
152
153sub view_begin {
154 ()
155}
156
157sub view {
158 my ($self, $type, $item) = @_;
159
160 $item->content->present ($self);
161}
162
163#############################################################################
164
165package cf::pod;
166
167sub pom_as_paragraphs($) {
168 my ($pom) = @_;
169
170 # we suckers use global variables, unfortunately.
171 my $guard = cf::lock_acquire "cf::pod::as_paragraphs";
172
173 local $indent = 0;
174 local $level = 1;
175 local @result = ( { } );
176
177 $pom->present ("cf::pod::AsParagraphs");
178
179 [grep $_->{index} || exists $_->{markup}, @result]
180}
181
182sub load_pod($) {
183 my ($path) = @_;
184
185 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
186 4 => sub {
187 my ($src) = @_;
188
189 cf::fork_call {
190 my $pod = $src->[0];
191 utf8::decode $pod;
192 Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod))
193 }
194 };
195}
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
2181;
219

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines