-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
232 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
activities/.DS_Store | ||
protocols/.DS_Store | ||
|
||
__pycache__ | ||
|
||
.idea/ | ||
|
||
node_modules | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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,9 @@ | ||
from .macros import ( | ||
schema_table, | ||
) | ||
from .main import define_env | ||
|
||
__all__ = [ | ||
"define_env", | ||
"schema_table", | ||
] |
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,93 @@ | ||
from pathlib import Path | ||
|
||
import ruamel.yaml | ||
from jinja2 import Environment, FileSystemLoader, select_autoescape | ||
|
||
yaml = ruamel.yaml.YAML() | ||
yaml.indent(mapping=2, sequence=4, offset=2) | ||
|
||
ROOT = Path(__file__).parents[1] | ||
|
||
TEMPLATES_DIR = ROOT / "templates" | ||
|
||
SCHEMA_DIR = ROOT / "linkml-schema" | ||
|
||
|
||
def return_jinja_env() -> Environment: | ||
return Environment( | ||
loader=FileSystemLoader(TEMPLATES_DIR), | ||
autoescape=select_autoescape(), | ||
lstrip_blocks=True, | ||
trim_blocks=True, | ||
) | ||
|
||
|
||
def schema_table() -> str: | ||
|
||
target_classes = [ | ||
"Protocol", | ||
"Activity", | ||
"Item", | ||
"AdditionalProperty", | ||
"OverrideProperty", | ||
"UnitOption", | ||
"ResponseOption", | ||
"Choice", | ||
"ComputeSpecification", | ||
"MessageSpecification", | ||
"AdditionalNoteObj", | ||
"ResponseActivity", | ||
"Response", | ||
"Participant", | ||
"SoftwareAgent", | ||
] | ||
|
||
input_file = SCHEMA_DIR / "reproschema.yaml" | ||
|
||
reproschema = yaml.load(input_file) | ||
|
||
env = return_jinja_env() | ||
template = env.get_template("table.jinja") | ||
|
||
content = [] | ||
for this_class in target_classes: | ||
|
||
class_dict = reproschema["classes"][this_class] | ||
class_dict["uri"] = class_dict["class_uri"].replace( | ||
"reproschema:", reproschema["id"] | ||
) | ||
|
||
slots = [] | ||
for this_slot in class_dict["slots"]: | ||
|
||
slot_dict = reproschema["slots"][this_slot] | ||
|
||
slot_dict["name"] = this_slot | ||
|
||
if "title" not in slot_dict: | ||
slot_dict["title"] = "**TODO**" | ||
if "description" not in slot_dict: | ||
slot_dict["description"] = "**TODO**" | ||
|
||
prefix = slot_dict["slot_uri"].split(":")[0] | ||
value = reproschema["id"] | ||
if prefix in reproschema["prefixes"]: | ||
value = reproschema["prefixes"][prefix] | ||
|
||
slot_dict["uri"] = slot_dict["slot_uri"].replace(f"{prefix}:", value) | ||
|
||
slots.append(slot_dict) | ||
|
||
class_dict["slots"] = slots | ||
|
||
content.append(template.render(this_class=class_dict)) | ||
|
||
return "\n".join(content) | ||
|
||
|
||
def main(): | ||
print(schema_table()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,32 @@ | ||
"""This package is used to build elements from data into | ||
MarkDown format for the specification text. | ||
Functions decorated in "define_env()" are callable throughout the | ||
specification and are run/rendered with the mkdocs plugin "macros". | ||
""" | ||
|
||
import os | ||
import sys | ||
|
||
code_path = os.path.abspath(os.path.join(os.path.dirname(__file__))) | ||
sys.path.append(code_path) | ||
|
||
import macros # noqa E402 | ||
|
||
|
||
def define_env(env): | ||
"""Define variables, macros and filters for the mkdocs-macros plugin. | ||
Parameters | ||
---------- | ||
env : :obj:`macros.plugin.MacrosPlugin` | ||
An object in which to inject macros, variables, and filters. | ||
Notes | ||
----- | ||
"variables" are the dictionary that contains the environment variables | ||
"macro" is a decorator function, to declare a macro. | ||
Macro aliases must start with "MACROS___" | ||
""" | ||
env.macro(macros.schema_table, "MACROS___schema_table") |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
rdflib==5.0.0 | ||
mkdocs-macros-plugin | ||
mkdocs-material | ||
pymdown-extensions | ||
rdflib==5.0.0 | ||
ruamel.yaml |
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,13 @@ | ||
|
||
|
||
### {{ this_class.title }} | ||
|
||
{{ this_class.description }} | ||
|
||
URI: [{{ this_class.uri }}]({{ this_class.uri }}) | ||
|
||
| Property | Title | Description | URI | | ||
| :------- | :---- | :---------- | :-- | | ||
{% for slot in this_class.slots %} | ||
| {{ slot.name }} | {{ slot.title }} | {{ slot.description }} | [{{ slot.uri }}]({{ slot.uri }}) | | ||
{% endfor %} |