From c77a9dc10e02df26895598d974e8ddfba4bc1545 Mon Sep 17 00:00:00 2001 From: 3w36zj6 <52315048+3w36zj6@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:33:21 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9E=8B=E6=83=85=E5=A0=B1=E3=81=B8?= =?UTF-8?q?=E3=81=AE=E3=83=AA=E3=83=B3=E3=82=AF=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen.py | 69 +++++++++++++++++++++++++++++++- templates/func_template.html.j2 | 6 +-- templates/group_template.html.j2 | 2 +- templates/macros.html.j2 | 21 ++++++---- templates/type_template.html.j2 | 4 +- 5 files changed, 87 insertions(+), 15 deletions(-) diff --git a/gen.py b/gen.py index 4ee07f7c8d..15b9100f63 100644 --- a/gen.py +++ b/gen.py @@ -36,8 +36,74 @@ class PageDict(TypedDict): children: list["PageDict"] +def type2href(parameter_type: str) -> str | None: + """型名からリンクを取得する""" + foundation_set = set( + ( + "arguments", + "array", + "auto", + "bool", + "bytes", + "content", + "datetime", + "decimal", + "dictionary", + "duration", + "float", + "function", + "int", + "label", + "module", + "none", + "plugin", + "regex", + "selector", + "str", + "type", + "version", + ) + ) + layout_set = set( + ( + "alignment", + "angle", + "direction", + "fraction", + "length", + "ratio", + "relative", + ) + ) + visualize_set = set( + ( + "color", + "gradient", + "pattern", + "stroke", + ) + ) + introspection_set = set( + ( + "counter", + "location", + "state", + ) + ) + if parameter_type in foundation_set: + return f"foundations/{parameter_type}" + elif parameter_type in layout_set: + return f"layout/{parameter_type}" + elif parameter_type in visualize_set: + return f"visualize/{parameter_type}" + elif parameter_type in introspection_set: + return f"introspection/{parameter_type}" + else: + return None + + def type2class(parameter_type: str) -> str: - """関数の引数の型名からCSSのクラス名を取得する""" + """型名からCSSのクラス名を取得する""" type2class_map: dict[str, str] = { "none": "pill-kw", "auto": "pill-kw", @@ -155,6 +221,7 @@ def _render_to_file( path=path, prev=previous_page, next=next_page, + type2href=type2href, type2class=type2class, gen_path=gen_path, **page, diff --git a/templates/func_template.html.j2 b/templates/func_template.html.j2 index 623d955554..1d3b95710e 100644 --- a/templates/func_template.html.j2 +++ b/templates/func_template.html.j2 @@ -9,11 +9,11 @@

{{ macros.tooltip_display('引数', 'Parameters are the inputs to a function. They are specified in parentheses after the function name.', prefix='parameters') }}

-{{ macros.function_definition_display(body['content'], type2class, gen_path, prefix=body['content']['name']) }} +{{ macros.function_definition_display(body['content'], type2href, type2class, gen_path, prefix=body['content']['name']) }} {% if body['content']['example'] %} {{ body['content']['example'] | safe }} {% endif %} -{{ macros.function_params_display(body['content'], type2class, gen_path, prefix=body['content']['name']) }} +{{ macros.function_params_display(body['content'], type2href, type2class, gen_path, prefix=body['content']['name']) }} {% if body['content']['scope'].__len__() > 0 %} @@ -23,7 +23,7 @@ {% endif %} {% for method in body['content']['scope'] %}

{{ method['name'] }}

- {{ macros.function_display(method, type2class, gen_path, prefix='definitions-' + method['name']) }} + {{ macros.function_display(method, type2href, type2class, gen_path, prefix='definitions-' + method['name']) }} {% endfor %} {% endblock %} diff --git a/templates/group_template.html.j2 b/templates/group_template.html.j2 index ff15a4d4ec..f47869171b 100644 --- a/templates/group_template.html.j2 +++ b/templates/group_template.html.j2 @@ -8,7 +8,7 @@

Calculation

{% for method in body['content']['functions'] %}

{{ method['name'] }}

- {{ macros.function_display(method, type2class, gen_path, prefix='definitions-' + method['name'], is_example_folding=false) }} + {{ macros.function_display(method, type2href, type2class, gen_path, prefix='definitions-' + method['name'], is_example_folding=false) }} {% endfor %} {% endblock %} diff --git a/templates/macros.html.j2 b/templates/macros.html.j2 index f36d5947cd..2f068841f6 100644 --- a/templates/macros.html.j2 +++ b/templates/macros.html.j2 @@ -9,23 +9,28 @@ {% endmacro %} -{% macro function_definition_display(function, type2class, gen_path, prefix='') %} +{% macro function_definition_display(function, type2href, type2class, gen_path, prefix='') %}
{% if function['self'] %}self.{% else %}{{ gen_path(function) }}{% endif %}{{ function['name'] }}(
{% for param in function['params'] %}{% if not param['positional'] %}{{ param['name'] }}: {% endif %}{% - for t in param['types'] %}{{ t }}{% endfor %}{{',' if + for t in param['types'] %}{% set href = type2href(t) %}{% if href %}{{ t }}{% else %}{{ t }}{% endif %}{% endfor %}{{',' if function['params'].__len__() > 1 else '' }} {% endfor %}
) {% if function['returns'] %}-> {% for ret in function['returns'] - %}{{ ret }}{% endfor %}{% endif %}
+ %}{% set href = type2href(ret) %}{% if href %}{{ ret }}{% else %}{{ ret }}{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %} {% endmacro %} -{% macro function_params_display(function, type2class, gen_path, prefix='') %} +{% macro function_params_display(function, type2href, type2class, gen_path, prefix='') %} {% for param in function['params'] %}

{{ param['name'] }}
{% for t in param['types'] %} - {{ t }} + {% set href = type2href(t) %} + {% if href %} + {{ t }} + {% else %} + {{ t }} + {% endif %} {% endfor %}
{% if param['required'] %}Required{% endif %}{% if param['positional'] %} View example @@ -106,5 +111,5 @@ {% if function['example'] and not is_example_folding %} {{ function['example'] | safe }} {% endif %} -{{ function_params_display(function, type2class, gen_path, prefix) }} +{{ function_params_display(function, type2href, type2class, gen_path, prefix) }} {% endmacro %} diff --git a/templates/type_template.html.j2 b/templates/type_template.html.j2 index f122585d01..fc7f9d10c6 100644 --- a/templates/type_template.html.j2 +++ b/templates/type_template.html.j2 @@ -10,7 +10,7 @@

{{ macros.tooltip_display('コンストラクタ', 'If a type has a constructor, you can call it like a function to create a new value of the type.', prefix='constructor') }}

-{{ macros.function_display(body['content']['constructor'], type2class, gen_path, prefix='constructor', is_example_folding=false) }} +{{ macros.function_display(body['content']['constructor'], type2href, type2class, gen_path, prefix='constructor', is_example_folding=false) }} {% endif %} @@ -21,7 +21,7 @@ {% endif %} {% for method in body['content']['scope'] %}

{{ method['name'] }}

- {{ macros.function_display(method, type2class, gen_path, prefix='definitions-' + method['name']) }} + {{ macros.function_display(method, type2href, type2class, gen_path, prefix='definitions-' + method['name']) }} {% endfor %} {% endblock %}