Skip to main content
CI Status https://coveralls.io/repos/github/morepath/more.webassets/badge.svg?branch=master https://img.shields.io/pypi/v/more.webassets.svg https://img.shields.io/pypi/pyversions/more.webassets.svg

More Webassets

An opinionated Webassets integration for Morepath.

Webassets | Morepath

This package is somewhat similar to more.static, which integrates bowerstatic into Morepath. It is currently not really used anywhere, so you should probably stick to more.static.

Now that you are sufficently discouraged from using more.webassets, these are the reasons it might be for you:

  • You don’t have to learn about javascript package managers (i.e. Bower).

  • 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.

Usage

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):

<html>
    <head></head>
    <body>
        hello
        <script type="text/javascript" src="./assets/jquery.bundle.js?1234"></script>
    </body>
</html>

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.

Debug Mode

To activate webassets debug mode use the following environment variable:

MORE_WEBASSETS_DEBUG=1

Documentation

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 py311

Conventions

More Webassets follows PEP8 as close as possible. To test for it run:

tox -e lint

More Webassets uses Semantic Versioning

License

more.webassets is released under the revised BSD license

Changelog

0.5.2 (2026-08-05)

  • Switch to PEP-420 namespace package

  • Drop support for Python below 3.10

  • Use GitHub Actions for CI.

  • Ensure assets are also included in error views. #13 by Cyrill Küttel

0.5.1 (2017-07-12)

  • Fixes an additional case default filters overriding asset specific filters. [href]

0.5.0 (2017-07-12)

  • Stops default filters from overriding asset specific filters. [href]

  • Adds the ability to define a list of filters (chain) on an asset. [href]

0.4.0 (2017-07-10)

  • Adds the ability chain output filters (i.e. jsx -> jss -> minified). [href]

0.3.4 (2017-05-03)

  • 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]

0.3.3 (2016-10-04)

  • Add Python 3.5 and make it the default test environment.

  • Update to work with Morepath 0.16.

0.3.2 (2016-04-11)

  • Ensures that the webasset_path is always an absolute path. [href]

0.3.1 (2016-04-11)

  • Adds a debug environment variable used to activate webasset’s debug mode. [href]

  • Uses a temporary default output directory if none is specified. [href]

0.3.0 (2016-04-08)

  • 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).

    Have a look at the readme and at the comments in the directives file, to get an idea about what has changed.

    Don’t hesitate to open an issue if you need help migrating your existing setup.

0.2.0 (2016-04-06)

  • Adds compatibility with morepath 0.13. [href]

0.1.1 (2016-01-24)

  • Disables webassets url caching if debug mode is active. [href]

0.1.0 (2016-01-24)

  • Support webassets debug mode (before it would trigger an exception). [href]

0.0.3 (2015-08-07)

  • Cache the resource urls for increased speed. Note that with this change a reload of the application is necessary to get the updated javascript files.

    If this is an issue for you, speak up and we might add a debug flag. [href]

0.0.2 (2015-05-18)

  • Adds more checks to ensure we never serve anything outside the assets directory. [href]

0.0.1 (2015-04-29)

  • Initial Release [href]

Download files

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

Source Distribution

more_webassets-0.5.2.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

more_webassets-0.5.2-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file more_webassets-0.5.2.tar.gz.

File metadata

  • Download URL: more_webassets-0.5.2.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for more_webassets-0.5.2.tar.gz
Algorithm Hash digest
SHA256 395767f0d3c42f772f0c1ad53c8b7b5bb16499830be1250fc3ea6a1e7c50a58e
MD5 00c9793a847b19f5423588a860de9fe5
BLAKE2b-256 095e06b1eb1480d13c920442aff80fa10cc35c8028ea2e3904472f5801f85cb1

See more details on using hashes here.

File details

Details for the file more_webassets-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: more_webassets-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for more_webassets-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 560631a2c7f6382e5679ab2c2b5b4f3c93af060011152034bd779baaeb4f0e77
MD5 b1f3dc90526f1cdb9d5132e0bd336879
BLAKE2b-256 923f1780709ed0ad7a9894650928d972760dfd3d44a24cdb6a0ac7bb7a796bca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page