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.4 by root, Wed Apr 18 15:28:18 2007 UTC vs.
Revision 1.27 by root, Tue Nov 6 21:52:55 2012 UTC

1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3#
4# Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5#
6# 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#
11# 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#
16# 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#
20# The authors can be reached via e-mail to <support@deliantra.net>
21#
22
1package cf::pod; 23package cf::pod;
24
25use common::sense;
2 26
3use Pod::POM; 27use Pod::POM;
4 28
5our $indent; 29our $indent;
6our $level; 30our $level;
7our @result; 31our @result;
8 32
9package cf::pod::AsParagraphs; 33package cf::pod::AsParagraphs;
10 34
11use strict; 35use common::sense;
12 36
13use base "Pod::POM::View"; 37use base "Pod::POM::View";
14 38
39my %E = (
40 "<" => "E<lt>",
41 ">" => "E<gt>",
42);
43
15sub asxml($) { 44sub aspod($) {
16 local $_ = $_[0]; 45 local $_ = $_[0];
17 46
18 s/&/&amp;/g; 47 s/[<>]/$E{$1}/g;
19 s/>/&gt;/g;
20 s/</&lt;/g;
21 48
22 $_ 49 $_
23} 50}
24 51
25*view_seq_file = 52sub flatten($) {
26*view_seq_code = 53 local $_ = $_[0];
54
55 s/^\s+//;
56 s/\s+$//;
57 s/\s+/ /g;
58
59 $_
60}
61
62*view_seq_file = sub { "C<$_[1]>" };
63*view_seq_code = sub { "C<$_[1]>" };
27*view_seq_bold = sub { "<b>$_[1]</b>" }; 64*view_seq_bold = sub { "B<$_[1]>" };
28*view_seq_italic = sub { "<i>$_[1]</i>" }; 65*view_seq_italic = sub { "I<$_[1]>" };
66*view_seq_T = sub { "T<$_[1]>" };
67*view_seq_G = sub { "G<$_[1]>" };
29*view_seq_zero = sub { }; 68*view_seq_zero = sub { "Z<>" };
30*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; 69*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text };
31*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; 70*view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" };
32 71
33sub view_seq_text { 72sub view_seq_text {
34 my $text = $_[1]; 73 my $text = $_[1];
35 $text =~ s/\s+/ /g; 74 $text =~ s/\s+/ /g;
36 ::asxml $text 75 aspod $text
37} 76}
38 77
39sub view_seq_link { 78sub view_seq_link {
40 my (undef, $link) = @_; 79 my (undef, $link) = @_;
41 80
42 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 81 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
43 82
44 if ($link =~ /http:/) { 83 if ($link =~ /http:/) {
45 "<u>" . (::asxml $link) . "</u>" 84 "U<" . (aspod $link) . ">"
46 } else { 85 } else {
47 () 86 ()
48 } 87 }
49} 88}
50 89
51sub view_item { 90sub view_item {
52 push @result, { 91 push @result, {
92 type => "item",
53 indent => $indent * 8, 93 indent => $indent * 8,
54 level => $level, 94 level => $level,
55 }; 95 };
56 my $title = $_[1]->title->present ($_[0]); 96 my $title = $_[1]->title->present ($_[0]);
57 $result[-1]{markup} = "$title\n" if length $title; 97 $result[-1]{markup} = $title if length $title;
58 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 98 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
59 local $level = $level + 1; 99 local $level = $level + 1;
60 $_[1]->content->present ($_[0]); 100 $_[1]->content->present ($_[0]);
61 () 101 ()
62} 102}
63 103
64sub view_verbatim { 104sub view_verbatim {
65 push @result, { 105 push @result, {
106 type => "verbatim",
66 indent => $indent * 16, 107 indent => $indent * 16,
67 level => $level, 108 level => $level,
68 markup => "<tt>" . (::asxml $_[1]) . "</tt>\n", 109 markup => $_[1],
69 }; 110 };
70 () 111 ()
71} 112}
72 113
73sub view_textblock { 114sub view_textblock {
74 push @result, { 115 push @result, {
75 indent => $indent * 16, 116 indent => $indent * 16,
76 level => $level, 117 level => $level,
77 markup => "$_[1]\n", 118 markup => flatten $_[1],
78 }; 119 };
79 () 120 ()
80} 121}
81 122
82sub view_head1 { 123sub view_head1 {
83 push @result, { 124 push @result, {
125 type => "head1",
84 indent => $indent * 16, 126 indent => $indent * 16,
85 level => $level, 127 level => $level,
86 }; 128 };
87 my $title = $_[1]->title->present ($_[0]); 129 my $title = $_[1]->title->present ($_[0]);
88 $result[-1]{markup} = "\n\n<h1>$title</h1>\n" if length $title; 130 $result[-1]{markup} = $title if length $title;
89 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 131 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
90 local $level = $level + 1; 132 local $level = $level + 1;
91 $_[1]->content->present ($_[0]); 133 $_[1]->content->present ($_[0]);
92 () 134 ()
93}; 135};
94 136
95sub view_head2 { 137sub view_head2 {
96 push @result, { 138 push @result, {
139 type => "head2",
97 indent => $indent * 16, 140 indent => $indent * 16,
98 level => $level, 141 level => $level,
99 }; 142 };
100 my $title = $_[1]->title->present ($_[0]); 143 my $title = $_[1]->title->present ($_[0]);
101 $result[-1]{markup} = "\n\n<h2>$title</h2>\n" if length $title; 144 $result[-1]{markup} = $title if length $title;
102 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 145 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
103 local $level = $level + 1; 146 local $level = $level + 1;
104 $_[1]->content->present ($_[0]); 147 $_[1]->content->present ($_[0]);
105 () 148 ()
106}; 149};
107 150
108sub view_head3 { 151sub view_head3 {
109 push @result, { 152 push @result, {
153 type => "head3",
110 indent => $indent * 16, 154 indent => $indent * 16,
111 level => $level, 155 level => $level,
112 }; 156 };
113 my $title = $_[1]->title->present ($_[0]); 157 my $title = $_[1]->title->present ($_[0]);
114 $result[-1]{markup} = "\n\n<h3>$title</h3>\n" if length $title; 158 $result[-1]{markup} = $title if length $title;
115 $title = ::flatten $title; unshift @{ $result[-1]{index} }, $title if length $title; 159 $title = flatten $title; unshift @{ $result[-1]{index} }, $title if length $title;
116 local $level = $level + 1; 160 local $level = $level + 1;
117 $_[1]->content->present ($_[0]); 161 $_[1]->content->present ($_[0]);
118 () 162 ()
119}; 163};
120 164
167 211
168sub load_pod($) { 212sub load_pod($) {
169 my ($path) = @_; 213 my ($path) = @_;
170 214
171 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], 215 Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path],
172 1 => sub { 216 8 => sub {
173 my ($src) = @_; 217 my ($src) = @_;
218
174 fork_exec { 219 cf::fork_call {
175 my $pod = $src->[0]; 220 Coro::Storable::blocking_nfreeze
176 utf8::decode $pod; 221 pom_as_paragraphs
177 Coro::Storable::freeze pom_as_paragraphs Pod::POM->new->parse_text ($pod) 222 +(Pod::POM->new->parse_text ($src->[0]))
178 } 223 }
179 }; 224 };
180} 225}
181 226
227# format as cfpod-style text
228sub as_cfpod($) {
229 my ($pars) = @_;
230
231 my $res;
232
233 for my $par (@$pars) {
234 if ($par->{type} =~ /^head\d+$/) {
235 $res .= "B<$par->{markup}>\n\n";
236 } elsif ($par->{type} eq "verbatim") {
237 $res .= "$par->{markup}\n\n";
238 } elsif ($par->{type} eq "item") {
239 $res .= "* I<$par->{markup}>\n\n";
240 } else {
241 $res .= "$par->{markup}\n\n";
242 }
243 }
244
245 $res
246}
247
1821; 2481;
183 249

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines