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.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; # 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::AsXML; 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_code = 24 my $kw = pop @path;
22*view_seq_bold = sub { "<b>$_[1]</b>" };
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 25
28sub view_seq_text { 26 $node = $node->{parent}
29 my $text = $_[1]; 27 or return 0;
30 $text =~ s/\s+/ /g; 28
31 CFClient::asxml $text 29 return ! ! grep $_ eq $kw, @{ $node->{kw} };
32} 30}
33 31
34sub view_item { 32sub find(@) {
35 ("\t" x ($indent / 4)) 33 my (@path) = @_;
36 . $_[1]->title->present ($_[0]) 34
37 . "\n\n" 35 return unless @path;
38 . $_[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}
39} 45}
40 46
41sub view_verbatim { 47sub full_path_of($) {
42 (join "", 48 my ($node) = @_;
43 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n", 49
44 split /\n/, CFClient::asxml $_[1]) 50 my $path = $node->{kw}[0];
45 . "\n" 51 $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
52 $path
46} 53}
47 54
48sub view_textblock { 55sub section_of($) {
49 ("\t" x ($indent / 2)) . "$_[1]\n\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
50} 76}
51 77
52sub view_head1 { 78sub section(@) {
53 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" 79 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} 80}
71 81
72package 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;
73 90
74use strict; 91 $_[1]{$type}($_, @arg)
75 92 }ogex;
76use base "Pod::POM::View"; 93 }
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} 94}
90 95
91sub view_item { 96my %as_label = (
92 push @result, { 97 image => sub {
93 indent => $indent * 8, 98 my ($par, $path) = @_;
94 text => $_[1]->title->present ($_[0]) . "\n\n", 99
100 "<small>img</small>"
95 }; 101 },
96 $_[1]->content->present ($_[0]); 102 link => sub {
97 () 103 my ($par, $text, $link) = @_;
104
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
98} 121}
99 122
100sub view_verbatim { 123my %as_paragraphs = (
101 push @result, { 124 image => sub {
102 indent => $indent * 16, 125 my ($par, $path) = @_;
103 text => "<tt>" . (CFClient::asxml $_[1]) . "</tt>", 126
127 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path;
128
129 "\x{fffc}"
104 }; 130 },
105 () 131 link => sub {
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 @_
106} 153}
107 154
108sub view_textblock { 155sub section_paragraphs(@) {
109 push @result, { 156 as_paragraphs &section
110 indent => $indent * 16,
111 text => "$_[1]\n",
112 };
113 ()
114} 157}
115 158
116sub view_head1 { 159sub section_label(@) {
117 push @result, { 160 as_label &section
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} 161}
149 162
150sub view_for { 1631
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