mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 23:49:07 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
5f07f3d4da
commit
a5a0c74d31
4 changed files with 7 additions and 8 deletions
|
@ -202,6 +202,7 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
|
||||||
|
|
||||||
class Media:
|
class Media:
|
||||||
"""Defines JS and CSS media files associated with this component."""
|
"""Defines JS and CSS media files associated with this component."""
|
||||||
|
|
||||||
css: Optional[Union[str, List[str], Dict[str, str], Dict[str, List[str]]]] = None
|
css: Optional[Union[str, List[str], Dict[str, str], Dict[str, List[str]]]] = None
|
||||||
js: Optional[Union[str, List[str]]] = None
|
js: Optional[Union[str, List[str]]] = None
|
||||||
|
|
||||||
|
@ -492,14 +493,13 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
|
||||||
) -> Dict[SlotName, FillContent]:
|
) -> Dict[SlotName, FillContent]:
|
||||||
"""Fill component slots outside of template rendering."""
|
"""Fill component slots outside of template rendering."""
|
||||||
slot_fills = {}
|
slot_fills = {}
|
||||||
for (slot_name, content) in slots_data.items():
|
for slot_name, content in slots_data.items():
|
||||||
if isinstance(content, (str, SafeString)):
|
if isinstance(content, (str, SafeString)):
|
||||||
content_func = nodelist_to_render_func(
|
content_func = nodelist_to_render_func(
|
||||||
NodeList([
|
NodeList([TextNode(escape(content) if escape_content else content)])
|
||||||
TextNode(escape(content) if escape_content else content)
|
|
||||||
])
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def content_func(ctx: Context) -> RenderedContent:
|
def content_func(ctx: Context) -> RenderedContent:
|
||||||
rendered = content(ctx)
|
rendered = content(ctx)
|
||||||
return escape(rendered) if escape_content else rendered
|
return escape(rendered) if escape_content else rendered
|
||||||
|
|
|
@ -13,6 +13,7 @@ RenderFunc = Callable[[Context], RenderedContent]
|
||||||
def nodelist_to_render_func(nodelist: NodeList) -> RenderFunc:
|
def nodelist_to_render_func(nodelist: NodeList) -> RenderFunc:
|
||||||
def render_func(ctx: Context) -> RenderedContent:
|
def render_func(ctx: Context) -> RenderedContent:
|
||||||
return nodelist.render(ctx)
|
return nodelist.render(ctx)
|
||||||
|
|
||||||
return render_func
|
return render_func
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ Tests focusing on the Component class.
|
||||||
For tests focusing on the `component` tag, see `test_templatetags_component.py`
|
For tests focusing on the `component` tag, see `test_templatetags_component.py`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
from django.http import HttpResponse
|
||||||
from django.template import Context, Template, TemplateSyntaxError
|
from django.template import Context, Template, TemplateSyntaxError
|
||||||
|
|
||||||
# isort: off
|
# isort: off
|
||||||
|
|
|
@ -141,9 +141,7 @@ class InlineComponentTest(BaseTestCase):
|
||||||
"var2": var2,
|
"var2": var2,
|
||||||
}
|
}
|
||||||
|
|
||||||
rendered = FilteredComponent.render(
|
rendered = FilteredComponent.render(kwargs={"var1": "test1", "var2": "test2"})
|
||||||
kwargs={"var1": "test1", "var2": "test2"}
|
|
||||||
)
|
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
rendered,
|
rendered,
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue