Changeset 781

Show
Ignore:
Timestamp:
09/26/02 02:21:08
Author:
miyagawa
Message:

support named params

Files:

Legend:

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

    r778 r781  
    11Revision history for Perl extension Template::Plugin::HTML::Template 
     2 
     30.02 
     4        - Fixed MANIFEST problem 
     5        * Added named filter and conf parameter 
     6          (Thanks to darren chamberlain <darren@cpan.org>) 
    27 
    380.01  Wed Sep 25 23:33:47 2002 
  • Template-Plugin-HTML-Template/trunk/lib/Template/Plugin/HTML/Template.pm

    r778 r781  
    33use strict; 
    44use vars qw($VERSION $DYNAMIC $FILTER_NAME); 
    5 $VERSION = 0.01
     5$VERSION = 0.02
    66 
    77$DYNAMIC = 1; 
     
    1212 
    1313sub init { 
    14     my $self = shift
     14    my($self, $options) = @_
    1515    my $name = $self->{_ARGS}->[0] || $FILTER_NAME; 
    1616    $self->install_filter($name); 
     17    $self->{_options} = $options; 
    1718    return $self; 
    1819} 
    1920 
    20 my $dont_use = qr/^(?:global|component|HTML|_DEBUG|_PARENT|dec|template)$/; 
     21sub filter { 
     22    my($self, $text, $args, $options) = @_; 
     23    my $template = HTML::Template->new( 
     24        strict => 0, 
     25        die_on_bad_params => 0, 
     26        %{$self->{_options}}, 
     27        %$options, 
     28        scalarref => \$text, 
     29    ); 
    2130 
    22 sub filter { 
    23     my($self, $text, $args) = @_; 
    24     my $template = HTML::Template->new( 
    25         scalarref => \$text, 
    26         die_on_bad_params => 0, 
    27     ); 
    28     # XXX there should be a better way 
    2931    my $stash = $self->{_CONTEXT}->stash; 
    30     my @keys = grep !/$dont_use/, keys %{$stash}
    31     $template->param(map { $_ => $stash->get($_) } @keys); 
     32    my @params = map { ($_ => $stash->{ $_ }) } grep !/^[\._]/, keys %$stash
     33    $template->param(@params); 
    3234    return $template->output; 
    3335} 
     
    5456 
    5557Template::Plugin::HTML::Template is a TT plugin to filter 
    56 HTML::Template templates. It might sounds just silly, but it can be 
     58HTML::Template templates. It might sound just silly, but it can be 
    5759handy when you want to reuse existent HTML::Template templates inside 
    5860TT. 
     
    6163 
    6264Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> 
     65 
     66darren chamberlain <darren@cpan.org> 
    6367 
    6468This library is free software; you can redistribute it and/or modify 
  • Template-Plugin-HTML-Template/trunk/t/01_output.t

    r778 r781  
    2525  Job:  soda jerk  <p> 
    2626 
     27--test-- 
     28[% USE ht = HTML.Template(loop_context_vars = 1) -%] 
     29[% FILTER html_template -%] 
     30<TMPL_LOOP NAME=EMPLOYEE_INFO><TMPL_IF name=__FIRST__>First</TMPL_IF> 
     31  Name: <TMPL_VAR NAME=NAME> <br> 
     32  Job:  <TMPL_VAR NAME=JOB>  <p> 
     33</TMPL_LOOP> 
     34[%- END %] 
     35--expect-- 
     36First 
     37  Name: Sam <br> 
     38  Job:  programmer  <p> 
     39 
     40  Name: Steve <br> 
     41  Job:  soda jerk  <p> 
     42