mirror of
https://github.com/django-components/django-components.git
synced 2025-12-03 20:00:02 +00:00
refactor: Update docs and tests to use get_template_data() (#1161)
* refactor: update docs and tests to use get_template_data() * refactor: fix linting * docs: add note about difference between the two methods
This commit is contained in:
parent
c69980493d
commit
28b61c1609
69 changed files with 795 additions and 725 deletions
|
|
@ -116,8 +116,8 @@ def with_component_cls(on_created: Callable):
|
|||
class TempComponent(Component):
|
||||
template = "Hello {{ name }}!"
|
||||
|
||||
def get_context_data(self, name="World"):
|
||||
return {"name": name}
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {"name": kwargs.get("name", "World")}
|
||||
|
||||
on_created()
|
||||
|
||||
|
|
@ -143,8 +143,8 @@ class TestExtension:
|
|||
class TestAccessComp(Component):
|
||||
template = "Hello {{ name }}!"
|
||||
|
||||
def get_context_data(self, arg1, arg2, name="World"):
|
||||
return {"name": name}
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {"name": kwargs.get("name", "World")}
|
||||
|
||||
ext_class = TestAccessComp.TestExtension # type: ignore[attr-defined]
|
||||
assert issubclass(ext_class, ComponentExtension.ExtensionClass)
|
||||
|
|
@ -240,8 +240,8 @@ class TestExtensionHooks:
|
|||
class TestComponent(Component):
|
||||
template = "Hello {{ name }}!"
|
||||
|
||||
def get_context_data(self, name="World"):
|
||||
return {"name": name}
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {"name": kwargs.get("name", "World")}
|
||||
|
||||
registry.register("test_comp", TestComponent)
|
||||
extension = cast(DummyExtension, app_settings.EXTENSIONS[3])
|
||||
|
|
@ -268,13 +268,13 @@ class TestExtensionHooks:
|
|||
class TestComponent(Component):
|
||||
template = "Hello {{ name }}!"
|
||||
|
||||
def get_context_data(self, arg1, arg2, name="World"):
|
||||
return {"name": name}
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {"name": kwargs.get("name", "World")}
|
||||
|
||||
def get_js_data(self, *args, **kwargs):
|
||||
def get_js_data(self, args, kwargs, slots, context):
|
||||
return {"script": "console.log('Hello!')"}
|
||||
|
||||
def get_css_data(self, *args, **kwargs):
|
||||
def get_css_data(self, args, kwargs, slots, context):
|
||||
return {"style": "body { color: blue; }"}
|
||||
|
||||
# Render the component with some args and kwargs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue