… | |
… | |
5 | use Pod::POM; |
5 | use Pod::POM; |
6 | |
6 | |
7 | use CFClient; |
7 | use CFClient; |
8 | use CFClient::UI; |
8 | use CFClient::UI; |
9 | |
9 | |
10 | our $VERSION = 1; # bump if resultant formatting changes |
10 | our $VERSION = 1.02; # bump if resultant formatting changes |
11 | |
11 | |
12 | our @result; |
12 | our @result; |
13 | our $indent; |
13 | our $indent; |
14 | |
14 | |
15 | package CFClient::Pod::AsXML; |
15 | package CFClient::Pod::AsMarkup; |
16 | |
16 | |
17 | use strict; |
17 | use strict; |
18 | |
18 | |
19 | use base "Pod::POM::View::Text"; |
19 | use base "Pod::POM::View::Text"; |
20 | |
20 | |
|
|
21 | *view_seq_file = |
21 | *view_seq_code = |
22 | *view_seq_code = |
22 | *view_seq_bold = sub { "<b>$_[1]</b>" }; |
23 | *view_seq_bold = sub { "<b>$_[1]</b>" }; |
23 | *view_seq_italic = sub { "<i>$_[1]</i>" }; |
24 | *view_seq_italic = sub { "<i>$_[1]</i>" }; |
24 | *view_seq_space = |
25 | *view_seq_space = |
25 | *view_seq_link = |
|
|
26 | *view_seq_index = sub { CFClient::asxml $_[1] }; |
26 | *view_seq_link = sub { CFClient::asxml $_[1] }; |
|
|
27 | *view_seq_zero = |
|
|
28 | *view_seq_index = sub { }; |
27 | |
29 | |
28 | sub view_seq_text { |
30 | sub view_seq_text { |
29 | my $text = $_[1]; |
31 | my $text = $_[1]; |
30 | $text =~ s/\s+/ /g; |
32 | $text =~ s/\s+/ /g; |
31 | CFClient::asxml $text |
33 | CFClient::asxml $text |
… | |
… | |
44 | split /\n/, CFClient::asxml $_[1]) |
46 | split /\n/, CFClient::asxml $_[1]) |
45 | . "\n" |
47 | . "\n" |
46 | } |
48 | } |
47 | |
49 | |
48 | sub view_textblock { |
50 | sub view_textblock { |
49 | ("\t" x ($indent / 2)) . "$_[1]\n\n" |
51 | ("\t" x ($indent / 2)) . "$_[1]\n" |
50 | } |
52 | } |
51 | |
53 | |
52 | sub view_head1 { |
54 | sub view_head1 { |
53 | "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
55 | "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
54 | . $_[1]->content->present ($_[0]) |
56 | . $_[1]->content->present ($_[0]) |
… | |
… | |
73 | |
75 | |
74 | use strict; |
76 | use strict; |
75 | |
77 | |
76 | use base "Pod::POM::View"; |
78 | use base "Pod::POM::View"; |
77 | |
79 | |
|
|
80 | *view_seq_file = |
78 | *view_seq_code = |
81 | *view_seq_code = |
79 | *view_seq_bold = sub { "<b>$_[1]</b>" }; |
82 | *view_seq_bold = sub { "<b>$_[1]</b>" }; |
80 | *view_seq_italic = sub { "<i>$_[1]</i>" }; |
83 | *view_seq_italic = sub { "<i>$_[1]</i>" }; |
81 | *view_seq_space = |
84 | *view_seq_zero = sub { }; |
82 | *view_seq_link = |
85 | *view_seq_space = sub { my $text = $_[1]; $text =~ s/ / /g; $text }; |
83 | *view_seq_index = sub { CFClient::asxml $_[1] }; |
86 | *view_seq_index = sub { warn "index<@_>\n"; $result[-1]{index}{$_[1]} = undef }; |
84 | |
87 | |
85 | sub view_seq_text { |
88 | sub view_seq_text { |
86 | my $text = $_[1]; |
89 | my $text = $_[1]; |
87 | $text =~ s/\s+/ /g; |
90 | $text =~ s/\s+/ /g; |
88 | CFClient::asxml $text |
91 | CFClient::asxml $text |
89 | } |
92 | } |
90 | |
93 | |
|
|
94 | sub view_seq_link { |
|
|
95 | my (undef, $link) = @_; |
|
|
96 | |
|
|
97 | # TODO: |
|
|
98 | # http://... |
|
|
99 | # ref |
|
|
100 | # pod/ref |
|
|
101 | |
|
|
102 | "<u>" . (CFClient::asxml $_[1]) . "</u>"; |
|
|
103 | } |
|
|
104 | |
91 | sub view_item { |
105 | sub view_item { |
92 | push @result, { |
106 | push @result, { |
93 | indent => $indent * 8, |
107 | indent => $indent * 8, |
94 | text => $_[1]->title->present ($_[0]) . "\n\n", |
108 | markup => $_[1]->title->present ($_[0]) . "\n\n", |
95 | }; |
109 | }; |
96 | $_[1]->content->present ($_[0]); |
110 | $_[1]->content->present ($_[0]); |
97 | () |
111 | () |
98 | } |
112 | } |
99 | |
113 | |
100 | sub view_verbatim { |
114 | sub view_verbatim { |
101 | push @result, { |
115 | push @result, { |
102 | indent => $indent * 16, |
116 | indent => $indent * 16, |
103 | text => "<tt>" . (CFClient::asxml $_[1]) . "</tt>", |
117 | markup => "<tt>" . (CFClient::asxml $_[1]) . "</tt>\n", |
104 | }; |
118 | }; |
105 | () |
119 | () |
106 | } |
120 | } |
107 | |
121 | |
108 | sub view_textblock { |
122 | sub view_textblock { |
109 | push @result, { |
123 | push @result, { |
110 | indent => $indent * 16, |
124 | indent => $indent * 16, |
111 | text => "$_[1]\n", |
125 | markup => "$_[1]\n", |
112 | }; |
126 | }; |
113 | () |
127 | () |
114 | } |
128 | } |
115 | |
129 | |
116 | sub view_head1 { |
130 | sub view_head1 { |
117 | push @result, { |
131 | push @result, { |
118 | indent => $indent * 16, |
132 | indent => $indent * 16, |
119 | text => "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
133 | markup => "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
120 | }; |
134 | }; |
121 | $_[1]->content->present ($_[0]); |
135 | $_[1]->content->present ($_[0]); |
122 | () |
136 | () |
123 | }; |
137 | }; |
124 | |
138 | |
125 | sub view_head2 { |
139 | sub view_head2 { |
126 | push @result, { |
140 | push @result, { |
127 | indent => $indent * 16, |
141 | indent => $indent * 16, |
128 | text => "\n\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
142 | markup => "\n\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
129 | }; |
143 | }; |
130 | $_[1]->content->present ($_[0]); |
144 | $_[1]->content->present ($_[0]); |
131 | () |
145 | () |
132 | }; |
146 | }; |
133 | |
147 | |
134 | sub view_head3 { |
148 | sub view_head3 { |
135 | push @result, { |
149 | push @result, { |
136 | indent => $indent * 16, |
150 | indent => $indent * 16, |
137 | text => "\n\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
151 | markup => "\n\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
138 | }; |
152 | }; |
139 | $_[1]->content->present ($_[0]); |
153 | $_[1]->content->present ($_[0]); |
140 | () |
154 | () |
141 | }; |
155 | }; |
142 | |
156 | |
… | |
… | |
149 | |
163 | |
150 | sub view_for { |
164 | sub view_for { |
151 | if ($_[1]->format eq "image") { |
165 | if ($_[1]->format eq "image") { |
152 | push @result, { |
166 | push @result, { |
153 | indent => $indent * 16, |
167 | indent => $indent * 16, |
154 | text => "\x{fffc}", |
168 | markup => "\x{fffc}", |
155 | obj => [new CFClient::UI::Image path => "pod/" . $_[1]->text], |
169 | widget => [new CFClient::UI::Image path => "pod/" . $_[1]->text], |
156 | }; |
170 | }; |
157 | } |
171 | } |
158 | () |
172 | () |
159 | } |
173 | } |
160 | |
174 | |
… | |
… | |
174 | stat $path |
188 | stat $path |
175 | or die "$path: $!"; |
189 | or die "$path: $!"; |
176 | |
190 | |
177 | my $phash = join ",", $filterversion, $VERSION, (stat _)[7,9]; |
191 | my $phash = join ",", $filterversion, $VERSION, (stat _)[7,9]; |
178 | |
192 | |
|
|
193 | my ($chash, $pom) = eval { |
|
|
194 | local $SIG{__DIE__}; |
179 | my ($chash, $pom) = eval { @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } }; |
195 | @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } |
|
|
196 | }; |
180 | |
197 | |
181 | return $pom if $chash eq $phash; |
198 | return $pom if $chash eq $phash; |
182 | |
199 | |
183 | my $pod = do { |
200 | my $pod = do { |
184 | local $/; |
201 | local $/; |
… | |
… | |
194 | $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]); |
211 | $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]); |
195 | |
212 | |
196 | $pom |
213 | $pom |
197 | } |
214 | } |
198 | |
215 | |
|
|
216 | sub section($$) { |
|
|
217 | my ($pod, $section) = @_; |
|
|
218 | } |
|
|
219 | |
199 | sub as_xml($) { |
220 | sub as_markup($) { |
200 | my ($pom) = @_; |
221 | my ($pom) = @_; |
201 | |
222 | |
202 | local $indent = 0; |
223 | local $indent = 0; |
203 | |
224 | |
204 | $pom->present ("CFClient::Pod::AsXML") |
225 | $pom->present ("CFClient::Pod::AsMarkup") |
205 | } |
226 | } |
206 | |
227 | |
207 | sub as_paragraphs($) { |
228 | sub as_paragraphs($) { |
208 | my ($pom) = @_; |
229 | my ($pom) = @_; |
209 | |
230 | |
210 | local @result = ( { } ); |
231 | local @result = ( { } ); |
211 | local $indent = 0; |
232 | local $indent = 0; |
212 | |
233 | |
213 | $pom->present ("CFClient::Pod::AsParagraphs"); |
234 | $pom->present ("CFClient::Pod::AsParagraphs"); |
214 | |
235 | |
215 | [grep exists $_->{text}, @result] |
236 | [grep exists $_->{markup}, @result] |
216 | } |
237 | } |
217 | |
238 | |
|
|
239 | sub pod_paragraphs($) { |
|
|
240 | load CFClient::find_rcfile "pod/$_[0].pod", |
|
|
241 | pod_paragraphs => 1, sub { as_paragraphs $_[0] }; |
|
|
242 | } |
|
|
243 | |