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.1 by root, Sun Jul 23 16:11:12 2006 UTC vs.
Revision 1.6 by root, Sun Aug 13 14:30:06 2006 UTC

1package CFClient::Pod; 1package CFPlus::Pod;
2 2
3use strict; 3use strict;
4 4
5use Pod::POM; 5use Storable;
6 6
7use CFClient; 7our $VERSION = 1;
8use CFClient::UI;
9 8
10our $VERSION = 1; # 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 CFClient::Pod::AsXML; 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_code = 20 $node = $node->{parent}
22*view_seq_bold = sub { "<b>$_[1]</b>" }; 21 or return 0;
23*view_seq_italic = sub { "<i>$_[1]</i>" };
24*view_seq_space =
25*view_seq_link =
26*view_seq_index = sub { CFClient::asxml $_[1] };
27 22
28sub view_seq_text { 23 return ! ! grep $_ eq $kw, @{ $node->{kw} };
29 my $text = $_[1];
30 $text =~ s/\s+/ /g;
31 CFClient::asxml $text
32} 24}
33 25
34sub view_item { 26sub find(@) {
35 ("\t" x ($indent / 4)) 27 my (@path) = @_;
36 . $_[1]->title->present ($_[0]) 28
37 . "\n\n" 29 return unless @path;
38 . $_[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}
39} 39}
40 40
41sub view_verbatim { 41sub full_path_of($) {
42 (join "", 42 my ($node) = @_;
43 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n", 43
44 split /\n/, CFClient::asxml $_[1]) 44 my $path = $node->{kw}[0];
45 . "\n" 45 $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
46 $path
46} 47}
47 48
48sub view_textblock { 49sub section_of($) {
49 ("\t" x ($indent / 2)) . "$_[1]\n\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
50} 77}
51 78
52sub view_head1 { 79sub section(@) {
53 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" 80 map section_of $_, &find
54 . $_[1]->content->present ($_[0])
55};
56
57sub view_head2 {
58 "\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
59 . $_[1]->content->present ($_[0])
60};
61
62sub view_head3 {
63 "\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
64 . $_[1]->content->present ($_[0])
65};
66
67sub view_over {
68 local $indent = $indent + $_[1]->indent;
69 $_[1]->content->present ($_[0])
70} 81}
71 82
72package CFClient::Pod::AsParagraphs; 83sub as_label(@) {
84 my $text =
85 join "\n",
86 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
87 @_;
73 88
74use strict; 89 $text =~ s/^\s+//;
90 $text =~ s/\s+$//;
75 91
76use base "Pod::POM::View"; 92 $text
77
78*view_seq_code =
79*view_seq_bold = sub { "<b>$_[1]</b>" };
80*view_seq_italic = sub { "<i>$_[1]</i>" };
81*view_seq_space =
82*view_seq_link =
83*view_seq_index = sub { CFClient::asxml $_[1] };
84
85sub view_seq_text {
86 my $text = $_[1];
87 $text =~ s/\s+/ /g;
88 CFClient::asxml $text
89} 93}
90 94
91sub view_item { 95sub section_label(@) {
92 push @result, { 96 as_label &section
93 indent => $indent * 8,
94 text => $_[1]->title->present ($_[0]) . "\n\n",
95 };
96 $_[1]->content->present ($_[0]);
97 ()
98} 97}
99 98
100sub view_verbatim { 991
101 push @result, {
102 indent => $indent * 16,
103 text => "<tt>" . (CFClient::asxml $_[1]) . "</tt>",
104 };
105 ()
106}
107
108sub view_textblock {
109 push @result, {
110 indent => $indent * 16,
111 text => "$_[1]\n",
112 };
113 ()
114}
115
116sub view_head1 {
117 push @result, {
118 indent => $indent * 16,
119 text => "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n",
120 };
121 $_[1]->content->present ($_[0]);
122 ()
123};
124
125sub view_head2 {
126 push @result, {
127 indent => $indent * 16,
128 text => "\n\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n",
129 };
130 $_[1]->content->present ($_[0]);
131 ()
132};
133
134sub view_head3 {
135 push @result, {
136 indent => $indent * 16,
137 text => "\n\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n",
138 };
139 $_[1]->content->present ($_[0]);
140 ()
141};
142
143sub view_over {
144 local $indent = $indent + $_[1]->indent;
145 push @result, { indent => $indent };
146 $_[1]->content->present ($_[0]);
147 ()
148}
149
150sub view_for {
151 if ($_[1]->format eq "image") {
152 push @result, {
153 indent => $indent * 16,
154 text => "\x{fffc}",
155 obj => [new CFClient::UI::Image path => "pod/" . $_[1]->text],
156 };
157 }
158 ()
159}
160
161sub view {
162 my ($self, $type, $item) = @_;
163
164 $item->content->present ($self);
165}
166
167package CFClient::Pod;
168
169my $pod_cache = CFClient::db_table "pod_cache";
170
171sub load($$$$) {
172 my ($path, $filtertype, $filterversion, $filtercb) = @_;
173
174 stat $path
175 or die "$path: $!";
176
177 my $phash = join ",", $filterversion, $VERSION, (stat _)[7,9];
178
179 my ($chash, $pom) = eval { @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } };
180
181 return $pom if $chash eq $phash;
182
183 my $pod = do {
184 local $/;
185 open my $pod, "<:utf8", $_[0]
186 or die "$_[0]: $!";
187 <$pod>
188 };
189
190 #utf8::downgrade $pod;
191
192 $pom = $filtercb->(Pod::POM->new->parse_text ($pod));
193
194 $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]);
195
196 $pom
197}
198
199sub as_xml($) {
200 my ($pom) = @_;
201
202 local $indent = 0;
203
204 $pom->present ("CFClient::Pod::AsXML")
205}
206
207sub as_paragraphs($) {
208 my ($pom) = @_;
209
210 local @result = ( { } );
211 local $indent = 0;
212
213 $pom->present ("CFClient::Pod::AsParagraphs");
214
215 [grep exists $_->{text}, @result]
216}
217

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines