Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions templates/func_template.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<h2 id="parameters">
{{ macros.tooltip_display('引数', 'Parameters are the inputs to a function. They are specified in parentheses after the function name.', prefix='parameters') }}
</h2>
{{ 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 %}
Expand All @@ -23,7 +23,7 @@
{% endif %}
{% for method in body['content']['scope'] %}
<h3 id="{{ prefix }}-{{ method['name'] }}" class="method-head"><span><code>{{ method['name'] }}</code></span></h3>
{{ 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 %}
2 changes: 1 addition & 1 deletion templates/group_template.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h2 id="functions">Calculation</h2>
{% for method in body['content']['functions'] %}
<h3 id="{{ prefix }}-{{ method['name'] }}" class="method-head"><span><code>{{ method['name'] }}</code></span></h3>
{{ 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 %}
21 changes: 13 additions & 8 deletions templates/macros.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@
</div>
{% endmacro %}

{% macro function_definition_display(function, type2class, gen_path, prefix='') %}
{% macro function_definition_display(function, type2href, type2class, gen_path, prefix='') %}
<div class="code code-definition {{ 'single-arg' if function['params'].__len__() <= 1 else '' }}">{% if function['self'] %}self.{% else %}{{ gen_path(function) }}{% endif %}<span
class="typ-func">{{ function['name'] }}</span>(<div class="arguments">{% for param in function['params'] %}<span
class="overview-param">{% if not param['positional'] %}<a href="#parameters-{{ param['name'] }}">{{ param['name']
}}<!-- -->: </a>{% endif %}{%
for t in param['types'] %}<a href="/docs/reference/types/{{ t }}" class="pill {{ type2class(t) }}">{{ t }}</a>{% endfor %}{{',' if
for t in param['types'] %}{% set href = type2href(t) %}{% if href %}<a href="/docs/reference/{{ type2href(t) }}" class="pill {{ type2class(t) }}">{{ t }}</a>{% else %}<span class="pill {{ type2class(t) }}">{{ t }}</span>{% endif %}{% endfor %}{{',' if
function['params'].__len__() > 1 else '' }} </span>{% endfor %}</div>) {% if function['returns'] %}<!-- -->-&gt; {% for ret in function['returns']
%}<a href="/docs/reference/types/{{ ret }}" class="pill {{ type2class(ret) }}">{{ ret }}</a>{% endfor %}{% endif %}</div>
%}{% set href = type2href(ret) %}{% if href %}<a href="/docs/reference/{{ type2href(ret) }}" class="pill {{ type2class(ret) }}">{{ ret }}</a>{% else %}<span class="pill {{ type2class(ret) }}">{{ ret }}</span>{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}</div>
{% 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'] %}
<h4 id="{{ prefix }}-{{ function['name'] }}-parameters-{{ param['name'] }}"><code>{{ param['name'] }}</code>
<div class="additional-info">
<div>
{% for t in param['types'] %}
<a href="/docs/reference/types/{{ t }}" class="pill {{ type2class(t) }}">{{ t }}</a>
{% set href = type2href(t) %}
{% if href %}
<a href="/docs/reference/{{ href }}" class="pill {{ type2class(t) }}">{{ t }}</a>
{% else %}
<span class="pill {{ type2class(t) }}">{{ t }}</span>
{% endif %}
{% endfor %}
</div>
{% if param['required'] %}<small>Required</small>{% endif %}{% if param['positional'] %}<small><span
Expand Down Expand Up @@ -92,9 +97,9 @@
{% endfor %}
{% endmacro %}

{% macro function_display(function, type2class, gen_path, prefix='', is_example_folding=true) %}
{% macro function_display(function, type2href, type2class, gen_path, prefix='', is_example_folding=true) %}
{{ function['details'] | safe }}
{{ function_definition_display(function, type2class, gen_path, prefix) }}
{{ function_definition_display(function, type2href, type2class, gen_path, prefix) }}
{% if function['example'] and is_example_folding %}
<details class="folding-example">
<summary><img src="/assets/icons/16-arrow-right.svg" alt="" width="16" height="16">View example</summary>
Expand All @@ -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 %}
4 changes: 2 additions & 2 deletions templates/type_template.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h2 id="constructor">
{{ 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') }}
</h2>
{{ 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 %}


Expand All @@ -21,7 +21,7 @@
{% endif %}
{% for method in body['content']['scope'] %}
<h3 id="{{ prefix }}-{{ method['name'] }}" class="method-head"><span><code>{{ method['name'] }}</code></span></h3>
{{ 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 %}