|
1 |
| -{%- set original_expression = expression -%} |
2 |
| -{%- if original_expression is iterable and original_expression is not string -%} |
3 |
| - {%- for expression in original_expression -%} |
4 |
| - {%- include "expression.html" with context -%} |
5 |
| - {%- endfor -%} |
6 |
| -{%- elif original_expression is string -%} |
7 |
| - {{ original_expression }} |
8 |
| -{%- else -%} |
9 |
| - {%- with annotation = original_expression|attr(config.annotations_path) -%} |
10 |
| - {%- filter stash_crossref(length=annotation|length) -%} |
11 |
| - <span data-autorefs-optional{% if annotation != original_expression.full %}-hover{% endif %}="{{ original_expression.full }}">{{ annotation }}</span> |
12 |
| - {%- endfilter -%} |
| 1 | +{%- macro crossref(name, annotation_path) -%} |
| 2 | + {%- with full = name.canonical_path -%} |
| 3 | + {%- if annotation_path == "brief" -%} |
| 4 | + {%- set annotation = name.canonical_name -%} |
| 5 | + {%- elif annotation_path == "source" -%} |
| 6 | + {%- set annotation = name.name -%} |
| 7 | + {%- elif annotation_path == "full" -%} |
| 8 | + {%- set annotation = full -%} |
| 9 | + {%- endif -%} |
| 10 | + {%- for title, path in annotation|split_path(full) -%} |
| 11 | + {%- filter stash_crossref(length=title|length) -%} |
| 12 | + <span data-autorefs-optional{% if title != path %}-hover{% endif %}="{{ path }}">{{ title }}</span> |
| 13 | + {%- endfilter -%} |
| 14 | + {%- if not loop.last -%}.{%- endif -%} |
| 15 | + {%- endfor -%} |
13 | 16 | {%- endwith -%}
|
14 |
| -{%- endif -%} |
| 17 | +{%- endmacro -%} |
| 18 | + |
| 19 | +{%- macro render(expression, annotations_path) -%} |
| 20 | + {%- if expression is string -%} |
| 21 | + {%- if signature -%}{{ expression|safe }}{%- else -%}{{ expression }}{%- endif -%} |
| 22 | + {%- elif expression.classname == "ExprName" -%} |
| 23 | + {{ crossref(expression, annotations_path) }} |
| 24 | + {%- elif expression.classname == "ExprAttribute" -%} |
| 25 | + {%- if annotations_path == "brief" -%} |
| 26 | + {{ render(expression.last, "brief") }} |
| 27 | + {%- elif annotations_path == "full" -%} |
| 28 | + {{ render(expression.first, "full") }} |
| 29 | + {%- for element in expression -%} |
| 30 | + {%- if not loop.first -%} |
| 31 | + {{ render(element, "brief") }} |
| 32 | + {%- endif -%} |
| 33 | + {%- endfor -%} |
| 34 | + {%- else -%} |
| 35 | + {%- for element in expression -%} |
| 36 | + {{ render(element, annotations_path) }} |
| 37 | + {%- endfor -%} |
| 38 | + {%- endif -%} |
| 39 | + {%- else -%} |
| 40 | + {%- for element in expression -%} |
| 41 | + {{ render(element, annotations_path) }} |
| 42 | + {%- endfor -%} |
| 43 | + {%- endif -%} |
| 44 | +{%- endmacro -%} |
| 45 | + |
| 46 | +{{ render(expression, config.annotations_path) }} |
0 commit comments