ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Pod.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Pod.pm (file contents):
Revision 1.3 by root, Sun Jul 30 13:16:44 2006 UTC vs.
Revision 1.6 by root, Sun Aug 13 14:30:06 2006 UTC

1package CFPlus::Pod; 1package CFPlus::Pod;
2 2
3use strict; 3use strict;
4 4
5use Pod::POM; 5use Storable;
6 6
7use CFPlus; 7our $VERSION = 1;
8use CFPlus::UI;
9 8
10our $VERSION = 1.02; # bump if resultant formatting changes 9our %wiki;
11 10
12our @result; 11*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
13our $indent;
14 12
15package CFPlus::Pod::AsMarkup; 13sub is_prefix_of($@) {
14 my ($node, @path) = @_;
16 15
17use strict; 16 return 1 unless @path;
18 17
19use base "Pod::POM::View::Text"; 18 my $kw = pop @path;
20 19
21*view_seq_file = 20 $node = $node->{parent}
22*view_seq_code = 21 or return 0;
23*view_seq_bold = sub { "<b>$_[1]</b>" };
24*view_seq_italic = sub { "<i>$_[1]</i>" };
25*view_seq_space =
26*view_seq_link = sub { CFPlus::asxml $_[1] };
27*view_seq_zero =
28*view_seq_index = sub { };
29 22
30sub view_seq_text { 23 return ! ! grep $_ eq $kw, @{ $node->{kw} };
31 my $text = $_[1];
32 $text =~ s/\s+/ /g;
33 CFPlus::asxml $text
34} 24}
35 25
36sub view_item { 26sub find(@) {
37 ("\t" x ($indent / 4)) 27 my (@path) = @_;
38 . $_[1]->title->present ($_[0]) 28
39 . "\n\n" 29 return unless @path;
40 . $_[1]->content->present ($_[0]) 30
31 my $kw = pop @path;
32
33 # TODO: make sure results are unique
34
35 grep { is_prefix_of $_, @path }
36 map @$_,
37 $kw eq "*" ? @wiki{sort keys %wiki}
38 : grep $_, $wiki{$kw}
41} 39}
42 40
43sub view_verbatim { 41sub full_path_of($) {
44 (join "", 42 my ($node) = @_;
45 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n", 43
46 split /\n/, CFPlus::asxml $_[1]) 44 my $path = $node->{kw}[0];
47 . "\n" 45 $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
46 $path
48} 47}
49 48
50sub view_textblock { 49sub section_of($) {
51 ("\t" x ($indent / 2)) . "$_[1]\n" 50 my ($node) = @_;
51
52 my $doc = $node->{doc};
53 my $par = $node->{par};
54 my $lvl = $node->{level};
55
56 my @res;
57
58 do {
59 my $p = $doc->[$par];
60
61 if (exists $p->{markup}) {
62 my %para = (
63 markup => $p->{markup},
64 indent => $p->{indent},
65 );
66
67 for (@{ $p->{widget} || [] }) {
68 my ($class, @args) = @$_;
69 push @{ $para{widget} }, $class->new (@args);
70 }
71
72 push @res, \%para;
73 }
74 } while $doc->[++$par]{level} > $lvl;
75
76 @res
52} 77}
53 78
54sub view_head1 { 79sub section(@) {
55 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" 80 map section_of $_, &find
56 . $_[1]->content->present ($_[0])
57};
58
59sub view_head2 {
60 "\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
61 . $_[1]->content->present ($_[0])
62};
63
64sub view_head3 {
65 "\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
66 . $_[1]->content->present ($_[0])
67};
68
69sub view_over {
70 local $indent = $indent + $_[1]->indent;
71 $_[1]->content->present ($_[0])
72} 81}
73 82
74package CFPlus::Pod::AsParagraphs; 83sub as_label(@) {
84 my $text =
85 join "\n",
86 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
87 @_;
75 88
76use strict; 89 $text =~ s/^\s+//;
90 $text =~ s/\s+$//;
77 91
78use base "Pod::POM::View"; 92 $text
79
80*view_seq_file =
81*view_seq_code =
82*view_seq_bold = sub { "<b>$_[1]</b>" };
83*view_seq_italic = sub { "<i>$_[1]</i>" };
84*view_seq_zero = sub { };
85*view_seq_space = sub { my $text = $_[1]; $text =~ s/ /&#160;/g; $text };
86*view_seq_index = sub { warn "index<@_>\n"; $result[-1]{index}{$_[1]} = undef };
87
88sub view_seq_text {
89 my $text = $_[1];
90 $text =~ s/\s+/ /g;
91 CFPlus::asxml $text
92} 93}
93 94
94sub view_seq_link { 95sub section_label(@) {
95 my (undef, $link) = @_; 96 as_label &section
96
97 # TODO:
98 # http://...
99 # ref
100 # pod/ref
101
102 "<u>" . (CFPlus::asxml $_[1]) . "</u>";
103} 97}
104 98
105sub view_item { 991
106 push @result, {
107 indent => $indent * 8,
108 markup => $_[1]->title->present ($_[0]) . "\n\n",
109 };
110 $_[1]->content->present ($_[0]);
111 ()
112}
113
114sub view_verbatim {
115 push @result, {
116 indent => $indent * 16,
117 markup => "<tt>" . (CFPlus::asxml $_[1]) . "</tt>\n",
118 };
119 ()
120}
121
122sub view_textblock {
123 push @result, {
124 indent => $indent * 16,
125 markup => "$_[1]\n",
126 };
127 ()
128}
129
130sub view_head1 {
131 push @result, {
132 indent => $indent * 16,
133 markup => "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n",
134 };
135 $_[1]->content->present ($_[0]);
136 ()
137};
138
139sub view_head2 {
140 push @result, {
141 indent => $indent * 16,
142 markup => "\n\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n",
143 };
144 $_[1]->content->present ($_[0]);
145 ()
146};
147
148sub view_head3 {
149 push @result, {
150 indent => $indent * 16,
151 markup => "\n\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n",
152 };
153 $_[1]->content->present ($_[0]);
154 ()
155};
156
157sub view_over {
158 local $indent = $indent + $_[1]->indent;
159 push @result, { indent => $indent };
160 $_[1]->content->present ($_[0]);
161 ()
162}
163
164sub view_for {
165 if ($_[1]->format eq "image") {
166 push @result, {
167 indent => $indent * 16,
168 markup => "\x{fffc}",
169 widget => [new CFPlus::UI::Image path => "pod/" . $_[1]->text],
170 };
171 }
172 ()
173}
174
175sub view {
176 my ($self, $type, $item) = @_;
177
178 $item->content->present ($self);
179}
180
181package CFPlus::Pod;
182
183my $pod_cache = CFPlus::db_table "pod_cache";
184
185sub load($$$$) {
186 my ($path, $filtertype, $filterversion, $filtercb) = @_;
187
188 stat $path
189 or die "$path: $!";
190
191 my $phash = join ",", $filterversion, $VERSION, (stat _)[7,9];
192
193 my ($chash, $pom) = eval {
194 local $SIG{__DIE__};
195 @{ Storable::thaw $pod_cache->get ("$path/$filtertype") }
196 };
197
198 return $pom if $chash eq $phash;
199
200 my $pod = do {
201 local $/;
202 open my $pod, "<:utf8", $_[0]
203 or die "$_[0]: $!";
204 <$pod>
205 };
206
207 #utf8::downgrade $pod;
208
209 $pom = $filtercb->(Pod::POM->new->parse_text ($pod));
210
211 $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]);
212
213 $pom
214}
215
216sub section($$) {
217 my ($pod, $section) = @_;
218}
219
220sub as_markup($) {
221 my ($pom) = @_;
222
223 local $indent = 0;
224
225 $pom->present ("CFPlus::Pod::AsMarkup")
226}
227
228sub as_paragraphs($) {
229 my ($pom) = @_;
230
231 local @result = ( { } );
232 local $indent = 0;
233
234 $pom->present ("CFPlus::Pod::AsParagraphs");
235
236 [grep exists $_->{markup}, @result]
237}
238
239sub pod_paragraphs($) {
240 load CFPlus::find_rcfile "pod/$_[0].pod",
241 pod_paragraphs => 1, sub { as_paragraphs $_[0] };
242}
243

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines