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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines