Commits

Anonymous committed ec199b1

[svn] added support for the defer attribute to javascript_include_tag
suggested by s0undt3ch
fixes #214

  • Participants
  • Parent commits 278f444

Comments (0)

Files changed (3)

 WebHelpers ChangeLog
 
+0.3.1 (**svn**)
+* Added support for the defer attribute to javascript_include_tag. Suggested by
+  s0undt3ch. Fixes #214.
+
 0.3 (03/18/2007)
 * WARNING: paginate now takes arguments intended for the collection object as
   query_args. This could affect backwards compatibility. This fixes a common

tests/test_asset_tag.py

                          javascript_include_tag(builtins=True))
         self.assertEqual("""<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/other-javascripts/util.js" type="text/javascript"></script>""",
                          javascript_include_tag('prototype', '/other-javascripts/util.js'))
+        self.assertEqual("""<script defer="defer" src="/js/pngfix.js" type="text/javascript"></script>""",
+                         javascript_include_tag('/js/pngfix.js', defer=True))
+        self.assertEqual("""<script defer="defer" src="/js/pngfix.js" type="text/javascript"></script>""",
+                         javascript_include_tag('/js/pngfix.js', defer="defer"))
         self.assertEqual("""<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/scriptaculous.js" type="text/javascript"></script>\n<script src="/javascripts/app.js" type="text/javascript"></script>\n<script src="/test/test.1.js" type="text/javascript"></script>""",
                          javascript_include_tag('app', '/test/test.1.js', builtins=True))
 

webhelpers/rails/asset_tag.py

     Optionally includes (prepended) WebHelpers' built-in javascripts when passed the
     ``builtins=True`` keyword argument.
 
+    Specify the keyword argument ``defer=True`` to enable the script defer attribute.
+
     Examples::
     
         >>> print javascript_include_tag(builtins=True)
         <script src="/javascripts/prototype.js" type="text/javascript"></script>
         <script src="/javascripts/scriptaculous.js" type="text/javascript"></script>
 
+        >>> print javascript_include_tag(builtins=True, defer=True)
+        <script defer="defer" src="/javascripts/prototype.js" type="text/javascript"></script>
+        <script defer="defer" src="/javascripts/scriptaculous.js" type="text/javascript"></script>
+
         >>> print javascript_include_tag('prototype', '/other-javascripts/util.js')
         <script src="/javascripts/prototype.js" type="text/javascript"></script>
         <script src="/other-javascripts/util.js" type="text/javascript"></script>
         <script src="/javascripts/app.js" type="text/javascript"></script>
         <script src="/test/test.1.js" type="text/javascript"></script>
     """
-    if options.get('builtins'):
+    if options.pop('builtins', False):
         sources = javascript_builtins + sources
-        
-    tags = [content_tag('script', None,
-                        **dict(type='text/javascript',
-                               src=compute_public_path(source, 'javascripts', 'js'))) \
-            for source in sources]
+    if options.get('defer') == True:
+        options['defer'] = 'defer'
+
+    tags = []
+    for source in sources:
+        content_options = dict(type='text/javascript',
+                               src=compute_public_path(source, 'javascripts',
+                                                       'js'))
+        content_options.update(options)
+        tags.append(content_tag('script', None, **content_options))
     return '\n'.join(tags)
 
 def stylesheet_link_tag(*sources, **options):