[Checkins] SVN: hurry.zoperesource/trunk/ Support rendering inclusions at the bottom of the HTML as well as at the

Martijn Faassen faassen at infrae.com
Mon Oct 13 15:53:50 EDT 2008


Log message for revision 92161:
  Support rendering inclusions at the bottom of the HTML as well as at the
  top.
  

Changed:
  U   hurry.zoperesource/trunk/CHANGES.txt
  U   hurry.zoperesource/trunk/setup.py
  U   hurry.zoperesource/trunk/src/hurry/zoperesource/README.txt
  U   hurry.zoperesource/trunk/src/hurry/zoperesource/tests/ftesting.zcml
  A   hurry.zoperesource/trunk/src/hurry/zoperesource/tests/test_bottom.pt
  U   hurry.zoperesource/trunk/src/hurry/zoperesource/tests/view.py
  U   hurry.zoperesource/trunk/src/hurry/zoperesource/zopesupport.py

-=-
Modified: hurry.zoperesource/trunk/CHANGES.txt
===================================================================
--- hurry.zoperesource/trunk/CHANGES.txt	2008-10-13 19:51:31 UTC (rev 92160)
+++ hurry.zoperesource/trunk/CHANGES.txt	2008-10-13 19:53:49 UTC (rev 92161)
@@ -1,10 +1,14 @@
 CHANGES
 *******
 
-0.2 (unreleased)
+0.2 (2008-10-13)
 ================
 
-* ...
+* Add support for rendering fragments at the bottom of the page. When
+  you call ``hurry.resource.bottom`` resources which are marked bottom-safe
+  will be rendered at the bottom of the web page instead of in the ``<head>``
+  section. When you call ``hurry.resource.bottom(force=True)``, *all*
+  ``.js`` resources will be included at the bottom.
 
 0.1 (2008-10-11)
 ================

Modified: hurry.zoperesource/trunk/setup.py
===================================================================
--- hurry.zoperesource/trunk/setup.py	2008-10-13 19:51:31 UTC (rev 92160)
+++ hurry.zoperesource/trunk/setup.py	2008-10-13 19:53:49 UTC (rev 92161)
@@ -38,7 +38,7 @@
         'zope.traversing',
         'zope.securitypolicy',
         'zope.testbrowser',
-        'hurry.resource',
+        'hurry.resource > 0.1',
         ],
     entry_points={},
     )

Modified: hurry.zoperesource/trunk/src/hurry/zoperesource/README.txt
===================================================================
--- hurry.zoperesource/trunk/src/hurry/zoperesource/README.txt	2008-10-13 19:51:31 UTC (rev 92160)
+++ hurry.zoperesource/trunk/src/hurry/zoperesource/README.txt	2008-10-13 19:53:49 UTC (rev 92161)
@@ -51,3 +51,17 @@
   <p>the widget HTML itself</p>
   </body>
   </html>
+
+Let's force all javascript resources to be forced to be included at
+the bottom now, just before the ``</body>`` tag::
+
+  >>> browser.open('http://localhost/hurry.zoperesource.test_bottom')
+  >>> print browser.contents 
+  <html>
+  <head>
+  </head>
+  <body>
+  <p>the widget HTML itself</p>
+  <script type="text/javascript" src="http://localhost/@@/foo/a.js"></script>
+  <script type="text/javascript" src="http://localhost/@@/foo/b.js"></script></body>
+  </html>

Modified: hurry.zoperesource/trunk/src/hurry/zoperesource/tests/ftesting.zcml
===================================================================
--- hurry.zoperesource/trunk/src/hurry/zoperesource/tests/ftesting.zcml	2008-10-13 19:51:31 UTC (rev 92160)
+++ hurry.zoperesource/trunk/src/hurry/zoperesource/tests/ftesting.zcml	2008-10-13 19:53:49 UTC (rev 92161)
@@ -46,4 +46,12 @@
     class=".view.TestMultiple"
     />
 
+  <browser:page
+    for="zope.interface.Interface"
+    name="hurry.zoperesource.test_bottom"
+    permission="zope.Public"
+    template="test_bottom.pt"
+    class=".view.TestBottom"
+    />
+
 </configure>

Added: hurry.zoperesource/trunk/src/hurry/zoperesource/tests/test_bottom.pt
===================================================================
--- hurry.zoperesource/trunk/src/hurry/zoperesource/tests/test_bottom.pt	                        (rev 0)
+++ hurry.zoperesource/trunk/src/hurry/zoperesource/tests/test_bottom.pt	2008-10-13 19:53:49 UTC (rev 92161)
@@ -0,0 +1,7 @@
+<html>
+<head>
+</head>
+<body>
+<p tal:content="view/widget"></p>
+</body>
+</html>

Modified: hurry.zoperesource/trunk/src/hurry/zoperesource/tests/view.py
===================================================================
--- hurry.zoperesource/trunk/src/hurry/zoperesource/tests/view.py	2008-10-13 19:51:31 UTC (rev 92160)
+++ hurry.zoperesource/trunk/src/hurry/zoperesource/tests/view.py	2008-10-13 19:53:49 UTC (rev 92161)
@@ -1,6 +1,6 @@
 from zope import component
 from hurry.resource.interfaces import ICurrentNeededInclusions
-from hurry.resource import Library, ResourceInclusion
+from hurry.resource import Library, ResourceInclusion, bottom
 
 foo = Library("foo")
 
@@ -17,3 +17,10 @@
     def widget(self):
         b.need()
         return "the widget HTML itself"
+
+class TestBottom(object):
+    def widget(self):
+        b.need()
+        bottom(force=True)
+        return "the widget HTML itself"
+

Modified: hurry.zoperesource/trunk/src/hurry/zoperesource/zopesupport.py
===================================================================
--- hurry.zoperesource/trunk/src/hurry/zoperesource/zopesupport.py	2008-10-13 19:51:31 UTC (rev 92160)
+++ hurry.zoperesource/trunk/src/hurry/zoperesource/zopesupport.py	2008-10-13 19:53:49 UTC (rev 92161)
@@ -54,11 +54,13 @@
 
             needed = component.getUtility(ICurrentNeededInclusions)()
 
-            html = needed.render()
+            top, bottom = needed.render_topbottom()
             
-            if html:
-                body = body.replace('<head>', '<head>\n    %s\n' %
-                                    html, 1)
+            if top:
+                body = body.replace('<head>', '<head>\n    %s\n' % top, 1)
+            if bottom:
+                body = body.replace('</body>', '%s</body>' % bottom, 1)
+
         return super(Response, self)._implicitResult(body)
 
 class NoRequestError(Exception):



More information about the Checkins mailing list