WSGI middleware to manipulate css and javascript in the HTML header.
Project description
See ‘src/zif/headincludes/README.txt’ for more information.
Releases
0.4 (2010/03/12)
Added test and buildout configuration. Properly does requirements-of-requirements now. Many thanks to an anonymous contributor.
0.3 (2007/05/25)
Release to include zcml files that were missing from distribution.
0.2 (2007/04/13)
Correct releases README.
0.1 (2007/04/13)
Initial release.
Detailed Documentation
zif.headincludes
This is a wsgi middleware application intended for use with paste.deploy, zope.paste, and zope3.
It serves as a wsgi filter to create on-the-fly < script> and <style> tags inside the <head> of HTML documents. It was designed for output from a Zope3 application, but the wsgi filter itself, in headincluder.py, has no Zope3 dependencies.
The idea is that subobjects of a document may separately need special resources, but it is difficult to know whether a resource is asked for multiple times when documents are dynamically generated. For Zope3, headincludes replaces the functionality of zc.resourcelibrary, which also implements this idea. In fact, mostly because headincludes “borrows” code from zc.resourcelibrary, they may be installed side-by-side, but only one can be used at a time, because they both implement <zope:resourceLibrary> tags for zcml and the <tal:resource_library> statement for PageTemplates.
headincludes works by creating a key in the wsgi environment, ‘wsgi.html.head.includes’ that is a list of urls that need to be referenced in the head of the HTML document for the current request. The application registers a need for the reference by appending the url for the reference to the list. Urls that end in “.css” and “.js” in that list trigger the middleware to insert <style> or <script> tags into the <head> of the document after the application is done creating the HTML.
headincludes tries to maintain as much compatibility as possible with zc.resourcelibrary. The need() function has been rewritten, and using the headincludes version will be a simple matter of changing the import statement. The <tal:resource_library> statement is also still functional.
One new thing headincludes allows is arbitrary includes without needing to register the resource. urls can be placed in the includes list at any time that request.environ can be accessed. Just append any desired url to the list, e.g.,
try: request.environ['wsgi.html.head.includes'].append('/scripts/my_url.js') except KeyError: (handle case when the filter is not available)
Alternatively, headincludes has a utility that provides IHeadIncludeRegistration:
from zope.component import getUtility from zif.headincludes.interfaces import IHeadIncludeRegistration registrar = getUtility(IHeadIncludeRegistration) if registrar: registrar.register('scripts/my_url.js')
Dependencies
For zope3, headincludes requires Sidnei da Silva’s zope.paste
zope.paste is available at http://svn.zope.org/zope.paste/trunk/
cd [path.to.zope3.src.directory]/zope svn co http://svn.zope.org/zope.paste/trunk/ paste
Instructions for zope.paste are at http://awkly.org/
zope.paste requires paste.deploy. paste.deploy can be obtained from the cheese shop. Presuming you have setuptools installed,
sudo easy_install.py PasteDeploy
This (headincludes) package can be unzipped and installed anywhere on the Python path.
Setup
Follow Sidnei’s instructions for setting up zope.paste. It involves putting the usual zope.paste-configure.zcml file in [zope3 instance]/etc/site-packages. There is also a parameter to change in [zope3 instance]/etc/zope.conf. The new twist is a paste.ini file in [zope3 instance]/etc
For Zope3, copy the headincludes-configure.zcml and headincludes-meta.zcml files into [zope3 instance]/etc/package-includes directory.
An example paste.ini file looks like:
[pipeline:Paste.Main] pipeline = headincludes main [app:main] paste.app_factory = zope.paste.application:zope_publisher_app_factory [filter:headincludes] paste.filter_factory=zif.headincludes.headincluder:filter_factory location=top
Configuration
The paste.ini file above shows an example of the configuration option for headincludes
location is where in the <head> you want the new tags. “top” is the default, and places the new script and/or style tags just after the <head> element. Any other value will place the tags just before the </head> tag.
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
Built Distribution
File details
Details for the file zif.headincludes-0.4.tar.gz
.
File metadata
- Download URL: zif.headincludes-0.4.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb31828f3d805ecf5f7a75ec49b7beea3e543862e04632bc010bee11af1f36e8 |
|
MD5 | ca5d672eb073c22ddee6b75849a2ad9d |
|
BLAKE2b-256 | ebb62a6e31cfe1d67bddf8864cf1813864e6c681631c05aa7d2b2d8a883e1a81 |
File details
Details for the file zif.headincludes-0.4-py2.5.egg
.
File metadata
- Download URL: zif.headincludes-0.4-py2.5.egg
- Upload date:
- Size: 30.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a62285c7442a34984ee0a6e9836e53aca91876b9059d165ecaf1a6465e6611f |
|
MD5 | 513cccf4bcd69490792d4596ee428f3e |
|
BLAKE2b-256 | b6c83ebb3b4e8ab6264769d0da9a28ed11ccb4a0257a46e266a7a57e467e674d |