1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
# Contributions Reference
**Contributions** are a set of static declarations that you make in the
`contributions` field of the [Plugin Manifest](./manifest). Your extension registers
**Contributions** to extend various functionalities within napari.
Here is a list of all available **Contributions**:
{# list all contributions first #}
{%- for name, contrib in contributions.items() %}
{%- if not contrib.hide_docs %}
- [`{{ name }}`](contributions-{{ name|replace('_', '-') }})
{%- endif -%}
{% endfor %}
You may add as many contributions as you'd like to a single manifest. For
clarity, the following examples include only the specific contribution that
is being discussed.
{# now, iterate through all contributions and show fields and #}
{%- for contrib_name, contrib in contributions.items() -%}
{% if not contrib.hide_docs -%}
(contributions-{{ contrib_name|replace('_', '-') }})=
## `contributions.{{contrib_name}}`
{# check if this is a single type, or a union #}
{%- if contrib['items']['anyOf'] is defined %}
{%- set type_names = contrib['items']['anyOf']|map(attribute='$ref')|map("replace", "#/definitions/", "")|list %}
{%- set union = True %}
{%- else %}
{%- set type_names = [contrib['items']['$ref']|replace("#/definitions/", "")] %}
{%- set union = False %}
{%- endif -%}
{%- if union %}
```{tip}
This contribution accepts {{ type_names|length }} schema types
```
{%- endif -%}
{%- for tname in type_names -%}
{% set type = schema['definitions'][tname] %}
{% if union %}##### {{loop.index}}. {{type.title}}{% endif %}
{{ type.description }}
{% if contrib_name|has_guide %}
See the [{{ contrib_name.title()|replace('_', ' ') }} Guide]({{ contrib_name|replace('_', '-') }}-contribution-guide)
for more details on implementing this contribution.
{% endif %}
{# Using bold instead of headers in this case to avoid right-side nav #}
**Fields**
{%- for field_name, field_props in type.properties.items() -%}
{% set required = field_name in type.required %}
- **`{{contrib_name}}.{{field_name}}`** : {% if not required %}
*(Optional: default={{ field_props.default if field_props.default is not undefined else 'None' }}).*
{% endif -%}
{{- field_props.description -}}
{% endfor -%}
{% endfor %}
### {{ contrib_name.title()|replace("_", " ") }} example
::::{tab-set}
{% for format in ['yaml', 'toml'] %}
:::{tab-item} {{format}}
```{{format}}
{{ contrib_name|example_contribution(format) }}
```
:::
{% endfor -%}
::::
{% endif %}
{% endfor %}
|