ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf/pod.pm
Revision: 1.21
Committed: Tue Nov 3 23:44:21 2009 UTC (14 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_90, rel-2_92, rel-2_93
Changes since 1.20: +23 -0 lines
Log Message:
tighten copyright statements for files containing no gpl code whatsoever anymore

File Contents

# User Rev Content
1 root 1.21 #
2     #
3     # This file is part of Deliantra, the Roguelike Realtime MMORPG.
4     #
5     # Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6     #
7     # Deliantra is free software: you can redistribute it and/or modify it under
8     # the terms of the Affero GNU General Public License as published by the
9     # Free Software Foundation, either version 3 of the License, or (at your
10     # option) any later version.
11     #
12     # This program is distributed in the hope that it will be useful,
13     # but WITHOUT ANY WARRANTY; without even the implied warranty of
14     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     # GNU General Public License for more details.
16     #
17     # You should have received a copy of the Affero GNU General Public License
18     # and the GNU General Public License along with this program. If not, see
19     # <http://www.gnu.org/licenses/>.
20     #
21     # The authors can be reached via e-mail to <support@deliantra.net>
22     #
23    
24 root 1.2 package cf::pod;
25    
26 root 1.20 use common::sense;
27    
28 root 1.3 use Pod::POM;
29    
30 root 1.2 our $indent;
31     our $level;
32     our @result;
33    
34     package cf::pod::AsParagraphs;
35    
36 root 1.20 use common::sense;
37 root 1.2
38     use base "Pod::POM::View";
39    
40 root 1.15 my %E = (
41     "<" => "E<lt>",
42     ">" => "E<gt>",
43     );
44    
45 root 1.14 sub aspod($) {
46 root 1.2 local $_ = $_[0];
47    
48 root 1.15 s/[<>]/$E{$1}/g;
49 root 1.2
50     $_
51     }
52    
53 root 1.5 sub flatten($) {
54     local $_ = $_[0];
55    
56     s/^\s+//;
57     s/\s+$//;
58     s/\s+/ /g;
59    
60     $_
61     }
62    
63 root 1.17 *view_seq_file = sub { "C<$_[1]>" };
64     *view_seq_code = sub { "C<$_[1]>" };
65 root 1.13 *view_seq_bold = sub { "B<$_[1]>" };
66     *view_seq_italic = sub { "I<$_[1]>" };
67 root 1.19 *view_seq_T = sub { "T<$_[1]>" };
68     *view_seq_G = sub { "G<$_[1]>" };
69 root 1.14 *view_seq_zero = sub { "Z<>" };
70 root 1.2 *view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text };
71     *view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
72    
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     ()
88     }
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.3 sub pom_as_paragraphs($) {
199 root 1.2 my ($pom) = @_;
200    
201     # we suckers use global variables, unfortunately.
202     my $guard = cf::lock_acquire "cf::pod::as_paragraphs";
203    
204     local $indent = 0;
205     local $level = 1;
206     local @result = ( { } );
207    
208     $pom->present ("cf::pod::AsParagraphs");
209    
210     [grep $_->{index} || exists $_->{markup}, @result]
211     }
212    
213 root 1.3 sub load_pod($) {
214     my ($path) = @_;
215    
216 root 1.4 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
217 root 1.18 7 => sub {
218 root 1.4 my ($src) = @_;
219 root 1.12
220 root 1.5 cf::fork_call {
221 root 1.4 my $pod = $src->[0];
222     utf8::decode $pod;
223 root 1.12 Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod))
224 root 1.4 }
225     };
226 root 1.3 }
227    
228 root 1.8 # format as cfpod-style text
229 root 1.11 sub as_cfpod($) {
230 root 1.6 my ($pars) = @_;
231    
232     my $res;
233    
234     for my $par (@$pars) {
235     if ($par->{type} =~ /^head\d+$/) {
236 root 1.8 $res .= "B<$par->{markup}>\n\n";
237 root 1.6 } elsif ($par->{type} eq "verbatim") {
238 root 1.16 $res .= "$par->{markup}\n\n";
239 root 1.6 } elsif ($par->{type} eq "item") {
240 root 1.16 $res .= "* I<$par->{markup}>\n\n";
241 root 1.6 } else {
242 root 1.8 $res .= "$par->{markup}\n\n";
243 root 1.6 }
244     }
245    
246     $res
247     }
248    
249 root 1.2 1;
250