hurry.resource 0.10

Flexible resources for web applications
Resources are files that are used as resources in the display of a web page, such as CSS files, Javascript files and images. Resources packaged together in a directory to be published as such are called a resource library.

When a resource is included in the head section of a HTML page, we call this a resource inclusion. An inclusion is of a particular resource in a particular library. There are two forms of this kind of inclusion in HTML: javascript is included using the script tag, and CSS (and KSS) are included using a link tag.

Inclusions may depend on other inclusions. A javascript resource may for instance be built on top of another javascript resource. This means both of them should be loaded when the page displays.

Page components may actually require a certain inclusion in order to be functional. A widget may for instance expect a particular Javascript library to loaded. We call this an inclusion requirement of the component.

hurry.resource is a module that provides a simple API to specify resource libraries, inclusion and inclusion requirements.

A resource library

We define a library foo. It takes two arguments, the name of the library as it should be published under in a URL and uniquely identify it, and a path to the root of the resources (rootpath) that this library publishes:

>>> from hurry.resource import Library
>>> foo = Library('foo', 'dummy')


The full path to the directory with the resources is reconstructed from the package that the Library is defined in:

>>> foo.path #doctest: +ELLIPSIS
'.../hurry.resource/src/hurry/resource/dummy'


Entry points

Libraries can be exposed for registration by whatever web framework that hurry.resource is integrated with. This web framework can then expose the library path on a URL somewhere. This is done using the hurry.resource.libraries entry point. To register Library instances foo and bar in your package as entry points include a section like this in your setup.py:

entry_points={
 'hurry.resource.libraries': [
 'foo = mypackage.foomodule:foo',
 'bar = mypackage.barmodule:bar',
 ],
 }


There is an API to help you obtain all registered libraries:

>>> from hurry.resource import libraries

Nothing is registered however:

>>> list(libraries())
[]


It would be nice to now have some tests that see whether entry points actually get picked up so, but that would require an involved test setup that we find difficult to construct.

last updated on:
February 15th, 2011, 10:26 GMT
price:
FREE!
developed by:
Martijn Faassen
homepage:
pypi.python.org
license type:
ZPL (Zope Public License) 
category:
ROOT \ Internet \ HTTP (WWW)

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!
What's New in This Release:
  • The WSGI Middleware depends on WebOb, which is an optional dependency. Don't expose it into the __init__.py therefore, as that needs to be independent of WebOb. To use the middleware import it directly from hurry.resource.wsgi.
  • The Library factory now has to be called with a rootpath argument as the second argument. This is a path to the actual resource directory that the library represents, relative to the directory of the package. This is needed to make `` hurry.resource`` useful for frameworks not based on zope.configuration.
  • This breaks backwards compatibility with previous versions of hurry.resource; all code that uses Library should be adjusted. Please also update their setup.py to depend on hurry.resource >= 0.10.
  • Packages should register their Library instances with hurry.resource using the hurry.resource.libraries entry point.
read full changelog

Add your review!

SUBMIT