forked from bentglasstube/blosxom-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpolate_tt-v0i01
248 lines (174 loc) · 4.87 KB
/
interpolate_tt-v0i01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package interpolate_tt;
use strict;
=head1 NAME
interpolate_tt - Blosxom plugin for interpolating with text_template
=head1 VERSION
This describes version B<0.01> of interpolate_tt.
=cut
our $VERSION = '0.01';
=head1 DESCRIPTION
Overrides Blosxom's simple interpolate() subroutine, by using
the Text::Template module.
This is I<not> compatible with core Blosxom style interpolation.
In order to be able to call actions from other plugins which have
been designed with B<interpolate_fancy> in mind, this plugin
includes a function L</call_action>, which will call the given
action correctly. All the templateble things are expected to be pure perl,
set off by delimiters, as in Text::Template.
=head1 INSTALLATION
=head2 Installation
Drop the interpolate_tt plug-in into your Blosxom plugins folder.
If you have some other "interpolate" plugin, it's best to remove
it, as there can be only one.
=head2 Configuration
The following configuration variables can be set by editing the
plugin file.
=over
=item B<recurse_into_story>
Do you want me to recursively interpolate into the story $title
and $body? Consider carefully before turning this on, since if
anyone other than you has the ability to post stories, there is
a chance of foolishness or malice, exposing variables and
calling actions/subroutines you might not want called.
(0 = No, 1 = Yes)
=cut
my $recurse_into_story = 1;
=item B<left_delim> B<right_delim>
The delimiters to use for Text::Template; for the sake of speed,
it is best not to use the original '{' '}' delimiters.
(default: left_delim='<?perl', right_delim='perl?>')
=cut
#our $left_delim = '<?perl';
#our $right_delim = 'perl?>';
our $left_delim = '[==';
our $right_delim = '==]';
=back
=cut
=head1 PLUGIN FUNCTIONS
=head2 start
Say I am alive.
=cut
sub start {
1;
} # start
=head2 interpolate
Create the interpolate subroutine.
=cut
sub interpolate {
return sub {
package blosxom;
require Text::Template;
# call make a template of the $title and the $body if
# we were requested to "recurse_into_story"
if ($recurse_into_story) {
if ($blosxom::title) {
my $ob1 = new Text::Template(
TYPE=>'STRING',
SOURCE => $blosxom::title,
DELIMITERS => [$interpolate_tt::left_delim,
$interpolate_tt::right_delim],
);
$blosxom::title = $ob1->fill_in();
undef $ob1;
}
if ($blosxom::body) {
my $ob2 = new Text::Template(
TYPE=>'STRING',
SOURCE => $blosxom::body,
DELIMITERS => [$interpolate_tt::left_delim,
$interpolate_tt::right_delim],
);
$blosxom::body = $ob2->fill_in();
undef $ob2;
}
}
my $template = shift;
# do it!
my $obj = new Text::Template(
TYPE=>'STRING',
SOURCE => $template,
DELIMITERS => [$interpolate_tt::left_delim,
$interpolate_tt::right_delim],
);
$template = $obj->fill_in();
return $template;
};
}
=head2 call_action
Call this from within your embedded perl code, in order to call
another plugin's action.
interpolate_tt::call_action(
plugin=>I<plugin>,
action=>I<action>,
attributes=>{
I<arg1>=>I<value1>,
...
},
content=>I<content>
);
Arguments:
=over
=item plugin
The name of the plugin which supplies the action you want to call.
=item action
The name of the action you want to call.
=item attributes
The attributes which you would have put in the <@ tag if you were
using B<interpolate_fancy>. This is a reference to a hash whose
keys are the attribute names, and whose values are the attribute
values.
=item content
If this action does things to the "content" of the <@ tag, then
that content needs to go here.
Note that no recursive interpolation is done on this content
(apart from the usual double-quote interpolation of perl).
=back
For example:
<?perl
$OUT = interpolate_tt::call_action(
plugin=>'headlines',
action=>'get',
attributes=>{
sort_method=>'by_date',
output=>"yes"
},
);
perl?>
=cut
sub call_action {
my %args = (
plugin=>'',
action=>'',
attributes=>{},
content=>'',
@_
);
my $attributes = $args{attributes};
my $plugin = $args{plugin};
my $action = $args{action};
my $content = $args{content};
my $result = '';
no strict 'refs';
$blosxom::plugins{$plugin}
and $plugin->can($action)
and $result = $plugin->$action($attributes, $content);
return $attributes->{'output'} =~ /yes/i ? $result : undef;
}
=head1 REQUIRES
Perl 5.6.0
=head1 SEE ALSO
interpolate_fancy
=head1 BUGS
Please report any bugs or feature requests to the author.
=head1 AUTHOR
Kathryn Andersen (RUBYKAT)
perlkat AT katspace dot com
http://www.katspace.com
=head1 COPYRIGHT AND LICENCE
Copyright (c) 2004 by Kathryn Andersen
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
# vim: ft=perl ts=8 sw=4 sts=4 ai cinkeys="0{,0},0),!,o,O,e"
1; # End of interpolate_tt
__END__