{#- A JSON document on a record page, laid out as it reads. An object or a list folds on its first line and, folded, says how much it holds. The folding is plain HTML, so it works without a script; the buttons above only fold everything at once or copy the document. Takes `outline`, from JSONField.outline, and `pretty`, the document laid out as text for copying. -#} {% import "adminsite/_icons.html" as icons %} {%- macro name(piece) -%} {%- if piece.name -%} {{ piece.name }}:  {%- endif -%} {%- endmacro -%} {%- macro part(piece, depth) -%} {%- set comma = "" if piece.last else "," -%} {%- set opening = "{" if piece.kind == "object" else "[" -%} {%- set closing = "}" if piece.kind == "object" else "]" -%} {#- Each level steps in by the width of the arrow a folding part has. -#} {%- set indent = depth * 1.25 -%} {%- if piece.children and depth == 0 -%}
{{ opening }}
{%- for child in piece.children %}{{ part(child, 1) }}{% endfor -%}
{{ closing }}{{ comma }}
{%- elif piece.children -%}
{{ icons.icon("chevron-down", 12) }} {{- name(piece) -}} {{ opening }} {{- "" -}}  … {{ closing }}{{ comma }}{{ piece.count }} {%- for child in piece.children %}{{ part(child, depth + 1) }}{% endfor -%}
{{ closing }}{{ comma }}
{%- else -%}
{{- name(piece) -}} {{ piece.text }} {{- "" -}} {{ comma }}
{%- endif -%} {%- endmacro -%}
{% if outline.children %}
{% endif %}
{%- if outline.children -%} {{ part(outline, 0) }} {%- else -%} {{ part(outline, -1) }} {%- endif -%}