Fanstatic integration for Zope.
Project description
Zope integration for fanstatic
This package provides Zope integration for fanstatic. This means it’s taking care of three things:
provide access to the needed resources throughout the request/response cycle.
provide the base URL for the resources to be rendered.
clear the needed resources when an exception view is rendered.
This library fulfills these conditions for a Zope Toolkit/Grok setup.
We’ll run through a few tests to demonstrate it. Note that the real code being tested is not in this document itself, but in the views described in ftesting.zcml.
We need to be in a request to make this work, so let’s up a request to a page we have set up in ftesting.zcml that should cause the inclusion of a single resource in its header:
>>> from zope.app.wsgi.testlayer import Browser >>> browser = Browser() >>> browser.open('http://localhost/zope.fanstatic.test_single') >>> print browser.contents <html> <head> <script type="text/javascript" src="http://localhost/fanstatic/foo/a.js"></script> <BLANKLINE> </head> <body> <p>the widget HTML itself</p> </body> </html>
If a resource happens to need another resource, this resource is also automatically included:
>>> browser.open('http://localhost/zope.fanstatic.test_multiple') >>> print browser.contents <html> <head> <script type="text/javascript" src="http://localhost/fanstatic/foo/a.js"></script> <script type="text/javascript" src="http://localhost/fanstatic/foo/b.js"></script> <BLANKLINE> </head> <body> <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/zope.fanstatic.test_bottom') >>> print browser.contents <html> <head> </head> <body> <p>the widget HTML itself</p> <script type="text/javascript" src="http://localhost/fanstatic/foo/a.js"></script> <script type="text/javascript" src="http://localhost/fanstatic/foo/b.js"></script></body> </html>
In-template resources
zope.fanstatic provides support for rendering resource publisher aware URLs to in-template resources:
>>> browser.open('http://localhost/zope.fanstatic.test_inline_resource') >>> print browser.contents <html> <head> </head> <body> <img src="http://localhost/fanstatic/foo/evencaveman.jpg" /> <img src="http://localhost/fanstatic/foo/sub/evencaveman.jpg" /> </body> </html>
Exception views
When an exception occurs in the rendering of a view, we don’t want to have any needed resources intended for a view being also injected in the error view. The needed resources are cleared and if the exception view chooses to do so, it can need resources itself.
>>> browser.raiseHttpErrors = False >>> browser.open('http://localhost/zope.fanstatic.test_error') >>> import fanstatic >>> fanstatic.get_needed().has_resources() False
CHANGES
0.10 (2011-04-11)
Update to fanstatic 0.11 API.
0.9.1 (2011-01-20)
Do not clear resources on DummyNeededResources objects.
0.9 (2011-01-20)
Integrate zope.errorview, subscribing to the HandleExceptionEvent. This will clear the needed resources thusfar required, to have a clean slate for the error view to be rendered.
0.9b (2011-01-06)
Zope.fanstatic version 0.9 is a fundamental rewrite of hurry.zoperesource, as a result of the rewrite of hurry.resource into fanstatic.
Here’s a list of essential changes since version 0.7 of hurry.zoperesource:
Compliance with the Fanstatic API.
++resource++foo/bar/baz.jpg expressions in Page Templates are still supported by way registering a traversable component for all available resource libraries. There are no zope.browserresource components involved anymore in zope.fanstatic.
Download
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file zope.fanstatic-0.10.tar.gz
.
File metadata
- Download URL: zope.fanstatic-0.10.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc0766fe7ec70d5c732116aeb25e3f53857311d4904fc45b3d4f3104dc1dc7f0 |
|
MD5 | d3735d5514763345dc095c62266c2565 |
|
BLAKE2b-256 | b480053a3168e0e49dc57e00b6f615754f6360d1caa2eb9fb76bcf67a7a8b28e |