line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Templer::Site::Page - An interface to a site page. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use strict; |
11
|
|
|
|
|
|
|
use warnings; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Templer::Site::Page; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $page = Templer::Site::Page->new( file => "./input/foo.wgn" ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
A page is any non-directory beneath the input-directory which matches the |
22
|
|
|
|
|
|
|
pattern specified by the user (defaults to "*.skx"). |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Pages are processed via the L<HTML::Template> module to create the suitable |
25
|
|
|
|
|
|
|
output. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
In C<templer> the page objects are created by the L<Templer::Site> module. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 LICENSE |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
34
|
|
|
|
|
|
|
under the terms of either: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free Software |
37
|
|
|
|
|
|
|
Foundation; either version 2, or (at your option) any later version, |
38
|
|
|
|
|
|
|
or |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
b) the Perl "Artistic License". |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 AUTHOR |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Copyright (C) 2012-2015 Steve Kemp <steve@steve.org.uk>. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
55
|
|
|
|
|
|
|
the same terms as Perl itself. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
11
|
|
|
11
|
|
35
|
use strict; |
|
11
|
|
|
|
|
11
|
|
|
11
|
|
|
|
|
241
|
|
65
|
11
|
|
|
11
|
|
44
|
use warnings; |
|
11
|
|
|
|
|
10
|
|
|
11
|
|
|
|
|
6151
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
package Templer::Site::Page; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 new |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The constructor. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The single appropriate argument is the hash-key "file", pointing to the |
77
|
|
|
|
|
|
|
page-file on-disk. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub new |
82
|
|
|
|
|
|
|
{ |
83
|
9
|
|
|
9
|
1
|
7729
|
my ( $proto, %supplied ) = (@_); |
84
|
9
|
|
33
|
|
|
48
|
my $class = ref($proto) || $proto; |
85
|
|
|
|
|
|
|
|
86
|
9
|
|
|
|
|
14
|
my $self = {}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
9
|
|
|
|
|
26
|
foreach my $key ( keys %supplied ) |
92
|
|
|
|
|
|
|
{ |
93
|
12
|
|
|
|
|
32
|
$self->{ lc $key } = $supplied{ $key }; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
9
|
|
|
|
|
17
|
bless( $self, $class ); |
97
|
9
|
100
|
|
|
|
64
|
$self->_parse_page( $self->{ 'file' } ) if ( $self->{ 'file' } ); |
98
|
9
|
|
|
|
|
25
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 _parse_page |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Read the file, and parse the header/content. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is an internal method. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _parse_page |
111
|
|
|
|
|
|
|
{ |
112
|
8
|
|
|
8
|
|
11
|
my ( $self, $filename ) = (@_); |
113
|
|
|
|
|
|
|
|
114
|
8
|
50
|
|
|
|
210
|
open( my $handle, "<:utf8", $filename ) or |
115
|
|
|
|
|
|
|
die "Failed to read '$filename' - $!"; |
116
|
8
|
|
|
|
|
27
|
binmode( $handle, ":utf8" ); |
117
|
|
|
|
|
|
|
|
118
|
8
|
|
|
|
|
13
|
my $header = 1; |
119
|
|
|
|
|
|
|
|
120
|
8
|
|
|
|
|
86
|
while ( my $line = <$handle> ) |
121
|
|
|
|
|
|
|
{ |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
44
|
|
|
|
|
349
|
$line =~ s/[\r\n]*//g; |
125
|
|
|
|
|
|
|
|
126
|
44
|
100
|
|
|
|
65
|
if ($header) |
127
|
|
|
|
|
|
|
{ |
128
|
28
|
100
|
|
|
|
85
|
if ( $line =~ /^([^:]+):(.*)$/ ) |
129
|
|
|
|
|
|
|
{ |
130
|
20
|
|
|
|
|
31
|
my $key = $1; |
131
|
20
|
|
|
|
|
26
|
my $val = $2; |
132
|
20
|
|
|
|
|
48
|
$key = lc($key); |
133
|
20
|
|
|
|
|
43
|
$key =~ s/^\s+|\s+$//g; |
134
|
20
|
|
|
|
|
74
|
$val =~ s/^\s+|\s+$//g; |
135
|
|
|
|
|
|
|
|
136
|
20
|
|
|
|
|
40
|
$self->{ $key } = $val; |
137
|
|
|
|
|
|
|
print "Templer::Site::Page set: $key => $val\n" |
138
|
20
|
50
|
|
|
|
45
|
if ( $self->{ 'debug' } ); |
139
|
|
|
|
|
|
|
} |
140
|
28
|
100
|
|
|
|
90
|
if ( $line =~ /^----[\r\n]*$/ ) |
141
|
|
|
|
|
|
|
{ |
142
|
8
|
|
|
|
|
22
|
$header = undef; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else |
146
|
|
|
|
|
|
|
{ |
147
|
16
|
|
|
|
|
72
|
$self->{ 'content' } .= $line . "\n"; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
8
|
50
|
|
|
|
17
|
if ($header) |
156
|
|
|
|
|
|
|
{ |
157
|
0
|
|
|
|
|
0
|
print "WARNING: No header found in $filename\n"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
8
|
|
|
|
|
53
|
close($handle); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 content |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Return the body of the page. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Here we perform the textile/markdown expansion if possible via the use |
171
|
|
|
|
|
|
|
plugins loaded by L<Templer::Plugin::Factory>. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub content |
176
|
|
|
|
|
|
|
{ |
177
|
3
|
|
|
3
|
1
|
5
|
my ( $self, $data ) = (@_); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
3
|
|
|
|
|
5
|
my $content = $self->{ 'content' }; |
183
|
3
|
|
50
|
|
|
23
|
my $format = $self->{ 'format' } || $data->{ 'format' } || undef; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
3
|
50
|
|
|
|
24
|
if ($format) |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
0
|
my $factory = Templer::Plugin::Factory->new(); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
0
|
foreach my $fmt ( split( /,/, $format ) ) |
202
|
|
|
|
|
|
|
{ |
203
|
0
|
|
|
|
|
0
|
$fmt =~ s/^\s+|\s+$//g; |
204
|
0
|
0
|
|
|
|
0
|
next unless ($fmt); |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
0
|
my $helper = $factory->formatter($fmt); |
207
|
0
|
0
|
|
|
|
0
|
$content = $helper->format( $content, $data ) if ($helper); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
3
|
|
|
|
|
18
|
return $content; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 field |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Retrieve a field from the header of the page. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
In the following example file "foo", "bar" and "title" are fields: |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Foo: Testing .. |
221
|
|
|
|
|
|
|
Bar: file_glob( "*.gif" ) |
222
|
|
|
|
|
|
|
Title: This is my page title. |
223
|
|
|
|
|
|
|
----- |
224
|
|
|
|
|
|
|
<p>This is my page content ..</p> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub field |
229
|
|
|
|
|
|
|
{ |
230
|
25
|
|
|
25
|
1
|
1868
|
my ( $self, $field ) = (@_); |
231
|
25
|
|
|
|
|
86
|
return ( $self->{ $field } ); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 fields |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Return all known fields/values from the page. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub fields |
243
|
|
|
|
|
|
|
{ |
244
|
8
|
|
|
8
|
1
|
569
|
my ($self) = (@_); |
245
|
|
|
|
|
|
|
|
246
|
8
|
|
|
|
|
57
|
return (%$self); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 source |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Return the filename we were built from. This is the value passed |
253
|
|
|
|
|
|
|
in the constructor. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=cut |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub source |
258
|
|
|
|
|
|
|
{ |
259
|
15
|
|
|
15
|
1
|
17
|
my ($self) = (@_); |
260
|
15
|
|
|
|
|
25
|
$self->field("file"); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 layout |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Return the layout-template to use for this page, if one has been set. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub layout |
272
|
|
|
|
|
|
|
{ |
273
|
3
|
|
|
3
|
1
|
330
|
my ($self) = (@_); |
274
|
3
|
|
|
|
|
6
|
$self->field("layout"); |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head2 dependencies |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Return the dependencies of the current page. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=cut |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub dependencies |
285
|
|
|
|
|
|
|
{ |
286
|
1
|
|
|
1
|
1
|
1
|
my ($self) = (@_); |
287
|
|
|
|
|
|
|
|
288
|
1
|
50
|
|
|
|
4
|
$self->{ 'dependencies' } ? @{ $self->{ 'dependencies' } } : (); |
|
0
|
|
|
|
|
0
|
|
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head2 add_dependency |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Add a dependency to the current page. This is used so that the file-inclusion |
295
|
|
|
|
|
|
|
plugin can add such a thing. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=cut |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub add_dependency |
300
|
|
|
|
|
|
|
{ |
301
|
9
|
|
|
9
|
1
|
15
|
my ( $self, $file ) = (@_); |
302
|
9
|
|
|
|
|
9
|
push( @{ $self->{ 'dependencies' } }, $file ); |
|
9
|
|
|
|
|
28
|
|
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
1; |
307
|
|
|
|
|
|
|
|