[Zope-Checkins] CVS: Zope2 - Image.py:1.124.4.3
Brian Lloyd
brian@digicool.com
Thu, 12 Apr 2001 11:55:07 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/OFS
In directory korak:/home/brian/temp/zope-23-branch/lib/python/OFS
Modified Files:
Tag: zope-2_3-branch
Image.py
Log Message:
Added optional 'css_class' arg to Image.tag() to work around class
being a Python reserved word.
--- Updated File Image.py in package Zope2 --
--- Image.py 2001/03/01 14:33:56 1.124.4.2
+++ Image.py 2001/04/12 15:55:06 1.124.4.3
@@ -578,7 +578,7 @@
return self.tag()
def tag(self, height=None, width=None, alt=None,
- scale=0, xscale=0, yscale=0, **args):
+ scale=0, xscale=0, yscale=0, css_class=None, **args):
"""
Generate an HTML IMG tag for this image, with customization.
Arguments to self.tag() can be any valid attributes of an IMG tag.
@@ -587,6 +587,12 @@
'height', 'width', and 'alt'. If specified, the 'scale', 'xscale',
and 'yscale' keyword arguments will be used to automatically adjust
the output height and width values of the image tag.
+
+ Since 'class' is a Python reserved word, it cannot be passed in
+ directly in keyword arguments which is a problem if you are
+ trying to use 'tag()' to include a CSS class. The tag() method
+ will accept a 'css_class' argument that will be converted to
+ 'class' in the output tag to work around this.
"""
if height is None: height=self.height
if width is None: width=self.width
@@ -614,6 +620,9 @@
if not 'border' in map(string.lower, args.keys()):
result = '%s border="0"' % result
+
+ if css_class is not None:
+ result = '%s class="%s"' % (result, css_class)
for key in args.keys():
value = args.get(key)