1 |
root |
1.21 |
# |
2 |
|
|
# This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
root |
1.27 |
# |
4 |
root |
1.26 |
# Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.27 |
# |
6 |
root |
1.21 |
# Deliantra is free software: you can redistribute it and/or modify it under |
7 |
|
|
# the terms of the Affero GNU General Public License as published by the |
8 |
|
|
# Free Software Foundation, either version 3 of the License, or (at your |
9 |
|
|
# option) any later version. |
10 |
root |
1.27 |
# |
11 |
root |
1.21 |
# This program is distributed in the hope that it will be useful, |
12 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
# GNU General Public License for more details. |
15 |
root |
1.27 |
# |
16 |
root |
1.21 |
# You should have received a copy of the Affero GNU General Public License |
17 |
|
|
# and the GNU General Public License along with this program. If not, see |
18 |
|
|
# <http://www.gnu.org/licenses/>. |
19 |
root |
1.27 |
# |
20 |
root |
1.21 |
# The authors can be reached via e-mail to <support@deliantra.net> |
21 |
|
|
# |
22 |
|
|
|
23 |
root |
1.2 |
package cf::pod; |
24 |
|
|
|
25 |
root |
1.20 |
use common::sense; |
26 |
|
|
|
27 |
root |
1.3 |
use Pod::POM; |
28 |
|
|
|
29 |
root |
1.2 |
our $indent; |
30 |
|
|
our $level; |
31 |
|
|
our @result; |
32 |
|
|
|
33 |
|
|
package cf::pod::AsParagraphs; |
34 |
|
|
|
35 |
root |
1.20 |
use common::sense; |
36 |
root |
1.2 |
|
37 |
|
|
use base "Pod::POM::View"; |
38 |
|
|
|
39 |
root |
1.15 |
my %E = ( |
40 |
|
|
"<" => "E<lt>", |
41 |
|
|
">" => "E<gt>", |
42 |
|
|
); |
43 |
|
|
|
44 |
root |
1.14 |
sub aspod($) { |
45 |
root |
1.2 |
local $_ = $_[0]; |
46 |
|
|
|
47 |
root |
1.15 |
s/[<>]/$E{$1}/g; |
48 |
root |
1.2 |
|
49 |
|
|
$_ |
50 |
|
|
} |
51 |
|
|
|
52 |
root |
1.5 |
sub flatten($) { |
53 |
|
|
local $_ = $_[0]; |
54 |
|
|
|
55 |
|
|
s/^\s+//; |
56 |
|
|
s/\s+$//; |
57 |
|
|
s/\s+/ /g; |
58 |
|
|
|
59 |
|
|
$_ |
60 |
|
|
} |
61 |
|
|
|
62 |
root |
1.17 |
*view_seq_file = sub { "C<$_[1]>" }; |
63 |
|
|
*view_seq_code = sub { "C<$_[1]>" }; |
64 |
root |
1.13 |
*view_seq_bold = sub { "B<$_[1]>" }; |
65 |
|
|
*view_seq_italic = sub { "I<$_[1]>" }; |
66 |
root |
1.19 |
*view_seq_T = sub { "T<$_[1]>" }; |
67 |
|
|
*view_seq_G = sub { "G<$_[1]>" }; |
68 |
root |
1.14 |
*view_seq_zero = sub { "Z<>" }; |
69 |
root |
1.2 |
*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; |
70 |
|
|
*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; |
71 |
root |
1.29 |
#view_seq_entity |
72 |
root |
1.2 |
|
73 |
|
|
sub view_seq_text { |
74 |
|
|
my $text = $_[1]; |
75 |
|
|
$text =~ s/\s+/ /g; |
76 |
root |
1.14 |
aspod $text |
77 |
root |
1.2 |
} |
78 |
|
|
|
79 |
|
|
sub view_seq_link { |
80 |
|
|
my (undef, $link) = @_; |
81 |
|
|
|
82 |
|
|
my $text = $link =~ s/^(.*)\|// ? $1 : $link; |
83 |
|
|
|
84 |
|
|
if ($link =~ /http:/) { |
85 |
root |
1.15 |
"U<" . (aspod $link) . ">" |
86 |
root |
1.2 |
} else { |
87 |
root |
1.30 |
aspod $text |
88 |
root |
1.2 |
} |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
sub view_item { |
92 |
|
|
push @result, { |
93 |
root |
1.5 |
type => "item", |
94 |
root |
1.2 |
indent => $indent * 8, |
95 |
|
|
level => $level, |
96 |
|
|
}; |
97 |
|
|
my $title = $_[1]->title->present ($_[0]); |
98 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
99 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
100 |
root |
1.2 |
local $level = $level + 1; |
101 |
|
|
$_[1]->content->present ($_[0]); |
102 |
|
|
() |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
sub view_verbatim { |
106 |
|
|
push @result, { |
107 |
root |
1.5 |
type => "verbatim", |
108 |
root |
1.2 |
indent => $indent * 16, |
109 |
|
|
level => $level, |
110 |
root |
1.13 |
markup => $_[1], |
111 |
root |
1.2 |
}; |
112 |
|
|
() |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
sub view_textblock { |
116 |
|
|
push @result, { |
117 |
|
|
indent => $indent * 16, |
118 |
|
|
level => $level, |
119 |
root |
1.6 |
markup => flatten $_[1], |
120 |
root |
1.2 |
}; |
121 |
|
|
() |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
sub view_head1 { |
125 |
|
|
push @result, { |
126 |
root |
1.5 |
type => "head1", |
127 |
root |
1.2 |
indent => $indent * 16, |
128 |
|
|
level => $level, |
129 |
|
|
}; |
130 |
|
|
my $title = $_[1]->title->present ($_[0]); |
131 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
132 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
133 |
root |
1.2 |
local $level = $level + 1; |
134 |
|
|
$_[1]->content->present ($_[0]); |
135 |
|
|
() |
136 |
|
|
}; |
137 |
|
|
|
138 |
|
|
sub view_head2 { |
139 |
|
|
push @result, { |
140 |
root |
1.5 |
type => "head2", |
141 |
root |
1.2 |
indent => $indent * 16, |
142 |
|
|
level => $level, |
143 |
|
|
}; |
144 |
|
|
my $title = $_[1]->title->present ($_[0]); |
145 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
146 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
147 |
root |
1.2 |
local $level = $level + 1; |
148 |
|
|
$_[1]->content->present ($_[0]); |
149 |
|
|
() |
150 |
|
|
}; |
151 |
|
|
|
152 |
|
|
sub view_head3 { |
153 |
|
|
push @result, { |
154 |
root |
1.5 |
type => "head3", |
155 |
root |
1.2 |
indent => $indent * 16, |
156 |
|
|
level => $level, |
157 |
|
|
}; |
158 |
|
|
my $title = $_[1]->title->present ($_[0]); |
159 |
root |
1.5 |
$result[-1]{markup} = $title if length $title; |
160 |
|
|
$title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; |
161 |
root |
1.2 |
local $level = $level + 1; |
162 |
|
|
$_[1]->content->present ($_[0]); |
163 |
|
|
() |
164 |
|
|
}; |
165 |
|
|
|
166 |
|
|
sub view_over { |
167 |
|
|
local $indent = $indent + $_[1]->indent; |
168 |
|
|
push @result, { indent => $indent }; |
169 |
|
|
$_[1]->content->present ($_[0]); |
170 |
|
|
() |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
sub view_for { |
174 |
|
|
if ($_[1]->format eq "image") { |
175 |
|
|
# push @result, { |
176 |
|
|
# indent => $indent * 16, |
177 |
|
|
# level => $level, |
178 |
|
|
# markup => (::special image => "pod/" . $_->text), |
179 |
|
|
# }; |
180 |
|
|
} |
181 |
|
|
() |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
sub view_begin { |
185 |
|
|
() |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
sub view { |
189 |
|
|
my ($self, $type, $item) = @_; |
190 |
|
|
|
191 |
|
|
$item->content->present ($self); |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
############################################################################# |
195 |
|
|
|
196 |
|
|
package cf::pod; |
197 |
|
|
|
198 |
root |
1.28 |
sub pom_as_paragraphs_ng($) { |
199 |
root |
1.2 |
my ($pom) = @_; |
200 |
|
|
|
201 |
root |
1.31 |
# we suckers use global variables, unfortunately. |
202 |
root |
1.2 |
local $indent = 0; |
203 |
|
|
local $level = 1; |
204 |
|
|
local @result = ( { } ); |
205 |
|
|
|
206 |
|
|
$pom->present ("cf::pod::AsParagraphs"); |
207 |
|
|
|
208 |
|
|
[grep $_->{index} || exists $_->{markup}, @result] |
209 |
|
|
} |
210 |
|
|
|
211 |
root |
1.28 |
sub pom_as_paragraphs($) { |
212 |
|
|
my ($pom) = @_; |
213 |
|
|
|
214 |
|
|
my $guard = cf::lock_acquire "cf::pod::as_paragraphs"; |
215 |
|
|
|
216 |
|
|
$pom->pom_as_paragraphs_ng |
217 |
|
|
} |
218 |
|
|
|
219 |
root |
1.3 |
sub load_pod($) { |
220 |
|
|
my ($path) = @_; |
221 |
|
|
|
222 |
root |
1.4 |
Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], |
223 |
root |
1.30 |
9 => sub { |
224 |
root |
1.4 |
my ($src) = @_; |
225 |
root |
1.12 |
|
226 |
root |
1.5 |
cf::fork_call { |
227 |
root |
1.24 |
Coro::Storable::blocking_nfreeze |
228 |
root |
1.28 |
pom_as_paragraphs_ng |
229 |
root |
1.24 |
+(Pod::POM->new->parse_text ($src->[0])) |
230 |
root |
1.4 |
} |
231 |
|
|
}; |
232 |
root |
1.3 |
} |
233 |
|
|
|
234 |
root |
1.8 |
# format as cfpod-style text |
235 |
root |
1.11 |
sub as_cfpod($) { |
236 |
root |
1.6 |
my ($pars) = @_; |
237 |
|
|
|
238 |
|
|
my $res; |
239 |
|
|
|
240 |
|
|
for my $par (@$pars) { |
241 |
|
|
if ($par->{type} =~ /^head\d+$/) { |
242 |
root |
1.8 |
$res .= "B<$par->{markup}>\n\n"; |
243 |
root |
1.6 |
} elsif ($par->{type} eq "verbatim") { |
244 |
root |
1.16 |
$res .= "$par->{markup}\n\n"; |
245 |
root |
1.6 |
} elsif ($par->{type} eq "item") { |
246 |
root |
1.16 |
$res .= "* I<$par->{markup}>\n\n"; |
247 |
root |
1.6 |
} else { |
248 |
root |
1.8 |
$res .= "$par->{markup}\n\n"; |
249 |
root |
1.6 |
} |
250 |
|
|
} |
251 |
|
|
|
252 |
|
|
$res |
253 |
|
|
} |
254 |
|
|
|
255 |
root |
1.2 |
1; |
256 |
|
|
|