Skip to main content

Integrate Assetgen with the Pyramid framework.

Project description

Provides an add_assetgen_manifest configuration directive and

AssetGenRequestMixin custom request factory mixin class that can be used to integrate Assetgen with a Pyramid application.

Configure your Pyramid app (e.g.: in your main / WSGI app factory function):

from pyramid.request import Request
class MyRequest(AssetGenRequestMixin, Request): pass
config.set_request_factory(MyRequest)
config.add_directive('add_assetgen_manifest', add_assetgen_manifest)

(Note that the AssetGenRequestMixin argument must come before Request in your request factory class definition).

Expose the directory your assetgen’d static files are in as per normal using add_static_view and then register an assetgen manifest for the directory you’ve exposed by calling add_assetgen_manifest with the same path or pyramid asset specification you passed to add_static_view, e.g., assuming you have a manifest file at 'mypkg:static/assets.json:

config.add_static_view('static', 'mypkg:static')
config.add_assetgen_manifest('mypkg:static')

If your manifest file is somewhere else, use the manifest keyword argument to specify where it is, e.g.:

config.add_assetgen_manifest('mypkg:static', manifest='/foo/bar.json')

Once configured, you can use request.static_path(path, **kw) and request.static_url(path, **kw) as normal, e.g.:

request.static_url('mypkg:static/base.js')

Under the hood, static_url will now check the path to the static file you’re serving and, if it’s in a directory that you’ve exposed with an assetgen manifest, will look in the manifest file for a key that matches the path (relative to the directory) and, if found, will expand it.

So, for example, if you have registered a manifest containing:

{'foo.js': 'foo-fdsf465ds4f567ds4ds5674567f4s7.js'}

Calling:

request.static_url('mypkg:static/foo.js')

Will return:

'/static/foo-fdsf465ds4f567ds4ds5674567f4s7.js'

assetgen: http://pypi.python.org/pypi/assetgen configuration directive: http://readthedocs.org/docs/pyramid/en/latest/narr/extconfig.html custom request factory: http://readthedocs.org/docs/pyramid/en/latest/narr/hooks.html#changing-the-request-factory pyramid: http://readthedocs.org/docs/pyramid

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyramid_assetgen-0.2.2.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file pyramid_assetgen-0.2.2.tar.gz.

File metadata

File hashes

Hashes for pyramid_assetgen-0.2.2.tar.gz
Algorithm Hash digest
SHA256 05f12e2d4a0821fe459ee8500c92f97d300bfe229cef1c2e9cb5c97bbda99b08
MD5 4956a5a02241c33d5ced4342b4d9b6e4
BLAKE2b-256 455035d9df7f5c9222d47b6c4847e64e673e7b0688e8b5619b440db07a050b4f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page