Commits

Anonymous committed 1010426

[svn] Sync'd asset tag helper to 6057
o enforce image_tag's size arg syntax better
o some more docs/tests

Comments (0)

Files changed (3)

 WebHelpers ChangeLog
 
 0.2.3 (**svn**)
+* Sync'd Asset tag helper to 6057.
 * Sync'd Rails Number helper to 6045.
 * Updated Ajax commands to internally use 'with_' to avoid name conflicts with
   Python 2.5 and beyond. Reported by anilj. Fixes #190.

tests/test_asset_tag.py

                          image_tag('symbolize.jpg', size='45x70'))
         self.assertEqual('<img alt="Pylons-Tower-Dark1" src="http://pylons.tgtg.org/powered/_img/pylons-tower-dark1.png" />',
                          image_tag('http://pylons.tgtg.org/powered/_img/pylons-tower-dark1.png'))
+        self.assertEqual('<img alt="Edit Entry" height="10" src="/images/icon.png" width="16" />',
+            image_tag("icon.png", size="16x10", alt="Edit Entry"))
+        self.assertEqual('<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />',
+            image_tag("/icons/icon.gif", size="16x16"))
+        self.assertEqual('<img alt="Icon" src="/icons/icon.gif" width="16" />',
+            image_tag("/icons/icon.gif", size="16x"))
 
     def test_javascript_include_tag(self):
         self.assertEqual("""<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/scriptaculous.js" type="text/javascript"></script>""",
                          stylesheet_link_tag('style', media='all'))
         self.assertEqual('<link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />',
                          stylesheet_link_tag('random.styles', '/css/stylish'))
+        self.assertEqual('<link href="/stylesheets/dir/file.css" media="all" rel="Stylesheet" type="text/css" />',
+                         stylesheet_link_tag('dir/file', media='all'))
 
     def test_compute_public_path(self):
         self.assertEqual('/test.js', compute_public_path('/test.js'))

webhelpers/rails/asset_tag.py

 Asset Tag Helpers
 
 Provides functionality for linking an HTML page together with other assets, such as
-javascripts, stylesheets, and feeds.
+images, javascripts, stylesheets, and feeds.
 """
-# Last synced with Rails copy at Revision 4999 on Sep 6th, 2006.
+# Last synced with Rails copy at Revision 6057 on Feb 7th, 2007.
 
 import os
+import re
 import urlparse
 import warnings
 from tags import *
         '<img alt="Xml" src="/images/xml.png" />'
 
         >>> image_tag('rss.png', 'rss syndication')
-        '<img alt="rss syndication" src="/images/rss.png" />'    
+        '<img alt="rss syndication" src="/images/rss.png" />'
+
+        >>> image_tag("icon.png", size="16x10", alt="Edit Entry")
+        '<img alt="Edit Entry" height="10" src="/images/icon.png" width="16" />'
+
+        >>> image_tag("/icons/icon.gif", size="16x16")
+        '<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />'
+
+        >>> image_tag("/icons/icon.gif", size="16x")
+        '<img alt="Icon" src="/icons/icon.gif" width="16" />'
     """
     if not os.path.splitext(source)[1]:
         warnings.warn("You've called image_tag with a source that doesn't include an "
         alt = os.path.splitext(os.path.basename(source))[0].title()
     options['alt'] = alt
     
-    if size:
+    if size and re.match('^(\d+|)x(\d+|)$', size) and size != 'x':
         width, height = size.split('x')
         if width:
             options['width'] = width
         >>> stylesheet_link_tag('style')
         '<link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />'
 
+        >>> stylesheet_link_tag('dir/file', media='all')
+        '<link href="/stylesheets/dir/file.css" media="all" rel="Stylesheet" type="text/css" />'
+
         >>> stylesheet_link_tag('/dir/file', media='all')
         '<link href="/dir/file.css" media="all" rel="Stylesheet" type="text/css" />'
     """