line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Templer::Plugin::Breadcrumbs - A plugin to create breadcrumbs |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
The following is a good example use of this plugin |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
title: About my site |
13
|
|
|
|
|
|
|
crumbs: Home,Software |
14
|
|
|
|
|
|
|
---- |
15
|
|
|
|
|
|
|
<p>This is my page content...</p> |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Here the variable 'crumbs' will be converted into a loop variable called |
19
|
|
|
|
|
|
|
'breadcrumbs'. THe links and titls will be set automatically, but if you |
20
|
|
|
|
|
|
|
need to override them you can do so via: |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
title: About my site |
23
|
|
|
|
|
|
|
crumbs: Home,Software[Soft],Testing[Test] |
24
|
|
|
|
|
|
|
---- |
25
|
|
|
|
|
|
|
<p>This is my page content...</p> |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
That will result in links to /, /Soft, and /Soft/Test, respectively. With |
29
|
|
|
|
|
|
|
display names of "Home", "Software" and "Testing". |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This plugin expands the values of "crumbs", as written in a template, to |
36
|
|
|
|
|
|
|
a loop-variable with the name "breadcrumbs". |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This can be used in a template like so: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=for example begin |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
<!-- tmpl_if name='breadcrumbs' --> |
43
|
|
|
|
|
|
|
<ul> |
44
|
|
|
|
|
|
|
<!-- tmpl_loop name='breadcrumbs' --> |
45
|
|
|
|
|
|
|
<li><a href="<!-- tmpl_var name='link' -->"><!-- tmpl_var name='title' --></a></li> |
46
|
|
|
|
|
|
|
<!-- /tmpl_loop --> |
47
|
|
|
|
|
|
|
</ul> |
48
|
|
|
|
|
|
|
<!-- /tmpl_if --> |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=for example end |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This template is an example. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 LICENSE |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
59
|
|
|
|
|
|
|
under the terms of either: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free Software |
62
|
|
|
|
|
|
|
Foundation; either version 2, or (at your option) any later version, |
63
|
|
|
|
|
|
|
or |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
b) the Perl "Artistic License". |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AUTHOR |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Copyright (C) 2015 Steve Kemp <steve@steve.org.uk>. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
80
|
|
|
|
|
|
|
the same terms as Perl itself. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 METHODS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
11
|
|
|
11
|
|
4023
|
use strict; |
|
11
|
|
|
|
|
13
|
|
|
11
|
|
|
|
|
264
|
|
90
|
11
|
|
|
11
|
|
32
|
use warnings; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
3141
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
package Templer::Plugin::Breadcrumbs; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 new |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Constructor. No arguments are required/supported. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub new |
103
|
|
|
|
|
|
|
{ |
104
|
11
|
|
|
11
|
1
|
22
|
my ( $proto, %supplied ) = (@_); |
105
|
11
|
|
33
|
|
|
82
|
my $class = ref($proto) || $proto; |
106
|
|
|
|
|
|
|
|
107
|
11
|
|
|
|
|
15
|
my $self = {}; |
108
|
11
|
|
|
|
|
18
|
bless( $self, $class ); |
109
|
11
|
|
|
|
|
75
|
return $self; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 expand_variables |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This is the method which is called by the L<Templer::Plugin::Factory> |
117
|
|
|
|
|
|
|
to expand the variables contained in a L<Templer::Site::Page> object. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This method will expand any variable that is called 'crumbs' into a HTML::Template |
120
|
|
|
|
|
|
|
loop, suitable for the display of breadcrumbs. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub expand_variables |
125
|
|
|
|
|
|
|
{ |
126
|
9
|
|
|
9
|
1
|
18
|
my ( $self, $site, $page, $data ) = (@_); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
9
|
|
|
|
|
36
|
my %hash = %$data; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
9
|
|
|
|
|
25
|
foreach my $key ( keys %hash ) |
137
|
|
|
|
|
|
|
{ |
138
|
66
|
50
|
|
|
|
104
|
if ( $key =~ /^crumbs$/i ) |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
|
|
0
|
my $loop; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
my $val = $hash{ $key }; |
143
|
0
|
|
|
|
|
0
|
my $link = "/"; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
0
|
foreach my $path ( split( /,/, $val ) ) |
146
|
|
|
|
|
|
|
{ |
147
|
0
|
|
|
|
|
0
|
$path =~ s/^\s+|\s+$//g; |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
0
|
if ( $path =~ /Home/i ) |
150
|
|
|
|
|
|
|
{ |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
else |
153
|
|
|
|
|
|
|
{ |
154
|
0
|
0
|
|
|
|
0
|
if ( $path =~ /(.*)\[(.*)\]/ ) |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
|
|
|
|
0
|
$link .= "/" . $1; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else |
159
|
|
|
|
|
|
|
{ |
160
|
0
|
|
|
|
|
0
|
$link .= "/" . $path; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
$link =~ s/\/\//\//g; |
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
0
|
if ( $path =~ /\[(.*)\]/ ) |
167
|
|
|
|
|
|
|
{ |
168
|
0
|
|
|
|
|
0
|
$path = $1; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else |
171
|
|
|
|
|
|
|
{ |
172
|
0
|
|
|
|
|
0
|
$path = ucfirst($path); |
173
|
|
|
|
|
|
|
} |
174
|
0
|
|
|
|
|
0
|
push( @$loop, |
175
|
|
|
|
|
|
|
{ title => $path, |
176
|
|
|
|
|
|
|
link => $link |
177
|
|
|
|
|
|
|
} ); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
0
|
$hash{ 'breadcrumbs' } = $loop if ($loop); |
182
|
0
|
|
|
|
|
0
|
delete $hash{ $key }; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
9
|
|
|
|
|
20
|
return ( \%hash ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Templer::Plugin::Factory->new() |
194
|
|
|
|
|
|
|
->register_plugin("Templer::Plugin::Breadcrumbs"); |
195
|
|
|
|
|
|
|
|