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

Revision 605 (checked in by miyagawa, 18 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package Template::Plugin::Clickable;
2
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = 0.01;
6
7 require Template::Plugin::Filter;
8 use base qw(Template::Plugin::Filter);
9
10 use vars qw($DYNAMIC $FILTER_NAME);
11 $DYNAMIC = 1;
12 $FILTER_NAME = 'clickable';
13
14 use URI::Find;
15
16 sub init {
17     my $self = shift;
18     my $name = $self->{_ARGS}->[0] || $FILTER_NAME;
19     $self->install_filter($name);
20     return $self;
21 }
22
23 sub filter {
24     my($self, $text, $args, $config) = @_;
25
26     my $finder = URI::Find->new(
27         sub {
28             my($uri, $orig_uri) = @_;
29             my $target = $config->{target} ? qq( target="$config->{target}") : '';
30             return qq(<a href="$uri"$target>$orig_uri</a>);
31         },
32     );
33     $finder->find(\$text);
34     return $text;
35 }
36
37 1;
38 __END__
39
40 =head1 NAME
41
42 Template::Plugin::Clickable - Make URLs clickable in HTML
43
44 =head1 SYNOPSIS
45
46   [% USE Clickable %]
47   [% FILTER clickable %]
48   URL is http://www.template-toolkit.org/
49   [% END %]
50
51 this will become:
52
53   URL is <a href="http://www.template-toolkit.org/">http://www.template-toolkit.org/</a>
54
55 =head1 DESCRIPTION
56
57 Template::Plugin::Clickable is a plugin for TT, which allows your to
58 filter HTMLs clickable.
59
60 =head1 AUTHOR
61
62 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
63
64 This library is free software; you can redistribute it and/or modify
65 it under the same terms as Perl itself.
66
67 =head1 SEE ALSO
68
69 L<Template>, L<URI::Find>
70
71 =cut
Note: See TracBrowser for help on using the browser.