An opinionated Webassets integration for Morepath.
Now that you are sufficently discouraged from using more.webassets, these are the reasons it might be for you:
- You can have your assets compiled on the fly.
- Your stylesheets are rendered at the top, your scripts at the bottom. No configuration necessary.
If you are alreay familiar with webassets: This package might not be as powerful as you’re used to. It currently has little flexibility. It’s also the first time the author uses webassets, so things might be off.
If you’re using Webassets differently than me and you want your ways to work with more.webassets, do open an issue. I’m happy to turn this into something more powerful.
The following app serves a minified jquery from assets/js/jquery.js (relative to the code):
from more.webassets import WebassetsApp class App(WebassetsApp): pass @App.webasset_path() def get_asset_path(): return 'assets/js' @App.webasset_output() def get_output_path(): return 'assets/bundles' @App.webasset_filter('js') def get_js_filter(): return 'rjsmin' @App.webasset('jquery') def get_jquery_asset(): yield 'jquery.js' @App.path('') class Root(object): pass @App.html(model=Root) def index(self, request): request.include('jquery') return '<html><head></head><body>hello</body></html>'
This will result in the following html (formatted for readability):
For it to work you need an ‘assets/js’ folder with a ‘jquery.js’ file in the same folder as your python file where ‘MyApp’ is defined.
To activate webassets debug mode use the following environment variable:
Most documentation is currently found in source code. Have a look at the comments in the directives file.
Run the Tests
Install tox and run it:
pip install tox tox
Limit the tests to a specific python version:
tox -e py27
More Webassets follows PEP8 as close as possible. To test for it run:
tox -e pep8
More Webassets uses Semantic Versioning
more.webassets is released under the revised BSD license
- Fixes an additional case default filters overriding asset specific filters. [href]
- Stops default filters from overriding asset specific filters. [href]
- Adds the ability to define a list of filters (chain) on an asset. [href]
- Adds the ability chain output filters (i.e. jsx -> jss -> minified). [href]
Render the script tag inside the body element instead of after it.
This turns the output into valid HTML. Rendering it outside the body element as it was done before works in practice, but it is technically not valid. [href]
- Add Python 3.5 and make it the default test environment.
- Update to work with Morepath 0.16.
- Ensures that the webasset_path is always an absolute path. [href]
- Adds a debug environment variable used to activate webasset’s debug mode. [href]
- Uses a temporary default output directory if none is specified. [href]
Breaking Changes - This release changes everything!
Assets are no longer registerd through special methods on the application. Instead proper Morepath directives are used. This enables better re-use of assets, less verbosity and proper support of inheritance (you can now have applications which define assets and child-applications which use those assets).
Don’t hesitate to open an issue if you need help migrating your existing setup.
- Adds compatibility with morepath 0.13. [href]
- Disables webassets url caching if debug mode is active. [href]
- Support webassets debug mode (before it would trigger an exception). [href]
If this is an issue for you, speak up and we might add a debug flag. [href]
- Adds more checks to ensure we never serve anything outside the assets directory. [href]
- Initial Release [href]
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|more.webassets-0.5.1-py3-none-any.whl (21.0 kB) Copy SHA256 hash SHA256||Wheel||py3|
|more.webassets-0.5.1.tar.gz (14.2 kB) Copy SHA256 hash SHA256||Source||None|