-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to customize documentation pages using jinja templates (#333
) Resolves #332 This PR added in the relevant/necessary base jinja templates (as is) from the linkml library: https://github.com/linkml/linkml/tree/main/linkml/generators/docgen in a folder called `src/doc-templates`. Now the jinja templates can be edited here, in order to customize the class/slot/index, etc. documentation pages to look like how we want them to look. The downstream makefile target which uses linkml `gen-doc` is `make gendoc` and that has been updated too. - [ ] `docs/` have been added/updated if necessary - [x] `make test` has been run locally - [ ] tests have been added/updated (if applicable) - [ ] [CHANGELOG.md](https://github.com/mapping-commons/sssom/blob/master/CHANGELOG.md) has been updated.
- Loading branch information
1 parent
54dbd4c
commit e5c723a
Showing
6 changed files
with
420 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# Class: {{ gen.name(element) }} | ||
|
||
{%- if header -%} | ||
{{header}} | ||
{%- endif -%} | ||
|
||
|
||
{% if element.description %} | ||
{% set element_description_lines = element.description.split('\n') %} | ||
{% for element_description_line in element_description_lines %} | ||
_{{ element_description_line }}_ | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% if element.abstract %} | ||
* __NOTE__: this is an abstract class and should not be instantiated directly | ||
{% endif %} | ||
|
||
URI: {{ gen.uri_link(element) }} | ||
|
||
|
||
{% if diagram_type == "er_diagram" %} | ||
```{{ gen.mermaid_directive() }} | ||
{{ gen.mermaid_diagram([element.name]) }} | ||
``` | ||
{% else %} | ||
{% include "class_diagram.md.jinja2" %} | ||
{% endif %} | ||
|
||
{% if schemaview.class_parents(element.name) or schemaview.class_children(element.name, mixins=False) %} | ||
|
||
## Inheritance | ||
{{ gen.inheritance_tree(element, mixins=True) }} | ||
{% else %} | ||
<!-- no inheritance hierarchy --> | ||
{% endif %} | ||
|
||
## Slots | ||
|
||
| Name | Cardinality and Range | Description | Inheritance | | ||
| --- | --- | --- | --- | | ||
{% if gen.get_direct_slots(element)|length > 0 %} | ||
{%- for slot in gen.get_direct_slots(element) -%} | ||
| {{ gen.link(slot) }} | {{ gen.cardinality(slot) }} <br/> {{ gen.link(slot.range) }} | {{ slot.description|enshorten }} | direct | | ||
{% endfor -%} | ||
{% endif -%} | ||
{% if gen.get_indirect_slots(element)|length > 0 %} | ||
{%- for slot in gen.get_indirect_slots(element) -%} | ||
| {{ gen.link(slot) }} | {{ gen.cardinality(slot) }} <br/> {{ gen.link(slot.range) }} | {{ slot.description|enshorten }} | {{ gen.links(gen.get_slot_inherited_from(element.name, slot.name))|join(', ') }} | | ||
{% endfor -%} | ||
{% endif %} | ||
|
||
{% if schemaview.is_mixin(element.name) %} | ||
## Mixin Usage | ||
|
||
| mixed into | description | | ||
| --- | --- | | ||
{% for c in schemaview.class_children(element.name, is_a=False) -%} | ||
| {{ gen.link(c) }} | {{ schemaview.get_class(c).description|enshorten }} | | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% if schemaview.usage_index().get(element.name) %} | ||
## Usages | ||
|
||
| used by | used in | type | used | | ||
| --- | --- | --- | --- | | ||
{% for usage in schemaview.usage_index().get(element.name) -%} | ||
| {{gen.link(usage.used_by)}} | {{gen.link(usage.slot)}} | {{usage.metaslot}} | {{ gen.link(usage.used) }} | | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% include "common_metadata.md.jinja2" %} | ||
|
||
|
||
{% if schemaview.get_mappings(element.name).items() -%} | ||
## Mappings | ||
|
||
| Mapping Type | Mapped Value | | ||
| --- | --- | | ||
{% for m, mt in schemaview.get_mappings(element.name).items() -%} | ||
{% if mt|length > 0 -%} | ||
| {{ m }} | {{ mt|join(', ') }} | | ||
{% endif -%} | ||
{% endfor %} | ||
|
||
{% endif -%} | ||
|
||
{% if gen.example_object_blobs(element.name) -%} | ||
## Examples | ||
{% for name, blob in gen.example_object_blobs(element.name) -%} | ||
### Example: {{name}} | ||
|
||
```yaml | ||
{{ blob }} | ||
``` | ||
{% endfor %} | ||
{% endif %} | ||
|
||
|
||
## LinkML Source | ||
|
||
<!-- TODO: investigate https://stackoverflow.com/questions/37606292/how-to-create-tabbed-code-blocks-in-mkdocs-or-sphinx --> | ||
|
||
### Direct | ||
|
||
<details> | ||
```yaml | ||
{{gen.yaml(element)}} | ||
``` | ||
</details> | ||
|
||
### Induced | ||
|
||
<details> | ||
```yaml | ||
{{gen.yaml(element, inferred=True)}} | ||
``` | ||
</details> | ||
|
||
{%- if footer -%} | ||
{{footer}} | ||
{%- endif -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{% if schemaview.class_parents(element.name) and schemaview.class_children(element.name) %} | ||
```{{ gen.mermaid_directive() }} | ||
classDiagram | ||
class {{ gen.name(element) }} | ||
{% for s in schemaview.class_parents(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(schemaview.get_element(s)) }} <|-- {{ gen.name(element) }} | ||
{% endfor %} | ||
|
||
{% for s in schemaview.class_children(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(element) }} <|-- {{ gen.name(schemaview.get_element(s)) }} | ||
{% endfor %} | ||
|
||
{% for s in schemaview.class_induced_slots(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(element) }} : {{gen.name(s)}} | ||
{% if s.range not in gen.all_type_object_names() %} | ||
{{ gen.name(element) }} --|> {{ s.range }} : {{ gen.name(s) }} | ||
{% endif %} | ||
{% endfor %} | ||
``` | ||
{% elif schemaview.class_parents(element.name) %} | ||
```{{ gen.mermaid_directive() }} | ||
classDiagram | ||
class {{ gen.name(element) }} | ||
{% for s in schemaview.class_parents(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(schemaview.get_element(s)) }} <|-- {{ gen.name(element) }} | ||
{% endfor %} | ||
{% for s in schemaview.class_induced_slots(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(element) }} : {{gen.name(s)}} | ||
{% if s.range not in gen.all_type_object_names() %} | ||
{{ gen.name(element) }} --|> {{ s.range }} : {{ gen.name(s) }} | ||
{% endif %} | ||
{% endfor %} | ||
``` | ||
{% elif schemaview.class_children(element.name) %} | ||
```{{ gen.mermaid_directive() }} | ||
classDiagram | ||
class {{ gen.name(element) }} | ||
{% for s in schemaview.class_children(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(element) }} <|-- {{ gen.name(schemaview.get_element(s)) }} | ||
{% endfor %} | ||
{% for s in schemaview.class_induced_slots(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(element) }} : {{gen.name(s)}} | ||
{% if s.range not in gen.all_type_object_names() %} | ||
{{ gen.name(element) }} --|> {{ s.range }} : {{ gen.name(s) }} | ||
{% endif %} | ||
{% endfor %} | ||
``` | ||
{% else %} | ||
```{{ gen.mermaid_directive() }} | ||
classDiagram | ||
class {{ gen.name(element) }} | ||
{% for s in schemaview.class_induced_slots(element.name)|sort(attribute='name') -%} | ||
{{ gen.name(element) }} : {{gen.name(s)}} | ||
{% if s.range not in gen.all_type_object_names() %} | ||
{{ gen.name(element) }} --|> {{ s.range }} : {{ gen.name(s) }} | ||
{% endif %} | ||
{% endfor %} | ||
``` | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{% if element.aliases %} | ||
## Aliases | ||
|
||
{% for alias in element.aliases %} | ||
* {{ alias }} | ||
{%- endfor %} | ||
{% endif %} | ||
|
||
|
||
{% if element.examples %} | ||
## Examples | ||
|
||
| Value | | ||
| --- | | ||
{% for x in element.examples -%} | ||
| {{ x.value }} | | ||
{% endfor %} | ||
{% endif -%} | ||
|
||
{% if element.comments -%} | ||
## Comments | ||
|
||
{% for x in element.comments -%} | ||
* {{x}} | ||
{% endfor %} | ||
{% endif -%} | ||
|
||
{% if element.todos -%} | ||
## TODOs | ||
|
||
{% for x in element.todos -%} | ||
* {{x}} | ||
{% endfor %} | ||
{% endif -%} | ||
|
||
{% if element.see_also -%} | ||
## See Also | ||
|
||
{% for x in element.see_also -%} | ||
* {{ gen.uri_link(x) }} | ||
{% endfor %} | ||
{% endif -%} | ||
|
||
## Identifier and Mapping Information | ||
|
||
{% if element.id_prefixes %} | ||
### Valid ID Prefixes | ||
|
||
Instances of this class *should* have identifiers with one of the following prefixes: | ||
{% for p in element.id_prefixes %} | ||
* {{p}} | ||
{% endfor %} | ||
|
||
{% endif %} | ||
|
||
|
||
{% if element.annotations %} | ||
### Annotations | ||
|
||
| property | value | | ||
| --- | --- | | ||
{% for a in element.annotations -%} | ||
{%- if a|string|first != '_' -%} | ||
| {{ a }} | {{ element.annotations[a].value }} | | ||
{%- endif -%} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% if element.from_schema or element.imported_from %} | ||
### Schema Source | ||
|
||
{% if element.from_schema %} | ||
* from schema: {{ element.from_schema }} | ||
{% endif %} | ||
{% if element.imported_from %} | ||
* imported from: {{ element.imported_from }} | ||
{% endif %} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# {% if schema.title %}{{ schema.title }}{% else %}{{ schema.name }}{% endif %} | ||
|
||
{% if schema.description %}{{ schema.description }}{% endif %} | ||
|
||
URI: {{ schema.id }} | ||
|
||
Name: {{ schema.name }} | ||
|
||
{% if include_top_level_diagram %} | ||
|
||
## Schema Diagram | ||
|
||
```{{ gen.mermaid_directive() }} | ||
{{ gen.mermaid_diagram() }} | ||
``` | ||
{% endif %} | ||
|
||
## Classes | ||
|
||
| Class | Description | | ||
| --- | --- | | ||
{% if gen.hierarchical_class_view -%} | ||
{% for u, v in gen.class_hierarchy_as_tuples() -%} | ||
| {{ " "|safe*u*8 }}{{ gen.link(schemaview.get_class(v)) }} | {{ schemaview.get_class(v).description }} | | ||
{% endfor %} | ||
{% else -%} | ||
{% for c in gen.all_class_objects()|sort(attribute=sort_by) -%} | ||
| {{gen.link(c)}} | {{c.description|enshorten}} | | ||
{% endfor %} | ||
{% endif %} | ||
|
||
## Slots | ||
|
||
| Slot | Description | | ||
| --- | --- | | ||
{% for s in gen.all_slot_objects()|sort(attribute=sort_by) -%} | ||
| {{gen.link(s)}} | {{s.description|enshorten}} | | ||
{% endfor %} | ||
|
||
## Enumerations | ||
|
||
| Enumeration | Description | | ||
| --- | --- | | ||
{% for e in gen.all_enum_objects()|sort(attribute=sort_by) -%} | ||
| {{gen.link(e)}} | {{e.description|enshorten}} | | ||
{% endfor %} | ||
|
||
## Types | ||
|
||
| Type | Description | | ||
| --- | --- | | ||
{% for t in gen.all_type_objects()|sort(attribute=sort_by) -%} | ||
| {{gen.link(t)}} | {{t.description|enshorten}} | | ||
{% endfor %} | ||
|
||
## Subsets | ||
|
||
| Subset | Description | | ||
| --- | --- | | ||
{% for ss in schemaview.all_subsets().values()|sort(attribute='name') -%} | ||
| {{gen.link(ss)}} | {{ss.description|enshorten}} | | ||
{% endfor %} |
Oops, something went wrong.