Commits

smil...@18c32c52-eb3f-0410-93bd-f15eff1430f4  committed 10c8091

Removing the {% thumbnail_imgtag %} tag, we decided it could be a bit
confusing and isn't saving much.
Also, small change to the .img_tag() function to accept an xhtml
argument (True by default to be similar to the rest of Django)

  • Participants
  • Parent commits a69ada4
  • Branches smiley-refactor

Comments (0)

Files changed (2)

File thumbnail/main.py

     def __unicode__(self):
         return self.url
 
-    def img_tag(self, extra_attributes=None, dimensions=True):
+    def img_tag(self, extra_attributes=None, dimensions=True, xhtml=True):
         """
         Build the <img> HTML tag.
         
         attributes['src'] = self.url
         html_attributes = [' %s="%s"' % (k, conditional_escape(v))\
                            for k, v in attributes.items()]
-        return mark_safe('<img%s />' % ''.join(html_attributes))
+        html_attributes = ''.join(html_attributes)
+        return mark_safe('<img%s%s>' % (html_attributes, xhtml and ' /' or ''))

File thumbnail/templatetags/thumbnail.py

         context[self.context_name] = thumbnail
         return ''
 
-class ThumbnailImgTagNode(template.Node):
-    def __init__(self, thumbnail, attributes=None):
-        self.thumbnail = template.Variable(thumbnail)
-        self.attributes = dict([(k, template.Variable(v)) for k, v in
-                                attributes.items()])
-    def render(self, context):
-        thumbnail = self.thumbnail.resolve(context)
-        attributes = dict([(k, v.resolve(context)) for k, v in
-                           self.attributes.items()])
-        return thumbnail.img_tag(extra_attributes=attributes)
-
 @register.tag
 def thumbnail(parser, token):
     return get_thumbnail_node(token)
 def thumbnail_debug(parser, token):
     return get_thumbnail_node(token, debug=True)
 
-@register.tag
-def thumbnail_imgtag(parser, token):
-    """
-    Output an HTML <img> tag for a DjangoThumbnail instance.
-
-    Basic usage::
-
-        {% thumbnail_imgtag thumb %}
-
-    Pass HTML parameters like this:: 
-
-        {% thumbnail_imgtag thumb class="preview" %}
-        {% thumbnail_imgtag thumb alt=person.name %}
-    """
-    args = token.split_contents()
-    if len(args) < 2:
-        raise template.TemplateSyntaxError("'%s' tag requires at least one argument" % args[0])
-    attributes = {}
-    for arg in args[2:]:
-        try:
-            k, v = arg.split('=', 1)
-        except ValueError:
-            raise template.TemplateSyntaxError("'%s' received invalid argument format - expected 'attr=val' but got '%s'" % (args[0], arg))
-        attributes[k] = v
-    return ThumbnailImgTagNode(thumbnail=args[1], attributes=attributes)
-
 re_dimensions = re.compile(r'(\d+)x(\d+)$')
 def get_thumbnail_node(token, debug=False, thumbnail_class=DjangoThumbnail):
     """