mirror of
https://github.com/django-components/django-components.git
synced 2025-08-17 20:50:14 +00:00
Deployed 8cd4b03
to dev with MkDocs 1.6.1 and mike 2.1.3
This commit is contained in:
parent
e29034ce6a
commit
d31968a8e2
9 changed files with 110 additions and 121 deletions
|
@ -593,30 +593,19 @@ def _format_tag_signature(tag_spec: TagSpec) -> str:
|
|||
{% endcomponent %}
|
||||
```
|
||||
"""
|
||||
params: List[str] = [tag_spec.tag]
|
||||
|
||||
if tag_spec.positional_only_args:
|
||||
params.extend([*tag_spec.positional_only_args, "/"])
|
||||
|
||||
optional_kwargs = set(tag_spec.optional_kwargs or [])
|
||||
|
||||
params.extend([f"{name}=None" if name in optional_kwargs else name for name in tag_spec.pos_or_keyword_args or []])
|
||||
|
||||
if tag_spec.positional_args_allow_extra:
|
||||
params.append("[arg, ...]")
|
||||
|
||||
if tag_spec.keywordonly_args is True:
|
||||
params.append("**kwargs")
|
||||
elif tag_spec.keywordonly_args:
|
||||
params.extend(
|
||||
[f"{name}=None" if name in optional_kwargs else name for name in (tag_spec.keywordonly_args or [])]
|
||||
)
|
||||
# The signature returns a string like:
|
||||
# `(arg: Any, **kwargs: Any) -> None`
|
||||
params_str = str(tag_spec.signature)
|
||||
# Remove the return type annotation, the `-> None` part
|
||||
params_str = params_str.rsplit("->", 1)[0]
|
||||
# Remove brackets around the params, to end up only with `arg: Any, **kwargs: Any`
|
||||
params_str = params_str.strip()[1:-1]
|
||||
|
||||
if tag_spec.flags:
|
||||
params.extend([f"[{name}]" for name in tag_spec.flags])
|
||||
params_str += " " + " ".join([f"[{name}]" for name in tag_spec.flags])
|
||||
|
||||
# Create the function signature
|
||||
full_tag = f"{{% {' '.join(params)} %}}"
|
||||
full_tag = "{% " + tag_spec.tag + " " + params_str + " %}"
|
||||
if tag_spec.end_tag:
|
||||
full_tag += f"\n{{% {tag_spec.end_tag} %}}"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue