django-components/tests/components/glob/glob.py
Juro Oravec 42818ad6ff
refactor: fix component media URLs (#1067)
* refactor: fix component media URLs

* refactor: remove extraneous check and fix tests

* chore: bump v0.134
2025-03-23 22:32:18 +01:00

48 lines
1.5 KiB
Python

from django_components import Component
# The Media JS / CSS glob and are relative to the component directory
class GlobComponent(Component):
template = """
{% load component_tags %}
{% component_js_dependencies %}
{% component_css_dependencies %}
"""
class Media:
css = "glob_*.css"
js = "glob_*.js"
# The Media JS / CSS glob and are relative to the directory given in
# `COMPONENTS.dirs` and `COMPONENTS.app_dirs`
class GlobComponentRootDir(GlobComponent):
class Media:
css = "glob/glob_*.css"
js = "glob/glob_*.js"
# The Media JS / CSS are NOT globs, but URLs.
class UrlComponent(Component):
template = """
{% load component_tags %}
{% component_js_dependencies %}
{% component_css_dependencies %}
"""
class Media:
css = [
"https://cdnjs.cloudflare.com/example/style.min.css",
"http://cdnjs.cloudflare.com/example/style.min.css",
# :// is not a valid URL - will be resolved as static path
"://cdnjs.cloudflare.com/example/style.min.css",
"/path/to/style.css",
]
js = [
"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.2/chart.min.js",
"http://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.2/chart.min.js",
# :// is not a valid URL - will be resolved as static path
"://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.2/chart.min.js",
"/path/to/script.js",
]