Skip to content

Commit d140883

Browse files
committed
🆕 List of Traits used in classes
1 parent f6ba9f4 commit d140883

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

data/templates/vuepress/class.md.twig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
{#- Class and parent interfaces -#}
88
{% set interfaces = [] %}
9+
{#- Class and parent traits -#}
10+
{% set traits = [] %}
911

1012
{% macro getRecursiveInterfaces(targetClass) %}
1113
{%- import _self as self -%}
@@ -20,14 +22,36 @@
2022
{%- endif -%}
2123
{% endmacro %}
2224

25+
{% macro getRecursiveTraits(targetClass, includeTraitsInTraits) %}
26+
{%- import _self as self -%}
27+
28+
{%- if targetClass -%}
29+
{{- targetClass.usedTraits|join(',') -}},
30+
31+
{{- self.getRecursiveTraits(targetClass.parent, includeTraitsInTraits) -}}
32+
33+
{%- if includeTraitsInTraits -%}
34+
{%- for trait in targetClass.usedTraits -%}
35+
{{- self.getRecursiveTraits(trait, includeTraitsInTraits) -}}
36+
{%- endfor -%}
37+
{%- endif -%}
38+
39+
{%- endif -%}
40+
{% endmacro %}
41+
2342
{% import _self as self %}
2443
{% set interfacesText = self.getRecursiveInterfaces(class) %}
44+
{% set traitsText = self.getRecursiveTraits(class, false) %}
2545

2646
{#- Convert to array, sort and remove duplicates -#}
2747
{% for name in interfacesText|trim(', ')|split(',')|sort %}
2848
{%- set interfaces = interfaces|merge({ (name): (name|split('\\')|last) }) -%}
2949
{% endfor %}
3050

51+
{% for name in traitsText|trim(', ')|split(',')|sort %}
52+
{%- set traits = traits|merge({ (name): (name|split('\\')|last) }) -%}
53+
{% endfor %}
54+
3155
| Name | {{ class.name }} |
3256
| ----:|:---------------- |
3357
{% if class.parent %}
@@ -41,6 +65,12 @@
4165
[{{ iname|trim('\\')|split('\\')|slice(0, -1)|join('\\') }}\\<span style="font-weight: bold;">{{ ishort }}</span>](/api/interfaces.html#{{ iname|lower|replace('\\', '-') }}) {{- '<br />' -}}
4266
{% endfor %}
4367

68+
{% for tName, tShort in traits if tShort is not empty %}
69+
{% if loop.first -%}
70+
**Uses** |
71+
{%- endif -%}
72+
[{{ tName|trim('\\')|split('\\')|slice(0, -1)|join('\\') }}\\<span style="font-weight: bold;">{{ tShort }}</span>](/api/traits.html#{{ tShort|lower|replace('\\', '-') }}) {{- '<br />' -}}
73+
{% endfor %}
4474

4575
{% for author in class.tags.author %}
4676
{% if loop.first %}- **Authors:**{% endif %}

0 commit comments

Comments
 (0)