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.2 by root, Mon Jul 24 08:23:28 2006 UTC vs.
Revision 1.8 by root, Sun Aug 13 19:47:05 2006 UTC

1package CFClient::Pod; 1package CFPlus::Pod;
2 2
3use strict; 3use strict;
4use utf8;
4 5
5use Pod::POM; 6use Storable;
6 7
7use CFClient; 8our $VERSION = 1;
8use CFClient::UI;
9 9
10our $VERSION = 1.02; # bump if resultant formatting changes 10our $on_link = sub { };
11our %wiki;
11 12
12our @result; 13my $MA_BEG = "\x{fcd0}";
13our $indent; 14my $MA_SEP = "\x{fcd1}";
15my $MA_END = "\x{fcd2}";
14 16
15package CFClient::Pod::AsMarkup; 17*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
16 18
17use strict; 19sub is_prefix_of($@) {
20 my ($node, @path) = @_;
18 21
19use base "Pod::POM::View::Text"; 22 return 1 unless @path;
20 23
21*view_seq_file = 24 my $kw = pop @path;
22*view_seq_code =
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 { CFClient::asxml $_[1] };
27*view_seq_zero =
28*view_seq_index = sub { };
29 25
30sub view_seq_text { 26 $node = $node->{parent}
31 my $text = $_[1]; 27 or return 0;
32 $text =~ s/\s+/ /g; 28
33 CFClient::asxml $text 29 return ! ! grep $_ eq $kw, @{ $node->{kw} };
34} 30}
35 31
36sub view_item { 32sub find(@) {
37 ("\t" x ($indent / 4)) 33 my (@path) = @_;
38 . $_[1]->title->present ($_[0]) 34
39 . "\n\n" 35 return unless @path;
40 . $_[1]->content->present ($_[0]) 36
37 my $kw = pop @path;
38
39 # TODO: make sure results are unique
40
41 grep { is_prefix_of $_, @path }
42 map @$_,
43 $kw eq "*" ? @wiki{sort keys %wiki}
44 : grep $_, $wiki{$kw}
41} 45}
42 46
43sub view_verbatim { 47sub full_path_of($) {
44 (join "", 48 my ($node) = @_;
45 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n", 49
46 split /\n/, CFClient::asxml $_[1]) 50 my $path = $node->{kw}[0];
47 . "\n" 51 $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
52 $path
48} 53}
49 54
50sub view_textblock { 55sub section_of($) {
51 ("\t" x ($indent / 2)) . "$_[1]\n" 56 my ($node) = @_;
57
58 my $doc = $node->{doc};
59 my $par = $node->{par};
60 my $lvl = $node->{level};
61
62 my @res;
63
64 do {
65 my $p = $doc->[$par];
66
67 if (length $p->{markup}) {
68 push @res, {
69 markup => $p->{markup},
70 indent => $p->{indent},
71 };
72 }
73 } while $doc->[++$par]{level} > $lvl;
74
75 @res
52} 76}
53 77
54sub view_head1 { 78sub section(@) {
55 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" 79 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} 80}
73 81
74package CFClient::Pod::AsParagraphs; 82sub thaw_section(\@\%) {
83 for (@{$_[0]}) {
84 $_->{markup} =~ s{
85 $MA_BEG
86 ([^$MA_END]+)
87 $MA_END
88 }{
89 my ($type, @arg) = split /$MA_SEP/o, $1;
75 90
76use strict; 91 $_[1]{$type}($_, @arg)
77 92 }ogex;
78use base "Pod::POM::View"; 93 }
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 CFClient::asxml $text
92} 94}
93 95
94sub view_seq_link { 96my %as_label = (
95 my (undef, $link) = @_; 97 image => sub {
98 my ($par, $path) = @_;
96 99
97 # TODO: 100 "<small>img</small>"
98 # http://... 101 },
99 # ref 102 link => sub {
100 # pod/ref 103 my ($par, $text, $link) = @_;
101 104
102 "<u>" . (CFClient::asxml $_[1]) . "</u>"; 105 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>"
106 },
107);
108
109sub as_label(@) {
110 thaw_section @_, %as_label;
111
112 my $text =
113 join "\n",
114 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
115 @_;
116
117 $text =~ s/^\s+//;
118 $text =~ s/\s+$//;
119
120 $text
103} 121}
104 122
105sub view_item { 123my %as_paragraphs = (
106 push @result, { 124 image => sub {
107 indent => $indent * 8, 125 my ($par, $path) = @_;
108 markup => $_[1]->title->present ($_[0]) . "\n\n", 126
127 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path;
128
129 "\x{fffc}"
109 }; 130 },
110 $_[1]->content->present ($_[0]); 131 link => sub {
111 () 132 my ($par, $text, $link) = @_;
133
134 push @{ $par->{widget} }, new CFPlus::UI::Label
135 markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>",
136 size => 0.8,
137 can_hover => 1,
138 can_events => 1,
139 padding_x => 0,
140 padding_y => 0,
141 on_button_up => sub {
142 $on_link->(split /\//, $link);
143 };
144
145 "\x{fffc}"
146 },
147);
148
149sub as_paragraphs(@) {
150 thaw_section @_, %as_paragraphs;
151
152 @_
112} 153}
113 154
114sub view_verbatim { 155sub section_paragraphs(@) {
115 push @result, { 156 as_paragraphs &section
116 indent => $indent * 16,
117 markup => "<tt>" . (CFClient::asxml $_[1]) . "</tt>\n",
118 };
119 ()
120} 157}
121 158
122sub view_textblock { 159sub section_label(@) {
123 push @result, { 160 as_label &section
124 indent => $indent * 16,
125 markup => "$_[1]\n",
126 };
127 ()
128} 161}
129 162
130sub view_head1 { 1631
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 CFClient::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 CFClient::Pod;
182
183my $pod_cache = CFClient::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 ("CFClient::Pod::AsMarkup")
226}
227
228sub as_paragraphs($) {
229 my ($pom) = @_;
230
231 local @result = ( { } );
232 local $indent = 0;
233
234 $pom->present ("CFClient::Pod::AsParagraphs");
235
236 [grep exists $_->{markup}, @result]
237}
238
239sub pod_paragraphs($) {
240 load CFClient::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