78 lines
2.1 KiB
Django/Jinja
78 lines
2.1 KiB
Django/Jinja
{# Rendering components recursively. #}
|
|
{# Args: #}
|
|
{# component: component dictionary #}
|
|
{# indent_width: indent width #}
|
|
{% macro render(component, indent_width=0) %}
|
|
{% filter indent(width=indent_width) %}
|
|
{%- if component is not mapping %}
|
|
{{- component }}
|
|
{%- elif component.children|length %}
|
|
{{- render_tag(component) }}
|
|
{%- else %}
|
|
{{- render_self_close_tag(component) }}
|
|
{%- endif %}
|
|
{% endfilter %}
|
|
{% endmacro %}
|
|
|
|
{# Rendering self close tag. #}
|
|
{# Args: #}
|
|
{# component: component dictionary #}
|
|
{% macro render_self_close_tag(component) %}
|
|
{%- if component.name|length %}
|
|
<{{ component.name }} {{- render_props(component.props) }}{% if component.autofocus %} ref={focusRef} {% endif %}/>
|
|
{%- else %}
|
|
{{- component.contents }}
|
|
{%- endif %}
|
|
{% endmacro %}
|
|
|
|
{# Rendering close tag with args and props. #}
|
|
{# Args: #}
|
|
{# component: component dictionary #}
|
|
{% macro render_tag(component) %}
|
|
<{{component.name}} {{- render_props(component.props) }}>
|
|
{{ component.contents }}
|
|
{% for child in component.children %}
|
|
{{ render(child) }}
|
|
{% endfor %}
|
|
</{{component.name}}>
|
|
{%- endmacro %}
|
|
|
|
|
|
{# Rendering props of a component. #}
|
|
{# Args: #}
|
|
{# component: component dictionary #}
|
|
{% macro render_props(props) %}
|
|
{% if props|length %} {{ props|join(" ") }}{% endif %}
|
|
{% endmacro %}
|
|
|
|
{# Rendering content with args. #}
|
|
{# Args: #}
|
|
{# component: component dictionary #}
|
|
{% macro render_arg_content(component) %}
|
|
{% filter indent(width=2) %}
|
|
{# no string below for a line break #}
|
|
|
|
{({ {{component.args|join(", ")}} }) => (
|
|
{% for child in component.children %}
|
|
{{ render(child) }}
|
|
{% endfor %}
|
|
)}
|
|
{% endfilter %}
|
|
{% endmacro %}
|
|
|
|
|
|
{# Get react libraries import . #}
|
|
{# Args: #}
|
|
{# module: react module dictionary #}
|
|
{% macro get_import(module)%}
|
|
{%- if module.default|length and module.rest|length -%}
|
|
import {{module.default}}, { {{module.rest|sort|join(", ")}} } from "{{module.lib}}"
|
|
{%- elif module.default|length -%}
|
|
import {{module.default}} from "{{module.lib}}"
|
|
{%- elif module.rest|length -%}
|
|
import { {{module.rest|sort|join(", ")}} } from "{{module.lib}}"
|
|
{%- else -%}
|
|
import "{{module.lib}}"
|
|
{%- endif -%}
|
|
{% endmacro %}
|