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 Assets to an AppConfig using ox.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.

js: str

Static directory name, defaults to name.

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 (see ox.utils.functional.Owned, and contribute());

  • not related to a Django app: in this case, a path to the package is provided;

contribute(owner)[source]

TODO

property css_urls: set[str][source]

A list of CSS static urls.

dependencies: list[Asset] | None = None

Dependencies.

get_dependencies_urls(attr)[source]

Return urls of dependencies, based on attr attribute value.

Return type:

Generator[tuple[str, str], None, None]

get_dependency_url(asset, attr)[source]

Return url of an

Return type:

tuple[str, str] | None

get_includes_urls(attr)[source]

Return urls of includes, based on attr attribute 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 inner Assets instances.

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]

property import_map: dict[str, str][source]

A list of CSS static urls.

includes: list[Asset] | None = None

Exported assets.

property js_urls: set[str][source]

A list of JS static urls.

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 path is 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/ox package.

class ox.assets.finders.AssetsFinder(apps=None, *args, **kwargs)[source]

This class is used to find static based on applications’ Assets.

property assets: list[Assets][source]

A list of applications assets and dependencies.

find(path, find_all=False)[source]

Given a relative file path, find an absolute file path.

If the find_all parameter is False (default) return only the first found file path; if True, return a list of all found files paths.

list(ignore_patterns=[])[source]

Given an optional list of paths to ignore, return a two item iterable consisting of the relative path and storage instance.

property locations: list[tuple[str, Path]][source]

A list of prefix, path tuples used for looking up locations.