Changeset 798

Show
Ignore:
Timestamp:
11/14/02 18:49:42
Author:
miyagawa
Message:

0.03

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Template-Plugin-Clickable/trunk/Changes

    r605 r798  
    11Revision history for Perl extension Template::Plugin::Clickable 
     2 
     30.03  Thu Nov 14 18:49:15 JST 2002 
     4        * Fixed memory leak due to Template::Plugin::Filter 
     5 
     60.02  Sun Aug 18 19:04:30 JST 2002 
     7        - improved documentation 
    28 
    390.01  Tue Apr 23 20:40:40 2002 
  • Template-Plugin-Clickable/trunk/README

    r605 r798  
    55      [% USE Clickable %] 
    66      [% FILTER clickable %] 
    7       URL is http://www.template-toolkit.org/ 
     7      URL is http://www.tt2.org/ 
    88      [% END %] 
    99 
    1010    this will become: 
    1111 
    12       URL is <a href="http://www.template-toolkit.org/">http://www.template-toolkit.org/</a> 
     12      URL is <a href="http://www.tt2.org/">http://www.tt2.org/</a> 
    1313 
    1414DESCRIPTION 
    15     Template::Plugin::Clickable is a plugin for TT, which allows your to 
     15    Template::Plugin::Clickable is a plugin for TT, which allows you to 
    1616    filter HTMLs clickable. 
     17 
     18OPTIONS 
     19    target 
     20          [% FILTER clickable target => '_blank' %] 
     21          [% message.body | html %] 
     22          [% END %] 
     23 
     24        "target" option enables you to set target attribute in A links. none 
     25        by default. 
     26 
     27NOTE 
     28    If you use this module with "html" filter, you should set this 
     29    "clickable" module after the "html" filter. Otherwise links will be also 
     30    escaped and thus broken. 
    1731 
    1832AUTHOR 
  • Template-Plugin-Clickable/trunk/lib/Template/Plugin/Clickable.pm

    r605 r798  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.01
     5$VERSION = 0.03
    66 
    7 require Template::Plugin::Filter
    8 use base qw(Template::Plugin::Filter); 
     7require Template::Plugin
     8use base qw(Template::Plugin); 
    99 
    10 use vars qw($DYNAMIC $FILTER_NAME); 
    11 $DYNAMIC = 1; 
     10use vars qw($FILTER_NAME); 
    1211$FILTER_NAME = 'clickable'; 
    1312 
    1413use URI::Find; 
    1514 
    16 sub init
    17     my $self = shift
    18     my $name = $self->{_ARGS}->[0] || $FILTER_NAME; 
    19     $self->install_filter($name); 
    20     return $self
     15sub new
     16    my($class, $context, @args) = @_
     17    my $name = $args[0] || $FILTER_NAME; 
     18    $context->define_filter($name, $class->filter_factory()); 
     19    bless { }, $class
    2120} 
    2221 
    23 sub filter { 
    24     my($self, $text, $args, $config) = @_; 
     22sub filter_factory { 
     23    my $class = shift; 
     24    my $sub = sub { 
     25        my($context, @args) = @_; 
     26        my $config = ref $args[-1] eq 'HASH' ? pop(@args) : { }; 
     27        return sub { 
     28            my $text = shift; 
     29            my $finder = URI::Find->new( 
     30                sub { 
     31                    my($uri, $orig_uri) = @_; 
     32                    my $target = $config->{target} ? qq( target="$config->{target}") : ''; 
     33                    return qq(<a href="$uri"$target>$orig_uri</a>); 
     34                }, 
     35            ); 
     36            $finder->find(\$text); 
     37            return $text; 
     38        }; 
     39    }; 
     40    return [ $sub, 1 ]; 
     41
    2542 
    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 } 
    3643 
    37441; 
     
    4653  [% USE Clickable %] 
    4754  [% FILTER clickable %] 
    48   URL is http://www.template-toolkit.org/ 
     55  URL is http://www.tt2.org/ 
    4956  [% END %] 
    5057 
    5158this will become: 
    5259 
    53   URL is <a href="http://www.template-toolkit.org/">http://www.template-toolkit.org/</a> 
     60  URL is <a href="http://www.tt2.org/">http://www.tt2.org/</a> 
    5461 
    5562=head1 DESCRIPTION 
    5663 
    57 Template::Plugin::Clickable is a plugin for TT, which allows your to 
     64Template::Plugin::Clickable is a plugin for TT, which allows you to 
    5865filter HTMLs clickable. 
     66 
     67=head1 OPTIONS 
     68 
     69=over 4 
     70 
     71=item target 
     72 
     73  [% FILTER clickable target => '_blank' %] 
     74  [% message.body | html %] 
     75  [% END %] 
     76 
     77C<target> option enables you to set target attribute in A links. none 
     78by default. 
     79 
     80=back 
     81 
     82=head1 NOTE 
     83 
     84If you use this module with C<html> filter, you should set this 
     85C<clickable> module B<after> the C<html> filter. Otherwise links will 
     86be also escaped and thus broken. 
    5987 
    6088=head1 AUTHOR