On Mon, 26 Jan 2004, Dave Cash wrote:
> To create a filter in a plugin, just call the define_filter()
> method on the $context (which you get as the second argument to
> load() ).
I missed completely this point, sorry.
BTW, I find that it would be quite normal to define plugins and filters at
the same time, expecially considering that the filter_factory is the
same.
I tried the following (for a WikiFormat plugin/filter from Text::WikiFormat):
(but before putting the stuff: is there a repository for "contrib"
plugins? it is so small for an entry on cpan).
-----------------------------------------------------------
use Text::WikiFormat;
sub new {
my $class = shift;
my $context = shift;
my $filter;
unless (ref $_[0]){
$filter= shift ;
}
my ($tags, $options) = @_;
$tags={} unless defined $tags;
$tags = {
newline => "\n", #default tags
paragraph => [ '<p>', "</p>\n", '', "\n", 1 ],
strong_tag => qr/\*(.+?)\*/,
emphasized_tag => qr/""(.+?)""/,
extended_link_delimiters => [ '[[', ']]' ] ,
%$tags,
};
$options={} unless defined $options;
$options = {
extended=>1, #default opts
%$options,
};
if (defined $filter) {
$context->define_filter($filter,
make_formatter($tags, $options), 0);
} else {
$context->define_filter("WikiFormat",
\&make_formatter, 1);
}
return make_formatter($tags, $options);
}
sub make_formatter {
my ($tags, $options) = @_;
return sub {
my $text=shift;
return Text::WikiFormat::format($text, $tags, $options);
}
}
1;
------------------------------------------------------
so that one can write
[% USE wikiformatter = WikiFormat({tags..}, {options..} %]
[% wikiformatter("text") %]
or
[% USE WikiFormat("wikifilter", {tags..}, {options..} %]
[% FILTER wikifilter %]
...
[% END %]
(if one needs to use the same options in different parts) or
[% FILTER WikiFormat( {tags..}, {options..}) %]
...
[% END%]
or even both filter and functions with the same options
[% USE wikiformat=WikiFormat("wikifilter",...) %]
[% wikiformat ("text"%]
[%FILTER wikifilter %]
another text
[% END%]
--
Franco Bagnoli (franchino) <[EMAIL PROTECTED]> ([EMAIL PROTECTED])
virtual location: Dipartimento di Energetica "S. Stecco"
ultra-virtual affiliation: Centro Dinamiche Complesse (CSDC-Firenze)
real location: Dip. Matematica Applicata "G. Sansone", Universita' Firenze,
Via S. Marta, 3 I-50139 Firenze, Italy. Tel. +39 0554796422, fax: +39 055471787
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates