1 |
root |
1.3 |
package CFPlus::Pod; |
2 |
root |
1.1 |
|
3 |
|
|
use strict; |
4 |
|
|
|
5 |
|
|
use Pod::POM; |
6 |
|
|
|
7 |
root |
1.3 |
use CFPlus; |
8 |
|
|
use CFPlus::UI; |
9 |
root |
1.1 |
|
10 |
root |
1.2 |
our $VERSION = 1.02; # bump if resultant formatting changes |
11 |
root |
1.1 |
|
12 |
|
|
our @result; |
13 |
|
|
our $indent; |
14 |
|
|
|
15 |
root |
1.3 |
package CFPlus::Pod::AsMarkup; |
16 |
root |
1.1 |
|
17 |
|
|
use strict; |
18 |
|
|
|
19 |
|
|
use base "Pod::POM::View::Text"; |
20 |
|
|
|
21 |
root |
1.2 |
*view_seq_file = |
22 |
root |
1.1 |
*view_seq_code = |
23 |
|
|
*view_seq_bold = sub { "<b>$_[1]</b>" }; |
24 |
|
|
*view_seq_italic = sub { "<i>$_[1]</i>" }; |
25 |
|
|
*view_seq_space = |
26 |
root |
1.3 |
*view_seq_link = sub { CFPlus::asxml $_[1] }; |
27 |
root |
1.2 |
*view_seq_zero = |
28 |
|
|
*view_seq_index = sub { }; |
29 |
root |
1.1 |
|
30 |
|
|
sub view_seq_text { |
31 |
|
|
my $text = $_[1]; |
32 |
|
|
$text =~ s/\s+/ /g; |
33 |
root |
1.3 |
CFPlus::asxml $text |
34 |
root |
1.1 |
} |
35 |
|
|
|
36 |
|
|
sub view_item { |
37 |
|
|
("\t" x ($indent / 4)) |
38 |
|
|
. $_[1]->title->present ($_[0]) |
39 |
|
|
. "\n\n" |
40 |
|
|
. $_[1]->content->present ($_[0]) |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
sub view_verbatim { |
44 |
|
|
(join "", |
45 |
|
|
map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n", |
46 |
root |
1.3 |
split /\n/, CFPlus::asxml $_[1]) |
47 |
root |
1.1 |
. "\n" |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
sub view_textblock { |
51 |
root |
1.2 |
("\t" x ($indent / 2)) . "$_[1]\n" |
52 |
root |
1.1 |
} |
53 |
|
|
|
54 |
|
|
sub view_head1 { |
55 |
|
|
"\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
56 |
|
|
. $_[1]->content->present ($_[0]) |
57 |
|
|
}; |
58 |
|
|
|
59 |
|
|
sub view_head2 { |
60 |
|
|
"\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
61 |
|
|
. $_[1]->content->present ($_[0]) |
62 |
|
|
}; |
63 |
|
|
|
64 |
|
|
sub view_head3 { |
65 |
|
|
"\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
66 |
|
|
. $_[1]->content->present ($_[0]) |
67 |
|
|
}; |
68 |
|
|
|
69 |
|
|
sub view_over { |
70 |
|
|
local $indent = $indent + $_[1]->indent; |
71 |
|
|
$_[1]->content->present ($_[0]) |
72 |
|
|
} |
73 |
|
|
|
74 |
root |
1.3 |
package CFPlus::Pod::AsParagraphs; |
75 |
root |
1.1 |
|
76 |
|
|
use strict; |
77 |
|
|
|
78 |
|
|
use base "Pod::POM::View"; |
79 |
|
|
|
80 |
root |
1.2 |
*view_seq_file = |
81 |
root |
1.1 |
*view_seq_code = |
82 |
|
|
*view_seq_bold = sub { "<b>$_[1]</b>" }; |
83 |
|
|
*view_seq_italic = sub { "<i>$_[1]</i>" }; |
84 |
root |
1.2 |
*view_seq_zero = sub { }; |
85 |
|
|
*view_seq_space = sub { my $text = $_[1]; $text =~ s/ / /g; $text }; |
86 |
|
|
*view_seq_index = sub { warn "index<@_>\n"; $result[-1]{index}{$_[1]} = undef }; |
87 |
root |
1.1 |
|
88 |
|
|
sub view_seq_text { |
89 |
|
|
my $text = $_[1]; |
90 |
|
|
$text =~ s/\s+/ /g; |
91 |
root |
1.3 |
CFPlus::asxml $text |
92 |
root |
1.1 |
} |
93 |
|
|
|
94 |
root |
1.2 |
sub view_seq_link { |
95 |
|
|
my (undef, $link) = @_; |
96 |
|
|
|
97 |
|
|
# TODO: |
98 |
|
|
# http://... |
99 |
|
|
# ref |
100 |
|
|
# pod/ref |
101 |
|
|
|
102 |
root |
1.3 |
"<u>" . (CFPlus::asxml $_[1]) . "</u>"; |
103 |
root |
1.2 |
} |
104 |
|
|
|
105 |
root |
1.1 |
sub view_item { |
106 |
|
|
push @result, { |
107 |
|
|
indent => $indent * 8, |
108 |
root |
1.2 |
markup => $_[1]->title->present ($_[0]) . "\n\n", |
109 |
root |
1.1 |
}; |
110 |
|
|
$_[1]->content->present ($_[0]); |
111 |
|
|
() |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
sub view_verbatim { |
115 |
|
|
push @result, { |
116 |
|
|
indent => $indent * 16, |
117 |
root |
1.3 |
markup => "<tt>" . (CFPlus::asxml $_[1]) . "</tt>\n", |
118 |
root |
1.1 |
}; |
119 |
|
|
() |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
sub view_textblock { |
123 |
|
|
push @result, { |
124 |
|
|
indent => $indent * 16, |
125 |
root |
1.2 |
markup => "$_[1]\n", |
126 |
root |
1.1 |
}; |
127 |
|
|
() |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
sub view_head1 { |
131 |
|
|
push @result, { |
132 |
|
|
indent => $indent * 16, |
133 |
root |
1.2 |
markup => "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
134 |
root |
1.1 |
}; |
135 |
|
|
$_[1]->content->present ($_[0]); |
136 |
|
|
() |
137 |
|
|
}; |
138 |
|
|
|
139 |
|
|
sub view_head2 { |
140 |
|
|
push @result, { |
141 |
|
|
indent => $indent * 16, |
142 |
root |
1.2 |
markup => "\n\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
143 |
root |
1.1 |
}; |
144 |
|
|
$_[1]->content->present ($_[0]); |
145 |
|
|
() |
146 |
|
|
}; |
147 |
|
|
|
148 |
|
|
sub view_head3 { |
149 |
|
|
push @result, { |
150 |
|
|
indent => $indent * 16, |
151 |
root |
1.2 |
markup => "\n\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n", |
152 |
root |
1.1 |
}; |
153 |
|
|
$_[1]->content->present ($_[0]); |
154 |
|
|
() |
155 |
|
|
}; |
156 |
|
|
|
157 |
|
|
sub view_over { |
158 |
|
|
local $indent = $indent + $_[1]->indent; |
159 |
|
|
push @result, { indent => $indent }; |
160 |
|
|
$_[1]->content->present ($_[0]); |
161 |
|
|
() |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
sub view_for { |
165 |
|
|
if ($_[1]->format eq "image") { |
166 |
|
|
push @result, { |
167 |
|
|
indent => $indent * 16, |
168 |
root |
1.2 |
markup => "\x{fffc}", |
169 |
root |
1.3 |
widget => [new CFPlus::UI::Image path => "pod/" . $_[1]->text], |
170 |
root |
1.1 |
}; |
171 |
|
|
} |
172 |
|
|
() |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
sub view { |
176 |
|
|
my ($self, $type, $item) = @_; |
177 |
|
|
|
178 |
|
|
$item->content->present ($self); |
179 |
|
|
} |
180 |
|
|
|
181 |
root |
1.3 |
package CFPlus::Pod; |
182 |
root |
1.1 |
|
183 |
root |
1.3 |
my $pod_cache = CFPlus::db_table "pod_cache"; |
184 |
root |
1.1 |
|
185 |
|
|
sub 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 |
root |
1.2 |
my ($chash, $pom) = eval { |
194 |
|
|
local $SIG{__DIE__}; |
195 |
|
|
@{ Storable::thaw $pod_cache->get ("$path/$filtertype") } |
196 |
|
|
}; |
197 |
root |
1.1 |
|
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 |
|
|
|
216 |
root |
1.2 |
sub section($$) { |
217 |
|
|
my ($pod, $section) = @_; |
218 |
|
|
} |
219 |
|
|
|
220 |
|
|
sub as_markup($) { |
221 |
root |
1.1 |
my ($pom) = @_; |
222 |
|
|
|
223 |
|
|
local $indent = 0; |
224 |
|
|
|
225 |
root |
1.3 |
$pom->present ("CFPlus::Pod::AsMarkup") |
226 |
root |
1.1 |
} |
227 |
|
|
|
228 |
|
|
sub as_paragraphs($) { |
229 |
|
|
my ($pom) = @_; |
230 |
|
|
|
231 |
|
|
local @result = ( { } ); |
232 |
|
|
local $indent = 0; |
233 |
|
|
|
234 |
root |
1.3 |
$pom->present ("CFPlus::Pod::AsParagraphs"); |
235 |
root |
1.1 |
|
236 |
root |
1.2 |
[grep exists $_->{markup}, @result] |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
sub pod_paragraphs($) { |
240 |
root |
1.3 |
load CFPlus::find_rcfile "pod/$_[0].pod", |
241 |
root |
1.2 |
pod_paragraphs => 1, sub { as_paragraphs $_[0] }; |
242 |
root |
1.1 |
} |
243 |
|
|
|