[Zope-dev] Patch: Add versatile "tag" method to Image
Martijn Pieters
mj@antraciet.nl
Wed, 14 Jul 1999 11:27:13 +0200
--=====================_428927695==_
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 21:15 13/07/99 , bruce@perens.com wrote:
>However, I found this method constraining in that I could not add attributes
>such as "BORDER=0" to the tag. This patch adds a more versatile tag() method
>to Image. Arguments to the tag() method can be any of the usual IMG
>attributes. Defaults are provided for height and width (again, set from
>the image file) and For example:
Wonderful!
A few comments:
- I cannot remove the alt, width or height attrinutes. Yes, this is
sometimes necessary.
- Attributes are not quoted, except src and alt. This is needed with width
and height when using percentages. Quotes are generally a good idea, even
if the HTML spec says they are optional.
Attached patch (against the latest CVS), solves these points. I changed
addition of the alt attribute to conditional, and added quoting for all
tags. I also changed the way alt, width and height are defaulted. The code
now checks wether they are equal to None, so you can do things like:
imagename.tag(alt='', width='', height='') to get an IMG tag without any
alt, width or height attributes.
--=====================_428927695==_
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: attachment; filename="Image.py.patch"
Content-Transfer-Encoding: quoted-printable
*** Image.py 1999/07/13 20:46:58 1.79=0A--- Image.py 1999/07/14=
09:14:56=0A***************=0A*** 453,476 ****=0A downloading of=
images. Defaults are applied intelligently for=0A 'height',=
'width', and 'alt'.=0A """=0A! if not alt:=0A! =
alt=3Dself.title_or_id()=0A=0A! string=3D'<img src=3D"%s" alt=3D"%s=
"' % (self.absolute_url(), alt)=0A=0A! if not height:=0A =
height =3D self.height=0A if height:=0A! string =3D=
"%s height=3D%s" % (string, height)=0A=0A! if not width:=0A =
width =3D self.width=0A if width:=0A! string =3D=
"%s width=3D%s" % (string, width)=0A=0A for key in args.keys():=0A=
value =3D args.get(key)=0A! string =3D "%s %s=3D%s=
" % (string, key, value)=0A=0A return string + '>'=0A=0A--- 453,479=
----=0A downloading of images. Defaults are applied intelligently=
for=0A 'height', 'width', and 'alt'.=0A """=0A!=0A! =
string=3D'<img src=3D"%s"' % (self.absolute_url())=0A=0A! if=
alt=3D=3DNone:=0A! alt=3Dself.title_or_id()=0A! if=
alt:=0A! string =3D '%s alt=3D"%s"' % (string, alt)=0A=0A! =
if height=3D=3DNone:=0A height =3D self.height=0A =
if height:=0A! string =3D '%s height=3D"%s"' % (string,=
height)=0A=0A! if width=3D=3DNone:=0A width =3D=
self.width=0A if width:=0A! string =3D '%s width=3D"%s=
"' % (string, width)=0A=0A for key in args.keys():=0A =
value =3D args.get(key)=0A! string =3D '%s %s=3D"%s"' %=
(string, key, value)=0A=0A return string + '>'=0A=0A
--=====================_428927695==_
Content-Type: text/plain; charset="us-ascii"; format=flowed
--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------
--=====================_428927695==_--