Skip to content

Commit

Permalink
Merge pull request #5 from ClemensLinnhoff/106-material-param-docu
Browse files Browse the repository at this point in the history
Add general material parameters
  • Loading branch information
ClemensLinnhoff authored Sep 12, 2024
2 parents 19f6ee5 + f942d5e commit fca6074
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .antora/modules/specification/nav_openmaterial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
** xref:material/Introduction.adoc[]
** xref:material/Fileformat.adoc[]
** xref:material/Metadata.adoc[]
** xref:material/Material-parameters.adoc[]
** xref:material/material-properties-index.adoc[]
9 changes: 5 additions & 4 deletions .github/workflows/antora-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ jobs:

- name: Generate AsciiDoc from JSON
working-directory: scripts
run: python3 json2asciidoc.py ../schemas/asset_schema.json metadata

- name: Copy generated AsciiDoc
run: cp scripts/metadata.adoc content/geometry/metadata.adoc
run: |
python3 json2asciidoc.py ../schemas/asset_schema.json metadata
mv metadata.adoc ../content/geometry/
python3 json2asciidoc.py ../schemas/material_schema.json material_properties
mv material_properties.adoc ../content/material/material-properties.adoc
- name: Configure Pages
uses: actions/configure-pages@v4
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# IDE specific files
.vscode/
.idea/
.idea/

# Autogenerated files
content/material/material-properties.adoc
1 change: 0 additions & 1 deletion content/material/Material-parameters.adoc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
include::Introduction.adoc[leveloffset=+1]
include::Fileformat.adoc[leveloffset=+1]
include::Metadata.adoc[leveloffset=+1]
include::Material-parameters.adoc[leveloffset=+1]
include::material-properties-index.adoc[leveloffset=+1]
5 changes: 5 additions & 0 deletions content/material/material-properties-index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
= Material properties

include::material-properties.adoc[leveloffset=+1]

== Lookup tables
2 changes: 1 addition & 1 deletion examples/example_material.xomp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "aluminum",
"description": "aluminum material"
},
"materials_properties": {
"material_properties": {
"surface_roughness": {
"surface_height_rms": 0.8,
"surface_correlation_length": 1.0
Expand Down
2 changes: 1 addition & 1 deletion schemas/material_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"description"
]
},
"materials_properties": {
"material_properties": {
"type": "object",
"description": "Properties related to the material.",
"properties": {
Expand Down
55 changes: 39 additions & 16 deletions scripts/json2asciidoc.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
import json
import argparse


def escape_special_chars(pattern):
"""
Escape special characters in the pattern string for AsciiDoc compatibility.
Args:
pattern (str): The pattern string to be escaped.
Returns:
str: The escaped pattern string.
"""
pattern = pattern.replace("\\", "\\\\") # Escape backslashes
pattern = pattern.replace("{", "\\{").replace("}", "\\}") # Escape curly braces
return pattern


def generate_asciidoc(field_name, schema, required_fields):
def generate_asciidoc_properties(properties, required_fields, level=2):
"""
Generate AsciiDoc content for the specified field based on the JSON schema.
Recursively generate AsciiDoc content for a dictionary of properties.
Args:
field_name (str): The name of the field to generate documentation for.
schema (dict): The JSON schema dictionary.
required_fields (list): List of required fields for the specified field.
properties (dict): The dictionary of properties from the JSON schema.
required_fields (list): The list of required fields.
level (int): The current heading level in the AsciiDoc file.
Returns:
str: The generated AsciiDoc content.
str: The generated AsciiDoc content for the properties.
"""
asciidoc_content = f"= {field_name.capitalize()}\n\n"
field_data = schema['properties'][field_name]
asciidoc_content += field_data.get("description", "") + "\n\n"
asciidoc_content = ""

for prop_name, prop_data in field_data['properties'].items():
asciidoc_content += f"== {prop_name}\n"
for prop_name, prop_data in properties.items():
heading_prefix = "=" * level # Create heading based on level
asciidoc_content += f"{heading_prefix} {prop_name}\n"
asciidoc_content += f"{prop_data.get('description', 'No description')}\n"

# Add pattern inline and handle escaping of backslashes and curly braces
Expand All @@ -49,9 +46,36 @@ def generate_asciidoc(field_name, schema, required_fields):
asciidoc_content += "\n*Required:* No\n"

asciidoc_content += "\n"

# If there are nested properties, recursively generate content for them
if "properties" in prop_data:
nested_required_fields = prop_data.get('required', [])
asciidoc_content += generate_asciidoc_properties(
prop_data['properties'], nested_required_fields, level + 1
)

return asciidoc_content

def generate_asciidoc(field_name, schema, required_fields):
"""
Generate AsciiDoc content for the specified field based on the JSON schema.
Args:
field_name (str): The name of the field to generate documentation for.
schema (dict): The JSON schema dictionary.
required_fields (list): List of required fields for the specified field.
Returns:
str: The generated AsciiDoc content.
"""
asciidoc_content = f"= {field_name.capitalize()}\n\n"
field_data = schema['properties'][field_name]
asciidoc_content += field_data.get("description", "") + "\n\n"

# Generate the content for the properties, recursively handling nested properties
asciidoc_content += generate_asciidoc_properties(field_data['properties'], required_fields, level=2)

return asciidoc_content

def main():
"""
Expand Down Expand Up @@ -89,6 +113,5 @@ def main():

print(f"AsciiDoc generated successfully! Output saved to {output_filename}")


if __name__ == "__main__":
main()

0 comments on commit fca6074

Please sign in to comment.