Web resource (CSS/JS) management mixin extracted from Objects.Object.
ObjResource manages CSS and JavaScript resource lists for web pages. It
handles CDN mapping, alias resolution (e.g. @sweetalert), and optional
minification via rjsmin. Mixed into Object so all web-facing modules
inherit resource management.
ObjResource is a mixin, not a standalone class. It expects the host class
to provide:
self.ResourceCss -- list of CSS file paths/URLsself.ResourceScript -- list of JavaScript file paths/URLsself.debug(*args) -- logging methodself.load_cdn_mappings() -- optional CDN configuration loaderResources are deduplicated on add (no duplicates in the lists). When the
module-level DO_COMPRESS flag is True, local files are minified using
rjsmin and cached with an .axion.css or .axion.js suffix. When
compression is disabled, cached minified files are cleaned up.
| Method | Description |
|---|---|
add_resource_css(css_file_name) |
Add a CSS resource to the page. Resolves CDN mappings and @ aliases, optionally minifies, appends to self.ResourceCss. Returns the final file name or CDN URL. |
add_resource_script(script_name) |
Add a JavaScript resource to the page. Resolves CDN mappings and @ aliases, optionally minifies, appends to self.ResourceScript. Returns the final script name or CDN URL. |
get_parent_name() |
Return the command name of the parent process using psutil, or empty string on failure. |
Both add_resource_css and add_resource_script support alias-based
resource references. Names starting with @ are looked up in the CDN
mapping configuration returned by self.load_cdn_mappings():
# Alias resolves to a CDN URL
self.add_resource_css("@sweetalert")
# Path mapping resolves a local file to its CDN equivalent
self.add_resource_script("chart.js")
When DO_COMPRESS is True:
filename.axion.cssfilename.axion.js.min.js) and CDN URLs (http...) are skippedWhen DO_COMPRESS is False, any previously cached .axion.css and
.axion.js files are deleted to keep the resource directories clean.
DO_COMPRESS -- Controls minification behavior (default False)