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.7 by root, Sun Aug 13 18:48:56 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; 11my $MA_BEG = "\x{fcd0}";
13our $indent; 12my $MA_SEP = "\x{fcd1}";
13my $MA_END = "\x{fcd2}";
14 14
15package CFClient::Pod::AsXML; 15*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
16 16
17use strict; 17sub is_prefix_of($@) {
18 my ($node, @path) = @_;
18 19
19use base "Pod::POM::View::Text"; 20 return 1 unless @path;
20 21
21*view_seq_code = 22 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 23
28sub view_seq_text { 24 $node = $node->{parent}
29 my $text = $_[1]; 25 or return 0;
30 $text =~ s/\s+/ /g; 26
31 CFClient::asxml $text 27 return ! ! grep $_ eq $kw, @{ $node->{kw} };
32} 28}
33 29
34sub view_item { 30sub find(@) {
35 ("\t" x ($indent / 4)) 31 my (@path) = @_;
36 . $_[1]->title->present ($_[0]) 32
37 . "\n\n" 33 return unless @path;
38 . $_[1]->content->present ($_[0]) 34
35 my $kw = pop @path;
36
37 # TODO: make sure results are unique
38
39 grep { is_prefix_of $_, @path }
40 map @$_,
41 $kw eq "*" ? @wiki{sort keys %wiki}
42 : grep $_, $wiki{$kw}
39} 43}
40 44
41sub view_verbatim { 45sub full_path_of($) {
42 (join "", 46 my ($node) = @_;
43 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n", 47
44 split /\n/, CFClient::asxml $_[1]) 48 my $path = $node->{kw}[0];
45 . "\n" 49 $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
50 $path
46} 51}
47 52
48sub view_textblock { 53sub section_of($) {
49 ("\t" x ($indent / 2)) . "$_[1]\n\n" 54 my ($node) = @_;
55
56 my $doc = $node->{doc};
57 my $par = $node->{par};
58 my $lvl = $node->{level};
59
60 my @res;
61
62 do {
63 my $p = $doc->[$par];
64
65 if (length $p->{markup}) {
66 push @res, {
67 markup => $p->{markup},
68 indent => $p->{indent},
69 };
70 }
71 } while $doc->[++$par]{level} > $lvl;
72
73 @res
50} 74}
51 75
52sub view_head1 { 76sub section(@) {
53 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" 77 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} 78}
71 79
72package CFClient::Pod::AsParagraphs; 80sub thaw_section(\@\%) {
81 for (@{$_[0]}) {
82 $_->{markup} =~ s{
83 $MA_BEG
84 ([^$MA_END]+)
85 $MA_END
86 }{
87 my ($type, @arg) = split /$MA_SEP/o, $1;
73 88
74use strict; 89 $_[1]{$type}($_, @arg)
75 90 }ogex;
76use base "Pod::POM::View"; 91 }
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} 92}
90 93
91sub view_item { 94my %as_label = (
92 push @result, { 95 image => sub {
93 indent => $indent * 8, 96 my ($par, $path) = @_;
94 text => $_[1]->title->present ($_[0]) . "\n\n", 97
98 "<small>img</small>"
95 }; 99 },
96 $_[1]->content->present ($_[0]); 100 link => sub {
97 () 101 my ($par, $link) = @_;
102
103 "<big>" . (CFPlus::asxml $link) . "</big>"
104 },
105);
106
107sub as_label(@) {
108 thaw_section @_, %as_label;
109
110 my $text =
111 join "\n",
112 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
113 @_;
114
115 $text =~ s/^\s+//;
116 $text =~ s/\s+$//;
117
118 $text
98} 119}
99 120
100sub view_verbatim { 121my %as_paragraphs = (
101 push @result, { 122 image => sub {
102 indent => $indent * 16, 123 my ($par, $path) = @_;
103 text => "<tt>" . (CFClient::asxml $_[1]) . "</tt>", 124
125 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path;
126
127 "\x{FFFC}"
104 }; 128 },
105 () 129 link => sub {
130 my ($par, $link) = @_;
131
132 "<big>" . (CFPlus::asxml $link) . "</big>"
133 },
134);
135
136sub as_paragraphs(@) {
137 thaw_section @_, %as_paragraphs;
138
139 @_
106} 140}
107 141
108sub view_textblock { 142sub section_paragraphs(@) {
109 push @result, { 143 as_paragraphs &section
110 indent => $indent * 16,
111 text => "$_[1]\n",
112 };
113 ()
114} 144}
115 145
116sub view_head1 { 146sub section_label(@) {
117 push @result, { 147 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} 148}
149 149
150sub view_for { 1501
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