Template-Plugin-Clickable-0.06/0000755000175000017500000000000010376245634017747 5ustar miyagawamiyagawa00000000000000Template-Plugin-Clickable-0.06/t/0000755000175000017500000000000010376245634020212 5ustar miyagawamiyagawa00000000000000Template-Plugin-Clickable-0.06/t/01_clickable.t0000644000175000017500000000202610376245573022612 0ustar miyagawamiyagawa00000000000000use strict; use Template::Test; test_expect(\*DATA); __END__ --test-- [% USE Clickable -%] [% FILTER clickable -%] http://www.template-toolkit.org/ [%- END %] --expect-- http://www.template-toolkit.org/ --test-- [% USE Clickable -%] [% FILTER clickable target => '_blank' -%] http://www.template-toolkit.org/ http://www.template-toolkit.org/ [%- END %] --expect-- http://www.template-toolkit.org/ http://www.template-toolkit.org/ --test-- [% USE Clickable -%] [% FILTER clickable target => '_blank', rel => 'nofollow' -%] http://www.template-toolkit.org/ [%- END %] [% FILTER clickable rel => 'nofollow' -%] http://www.template-toolkit.org/ [%- END %] --expect-- http://www.template-toolkit.org/ http://www.template-toolkit.org/ Template-Plugin-Clickable-0.06/t/00_compile.t0000644000175000017500000000012710303520531022304 0ustar miyagawamiyagawa00000000000000use strict; use Test::More tests => 1; BEGIN { use_ok 'Template::Plugin::Clickable' } Template-Plugin-Clickable-0.06/lib/0000755000175000017500000000000010376245634020515 5ustar miyagawamiyagawa00000000000000Template-Plugin-Clickable-0.06/lib/Template/0000755000175000017500000000000010376245634022270 5ustar miyagawamiyagawa00000000000000Template-Plugin-Clickable-0.06/lib/Template/Plugin/0000755000175000017500000000000010376245634023526 5ustar miyagawamiyagawa00000000000000Template-Plugin-Clickable-0.06/lib/Template/Plugin/Clickable.pm0000644000175000017500000000602210376245627025737 0ustar miyagawamiyagawa00000000000000package Template::Plugin::Clickable; use strict; our $VERSION = 0.06; require Template::Plugin; use base qw(Template::Plugin); use vars qw($FILTER_NAME); $FILTER_NAME = 'clickable'; use UNIVERSAL::require; sub new { my($class, $context, @args) = @_; my $name = $args[0] || $FILTER_NAME; $context->define_filter($name, $class->filter_factory()); bless { }, $class; } sub filter_factory { my $class = shift; my $sub = sub { my($context, @args) = @_; my $config = ref $args[-1] eq 'HASH' ? pop(@args) : { }; return sub { my $text = shift; my $finder_class = $config->{finder_class} || 'URI::Find'; $finder_class->require or die $UNIVERSAL::require::ERROR; my $finder = $finder_class->new( sub { my($uri, $orig_uri) = @_; my $target = $config->{target} ? qq( target="$config->{target}") : ''; my $rel = $config->{rel} ? qq( rel="$config->{rel}") : ''; return qq($orig_uri); }, ); $finder->find(\$text); return $text; }; }; return [ $sub, 1 ]; } 1; __END__ =head1 NAME Template::Plugin::Clickable - Make URLs clickable in HTML =head1 SYNOPSIS [% USE Clickable %] [% FILTER clickable %] URL is http://www.tt2.org/ [% END %] this will become: URL is http://www.tt2.org/ =head1 DESCRIPTION Template::Plugin::Clickable is a plugin for TT, which allows you to filter HTMLs clickable. =head1 OPTIONS =over 4 =item target [% FILTER clickable target => '_blank' %] [% message.body | html %] [% END %] C option enables you to set target attribute in A links. none by default. =item finder_class C option enables you to set other URI finder class rather than URI::Find (default). For example, [% FILTER clickable finder_class => 'URI::Find::Schemeless' %] Visit www.example.com/join right now! [% END %] this will become: Visit www.example.com/join right now! =back =head1 NOTE If you use this module with C filter, you should be careful not to break tags or brackets around the URLs. For example if you have a following URL form, Clickable plugin will filter this into: which is bad for HTML viewing. However, if you HTML filter them first and then clickable filter, you'll get: <http://www.example.com/>; which href part is wrong. You'd better try L in this case. [% USE Clickable -%] [% USE TagRescue -%] [% FILTER html_except_for('a') -%] [% FILTER clickable -%] [%- END %] [%- END %] will give you the right format. =head1 AUTHOR Tatsuhiko Miyagawa Emiyagawa@bulknews.netE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L