root/Template-Plugin-ResolveLink/trunk/lib/Template/Plugin/ResolveLink.pm

Revision 1986 (checked in by miyagawa, 14 years ago)

import Template::Plugin::ResolveLink?

Line 
1 package Template::Plugin::ResolveLink;
2
3 use strict;
4 our $VERSION = '0.01';
5
6 use base qw(Template::Plugin);
7 our $FILTER_NAME = 'resolve_link';
8
9 use HTML::ResolveLink;
10
11 sub new {
12     my($class, $context, @args) = @_;
13     my $name = $args[0] || $FILTER_NAME;
14     $context->define_filter($name, $class->filter_factory());
15     bless {}, $class;
16 }
17
18 sub filter_factory {
19     my $class = shift;
20     my $sub = sub {
21         my($context, @args) = @_;
22         my $config = ref $args[-1] eq 'HASH' ? pop(@args) : { };
23         return sub {
24             my $html = shift;
25             my $resolver = HTML::ResolveLink->new(%$config);
26             return $resolver->resolve($html);
27         };
28     };
29     return [ $sub, 1 ];
30 }
31
32 1;
33 __END__
34
35 =head1 NAME
36
37 Template::Plugin::ResolveLink - Template plugin for HTML::ResolveLink
38
39 =head1 SYNOPSIS
40
41   use Template::Plugin::ResolveLink;
42
43   # in your template
44   [% USE ResolveLink -%]
45   [% FILTER resolve_link base = "http://www.example.com/base/" -%]
46   <a href="foo.html"><img src="/bar.gif"></a>
47   <a href="mailto:bar">foo</a>
48   [% END %]
49
50   # will become
51   <a href="http://www.example.com/base/foo.html"><img src="http://www.example.com/bar.gif"></a>
52   <a href="mailto:bar">foo</a>
53
54 =head1 DESCRIPTION
55
56 Template::Plugin::ResolveLink is a wrapper for HTML::ResolveLink to be
57 used in Template Toolkit templates.
58
59 =head1 AUTHOR
60
61 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
62
63 =head1 LICENSE
64
65 This library is free software; you can redistribute it and/or modify
66 it under the same terms as Perl itself.
67
68 =head1 SEE ALSO
69
70 L<HTML::ResolveLink>
71
72 =cut
Note: See TracBrowser for help on using the browser.