mirror of
https://github.com/django-components/django-components.git
synced 2025-08-30 10:47:20 +00:00
refactor: deprecate Component.input and add raw_args, raw_kwargs, raw_slots (#1233)
* refactor: deprecate Component.input and add raw_args, raw_kwargs, raw_slots * docs: update changelog
This commit is contained in:
parent
eceebb9696
commit
04f79a6e6b
15 changed files with 295 additions and 101 deletions
|
@ -252,6 +252,47 @@ class TestComponentLegacyApi:
|
|||
template_2 = _get_component_template(comp)
|
||||
assert template_2._test_id == "123" # type: ignore[union-attr]
|
||||
|
||||
# TODO_v1 - Remove
|
||||
def test_input(self):
|
||||
class TestComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
Variable: <strong>{{ variable }}</strong>
|
||||
{% slot 'my_slot' / %}
|
||||
"""
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
assert self.input.args == [123, "str"]
|
||||
assert self.input.kwargs == {"variable": "test", "another": 1}
|
||||
assert isinstance(self.input.context, Context)
|
||||
assert list(self.input.slots.keys()) == ["my_slot"]
|
||||
my_slot = self.input.slots["my_slot"]
|
||||
assert my_slot() == "MY_SLOT"
|
||||
|
||||
return {
|
||||
"variable": kwargs["variable"],
|
||||
}
|
||||
|
||||
def on_render_before(self, context, template):
|
||||
assert self.input.args == [123, "str"]
|
||||
assert self.input.kwargs == {"variable": "test", "another": 1}
|
||||
assert isinstance(self.input.context, Context)
|
||||
assert list(self.input.slots.keys()) == ["my_slot"]
|
||||
my_slot = self.input.slots["my_slot"]
|
||||
assert my_slot() == "MY_SLOT"
|
||||
|
||||
rendered = TestComponent.render(
|
||||
kwargs={"variable": "test", "another": 1},
|
||||
args=(123, "str"),
|
||||
slots={"my_slot": "MY_SLOT"},
|
||||
)
|
||||
|
||||
assertHTMLEqual(
|
||||
rendered,
|
||||
"""
|
||||
Variable: <strong data-djc-id-ca1bc3e>test</strong> MY_SLOT
|
||||
""",
|
||||
)
|
||||
|
||||
@djc_test
|
||||
class TestComponent:
|
||||
|
@ -477,7 +518,7 @@ class TestComponentRenderAPI:
|
|||
rendered = SimpleComponent.render()
|
||||
assert rendered == "render_id: ca1bc3e"
|
||||
|
||||
def test_input(self):
|
||||
def test_raw_input(self):
|
||||
class TestComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
|
@ -486,11 +527,11 @@ class TestComponentRenderAPI:
|
|||
"""
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
assert self.input.args == [123, "str"]
|
||||
assert self.input.kwargs == {"variable": "test", "another": 1}
|
||||
assert isinstance(self.input.context, Context)
|
||||
assert list(self.input.slots.keys()) == ["my_slot"]
|
||||
my_slot = self.input.slots["my_slot"]
|
||||
assert self.raw_args == [123, "str"]
|
||||
assert self.raw_kwargs == {"variable": "test", "another": 1}
|
||||
assert isinstance(self.context, Context)
|
||||
assert list(self.raw_slots.keys()) == ["my_slot"]
|
||||
my_slot = self.raw_slots["my_slot"]
|
||||
assert my_slot() == "MY_SLOT"
|
||||
|
||||
return {
|
||||
|
@ -498,11 +539,11 @@ class TestComponentRenderAPI:
|
|||
}
|
||||
|
||||
def on_render_before(self, context, template):
|
||||
assert self.input.args == [123, "str"]
|
||||
assert self.input.kwargs == {"variable": "test", "another": 1}
|
||||
assert isinstance(self.input.context, Context)
|
||||
assert list(self.input.slots.keys()) == ["my_slot"]
|
||||
my_slot = self.input.slots["my_slot"]
|
||||
assert self.raw_args == [123, "str"]
|
||||
assert self.raw_kwargs == {"variable": "test", "another": 1}
|
||||
assert isinstance(self.context, Context)
|
||||
assert list(self.raw_slots.keys()) == ["my_slot"]
|
||||
my_slot = self.raw_slots["my_slot"]
|
||||
assert my_slot() == "MY_SLOT"
|
||||
|
||||
rendered = TestComponent.render(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue