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.2 by root, Wed Apr 18 12:43:54 2007 UTC vs.
Revision 1.8 by root, Tue Jul 3 01:10:38 2007 UTC

1package cf::pod; 1package cf::pod;
2
3use Pod::POM;
2 4
3our $indent; 5our $indent;
4our $level; 6our $level;
5our @result; 7our @result;
6 8
14 local $_ = $_[0]; 16 local $_ = $_[0];
15 17
16 s/&/&/g; 18 s/&/&/g;
17 s/>/>/g; 19 s/>/>/g;
18 s/</&lt;/g; 20 s/</&lt;/g;
21
22 $_
23}
24
25sub flatten($) {
26 local $_ = $_[0];
27
28 s/<[^>]+>//g;
29 s/^\s+//;
30 s/\s+$//;
31 s/\s+/ /g;
19 32
20 $_ 33 $_
21} 34}
22 35
23*view_seq_file = 36*view_seq_file =
29*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 42*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
30 43
31sub view_seq_text { 44sub view_seq_text {
32 my $text = $_[1]; 45 my $text = $_[1];
33 $text =~ s/\s+/ /g; 46 $text =~ s/\s+/ /g;
34 ::asxml $text 47 asxml $text
35} 48}
36 49
37sub view_seq_link { 50sub view_seq_link {
38 my (undef, $link) = @_; 51 my (undef, $link) = @_;
39 52
40 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 53 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
41 54
42 if ($link =~ /http:/) { 55 if ($link =~ /http:/) {
43 "<u>" . (::asxml $link) . "</u>" 56 "<u>" . (asxml $link) . "</u>"
44 } else { 57 } else {
45 () 58 ()
46 } 59 }
47} 60}
48 61
49sub view_item { 62sub view_item {
50 push @result, { 63 push @result, {
64 type => "item",
51 indent => $indent * 8, 65 indent => $indent * 8,
52 level => $level, 66 level => $level,
53 }; 67 };
54 my $title = $_[1]->title->present ($_[0]); 68 my $title = $_[1]->title->present ($_[0]);
55 $result[-1]{markup} = "$title\n" if length $title; 69 $result[-1]{markup} = $title if length $title;
56 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 70 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
57 local $level = $level + 1; 71 local $level = $level + 1;
58 $_[1]->content->present ($_[0]); 72 $_[1]->content->present ($_[0]);
59 () 73 ()
60} 74}
61 75
62sub view_verbatim { 76sub view_verbatim {
63 push @result, { 77 push @result, {
78 type => "verbatim",
64 indent => $indent * 16, 79 indent => $indent * 16,
65 level => $level, 80 level => $level,
66 markup => "<tt>" . (::asxml $_[1]) . "</tt>\n", 81 markup => asxml $_[1],
67 }; 82 };
68 () 83 ()
69} 84}
70 85
71sub view_textblock { 86sub view_textblock {
72 push @result, { 87 push @result, {
73 indent => $indent * 16, 88 indent => $indent * 16,
74 level => $level, 89 level => $level,
75 markup => "$_[1]\n", 90 markup => flatten $_[1],
76 }; 91 };
77 () 92 ()
78} 93}
79 94
80sub view_head1 { 95sub view_head1 {
81 push @result, { 96 push @result, {
97 type => "head1",
82 indent => $indent * 16, 98 indent => $indent * 16,
83 level => $level, 99 level => $level,
84 }; 100 };
85 my $title = $_[1]->title->present ($_[0]); 101 my $title = $_[1]->title->present ($_[0]);
86 $result[-1]{markup} = "\n\n<h1>$title</h1>\n" if length $title; 102 $result[-1]{markup} = $title if length $title;
87 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 103 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
88 local $level = $level + 1; 104 local $level = $level + 1;
89 $_[1]->content->present ($_[0]); 105 $_[1]->content->present ($_[0]);
90 () 106 ()
91}; 107};
92 108
93sub view_head2 { 109sub view_head2 {
94 push @result, { 110 push @result, {
111 type => "head2",
95 indent => $indent * 16, 112 indent => $indent * 16,
96 level => $level, 113 level => $level,
97 }; 114 };
98 my $title = $_[1]->title->present ($_[0]); 115 my $title = $_[1]->title->present ($_[0]);
99 $result[-1]{markup} = "\n\n<h2>$title</h2>\n" if length $title; 116 $result[-1]{markup} = $title if length $title;
100 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 117 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
101 local $level = $level + 1; 118 local $level = $level + 1;
102 $_[1]->content->present ($_[0]); 119 $_[1]->content->present ($_[0]);
103 () 120 ()
104}; 121};
105 122
106sub view_head3 { 123sub view_head3 {
107 push @result, { 124 push @result, {
125 type => "head3",
108 indent => $indent * 16, 126 indent => $indent * 16,
109 level => $level, 127 level => $level,
110 }; 128 };
111 my $title = $_[1]->title->present ($_[0]); 129 my $title = $_[1]->title->present ($_[0]);
112 $result[-1]{markup} = "\n\n<h3>$title</h3>\n" if length $title; 130 $result[-1]{markup} = $title if length $title;
113 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 131 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
114 local $level = $level + 1; 132 local $level = $level + 1;
115 $_[1]->content->present ($_[0]); 133 $_[1]->content->present ($_[0]);
116 () 134 ()
117}; 135};
118 136
146 164
147############################################################################# 165#############################################################################
148 166
149package cf::pod; 167package cf::pod;
150 168
151sub as_paragraphs($) { 169sub pom_as_paragraphs($) {
152 my ($pom) = @_; 170 my ($pom) = @_;
153 171
154 # we suckers use global variables, unfortunately. 172 # we suckers use global variables, unfortunately.
155 my $guard = cf::lock_acquire "cf::pod::as_paragraphs"; 173 my $guard = cf::lock_acquire "cf::pod::as_paragraphs";
156 174
161 $pom->present ("cf::pod::AsParagraphs"); 179 $pom->present ("cf::pod::AsParagraphs");
162 180
163 [grep $_->{index} || exists $_->{markup}, @result] 181 [grep $_->{index} || exists $_->{markup}, @result]
164} 182}
165 183
184sub load_pod($) {
185 my ($path) = @_;
186
187 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
188 1 => sub {
189 my ($src) = @_;
190 cf::fork_call {
191 my $pod = $src->[0];
192 utf8::decode $pod;
193 Coro::Storable::freeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod))
194 }
195 };
196}
197
198# format as cfpod-style text
199sub as_text($) {
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
1661; 2191;
167 220

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines