Loaders¶
Using these helper classes, you can define your bundles or even your complete environment in some external data source, rather than constructing them in code.
-
class
webassets.loaders.
YAMLLoader
(file_or_filename)¶ Will load an environment or a set of bundles from YAML files.
-
load_bundles
(environment=None)¶ Load a list of
Bundle
instances defined in the YAML file.Expects the following format:
bundle-name: filters: sass,cssutils output: cache/default.css contents: - css/jquery.ui.calendar.css - css/jquery.ui.slider.css another-bundle: # ...
Bundles may reference each other:
js-all: contents: - jquery.js - jquery-ui # This is a bundle reference jquery-ui: contents: jqueryui/*.js
If an
environment
argument is given, it’s bundles may be referenced as well. Note that you may pass any compatibly dict-like object.Finally, you may also use nesting:
js-all: contents: - jquery.js # This is a nested bundle - contents: "*.coffee" filters: coffeescript
-
load_environment
()¶ Load an
Environment
instance defined in the YAML file.Expects the following format:
directory: ../static url: /media debug: True updater: timestamp filters: - my_custom_package.my_filter config: compass_bin: /opt/compass another_custom_config_value: foo bundles: # ...
All values, including
directory
andurl
are optional. The syntax for defining bundles is the same as forload_bundles()
.Sample usage:
from webassets.loaders import YAMLLoader loader = YAMLLoader('asset.yml') env = loader.load_environment() env['some-bundle'].urls()
-
-
class
webassets.loaders.
PythonLoader
(module_name)¶ Basically just a simple helper to import a Python file and retrieve the bundles defined there.
-
load_bundles
()¶ Load
Bundle
objects defined in the Python module.Collects all bundles in the global namespace.
-
load_environment
()¶ Load an
Environment
defined in the Python module.Expects as default a global name
environment
to be defined, or overridden by passing a stringmodule:environment
to the constructor.
-