[Zope-Checkins] CVS: Zope2 - Image.py:1.128

Brian Lloyd brian@digicool.com
Thu, 12 Apr 2001 11:55:44 -0400 (EDT)


Update of /cvs-repository/Zope2/lib/python/OFS
In directory korak:/home/brian/temp/mainline_test/lib/python/OFS

Modified Files:
	Image.py 
Log Message:
Merged fix to add 'css_class' to Image.tag() to work around 'class' being
a Python reserved word.



--- Updated File Image.py in package Zope2 --
--- Image.py	2001/03/01 02:32:15	1.127
+++ Image.py	2001/04/12 15:55:43	1.128
@@ -589,7 +589,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.
@@ -598,6 +598,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
@@ -625,6 +631,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)