ox.assets
This module provides assets management and integration into django apps.
Each Asset represent an npm package to use as static. They
are regrouped under the Assets class that represent the
current django application’s frontend requirements.
It provides the following features:
attach
Assetsto anAppConfigusingox.utils.functional.Owned;Provide a list of assets to include in the application template;
Provide an import map object that will map the provided dependencies to the corresponding files;
It allows to integrate theses dependencies as static using the
AssetsFinder.
By technical convention, Oxylus only handles building Vue based Vite.js projects. However it allows to run other frameworks.
- class ox.assets.Asset(name, js='', css='', dev_js='', static_dir='', dist='dist')[source]
A single Asset’s dependency.
- It target a specific static module and can provide:
javascript and development javascript distribution file
css directory
-
css:
str Include this javascript file.
-
dist:
str Distribution path. The file will be looked up there.
-
name:
str Asset’s package/module name, used as is for generated import map and in order to find packages in
node_modules.
-
static_dir:
str Include this css file.
- class ox.assets.Assets(name='', path=None, includes=None, dependencies=None, base_dir=None, owner=None)[source]
This class represent a package for a Django application.
It is responsible to:
provide a list of CSS, JS to include;
generate the import map (in
ox/core/base.html);provide list of directories and dependencies to include in statics;
provide list of exported files to include into the rendered templates;
A package can be related to a Django application or not:
related to a Django app: in this case it is expected that the package resides in
app_dir/assets(seeox.utils.functional.Owned, andcontribute());not related to a Django app: in this case, a path to the package is provided;
- get_dependencies_urls(attr)[source]
Return urls of dependencies, based on
attrattribute value.- Return type:
Generator[tuple[str,str],None,None]
- get_includes_urls(attr)[source]
Return urls of includes, based on
attrattribute value.- Return type:
Generator[tuple[str,str],None,None]
- get_locations()[source]
Get locations of npm packages.
Return a generator that yield tuples of
(prefix, path_to_dist). It doesn’t yield values from innerAssetsinstances.- Return type:
Generator[tuple[str,Path],None,None]
- get_urls(attr)[source]
Iter over assets and yield tuples
(asset.name, attribute).- Return type:
Generator[tuple[str,str],None,None]
-
name:
str= '' Package name
- property package_path: Path[source]
Get the actual path to package directory.
- Raises:
RuntimeError – assets is related to an app and the assets directory does not exists or when not related to a path and no
pathis provided.
-
path:
Path|None= None Path of the package (or workspace’s packages dir).
The actual package path is retrieved using
package_path.
- ox.assets.ox_assets = <ox.assets.base.Assets object>
Common assets for all applications, as it provides the
@oxylus/oxpackage.
- class ox.assets.finders.AssetsFinder(apps=None, *args, **kwargs)[source]
This class is used to find static based on applications’
Assets.- find(path, find_all=False)[source]
Given a relative file path, find an absolute file path.
If the
find_allparameter is False (default) return only the first found file path; if True, return a list of all found files paths.