[Templates-cvs] cvs commit: Template2/lib/Template/Plugin Image.pm

cvs@template-toolkit.org cvs@template-toolkit.org


cvs         06/01/30 16:06:43

  Modified:    lib/Template/Plugin Image.pm
  Log:
  * added support for alt="" tag
  
  Revision  Changes    Path
  1.17      +15 -4     Template2/lib/Template/Plugin/Image.pm
  
  Index: Image.pm
  ===================================================================
  RCS file: /template-toolkit/Template2/lib/Template/Plugin/Image.pm,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Image.pm	2006/01/30 14:41:15	1.16
  +++ Image.pm	2006/01/30 16:06:43	1.17
  @@ -13,7 +13,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: Image.pm,v 1.16 2006/01/30 14:41:15 abw Exp $
  +#   $Id: Image.pm,v 1.17 2006/01/30 16:06:43 abw Exp $
   #
   #============================================================================
   
  @@ -31,7 +31,7 @@
   use base qw( Template::Plugin );
   use vars qw( $VERSION $AUTOLOAD );
   
  -$VERSION = sprintf("%d.%02d", q$Revision: 1.16 $ =~ /(\d+)\.(\d+)/);
  +$VERSION = sprintf("%d.%02d", q$Revision: 1.17 $ =~ /(\d+)\.(\d+)/);
   
   BEGIN {
       if (eval { require Image::Info; }) {
  @@ -91,10 +91,13 @@
       # Make a note of whether we are using Image::Size or
       # Image::Info -- at least for the test suite
       $type = $INC{"Image/Size.pm"} ? "Image::Size" : "Image::Info";
  -        
  -    # do we want to check to see if file exists?
   
  +    # set a default (empty) alt attribute for tag()
  +    $config->{ alt } = '' unless defined $config->{ alt };
  +
  +    # do we want to check to see if file exists?
       bless { 
  +        %$config,
           name => $name,
           file => $file,
           root => $root,
  @@ -135,6 +138,7 @@
       return "width=\"$size->[0]\" height=\"$size->[1]\"";
   }
   
  +
   #------------------------------------------------------------------------
   # modtime()
   #
  @@ -149,6 +153,7 @@
       return $self->{ modtime };
   }
   
  +
   #------------------------------------------------------------------------
   # tag(\%options)
   #
  @@ -160,6 +165,12 @@
       my $options = ref $_[0] eq 'HASH' ? shift : { @_ };
   
       my $tag = "<img src=\"$self->{ name }\" " . $self->attr();
  +
  +    # XHTML spec says that the alt attribute is mandatory, so who
  +    # are we to argue?
  +
  +    $options->{ alt } = $self->{ alt }
  +        unless defined $options->{ alt };
   
       if (%$options) {
           while (my ($key, $val) = each %$options) {