feat: add Media.extend (#890)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Juro Oravec 2025-01-07 22:55:17 +01:00 committed by GitHub
parent 5e8770c720
commit ab037f24b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 727 additions and 61 deletions

View file

@ -490,6 +490,9 @@ class Component(
This path is still rendered to HTML with `media_class.render_js()` or `media_class.render_css()`.
- A `SafeString` (with `__html__` method) is considered an already-formatted HTML tag, skipping both static file
resolution and rendering with `media_class.render_js()` or `media_class.render_css()`.
- You can set [`extend`](../api#django_components.ComponentMediaInput.extend) to configure
whether to inherit JS / CSS from parent components. See
[Controlling Media Inheritance](../../concepts/fundamentals/defining_js_css_html_files/#controlling-media-inheritance).
However, there's a few differences from Django's Media class:
@ -498,8 +501,6 @@ class Component(
2. Individual JS / CSS files can be any of `str`, `bytes`, `Path`,
[`SafeString`](https://dev.to/doridoro/django-safestring-afj), or a function
(See [`ComponentMediaInputPath`](../api#django_components.ComponentMediaInputPath)).
3. Our Media class does NOT support
[Django's `extend` keyword](https://docs.djangoproject.com/en/5.1/topics/forms/media/#extend)
**Example:**
@ -518,7 +519,7 @@ class Component(
"print": ["path/to/style2.css"],
}
```
"""
""" # noqa: E501
response_class = HttpResponse
"""This allows to configure what class is used to generate response from `render_to_response`"""