Add a function to make parameter tables

Signed-off-by: Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com>
This commit is contained in:
Thomas A. Christensen II 2022-01-10 17:14:37 -06:00
parent f1b695baf9
commit ed37b5036a
Signed by: millironx
GPG key ID: 139C07724802BC5D

View file

@ -44,6 +44,74 @@ def params_to_list(params):
io_item += nodes.paragraph(text=params["description"])
return io_item
def params_to_table(type, params):
# Create a table
params_table = nodes.table()
params_table += nodes.title(text=type)
# Make it two columns wide
params_tgroup = nodes.tgroup(cols=2)
for _ in range(2):
colspec = nodes.colspec(colwidth=1)
params_tgroup.append(colspec)
# Create the row definitions
params_rows = []
for param in params:
# Create a new row
param_row = nodes.row()
# If this parameter is a tuple, the new row takes on the form
# +-------+------------------+
# | | +--------------+ |
# | Tuple | | Params Table | |
# | | +--------------+ |
# +-------+------------------+
# via recursion
if "tuple" in param.keys():
# Tuple title
param_name_entry = nodes.entry()
param_name_entry += nodes.paragraph(text="Tuple")
param_row += param_name_entry
# Params table
sub_params_entry = nodes.entry()
sub_params_entry += params_to_table("Tuple", param["tuple"])
param_row += sub_params_entry
# If this is actually a parameter, the new row takes on the form
# +------------+-------------+
# | Name(Type) | Description |
# +------------+-------------+
# or
# +------+-------------+
# | Type | Description |
# +------+-------------+
else:
# Parameter title
param_name_entry = nodes.entry()
if "name" in param.keys():
param_name_entry += nodes.paragraph(text=f"{param['name']}({param['type']})")
else:
param_name_entry += nodes.paragraph(text=param["type"])
param_row += param_name_entry
# Parameter description
param_description_entry = nodes.entry()
param_description_entry += nodes.paragraph(text=param["description"])
param_row += param_description_entry
# Add this row to the vector
params_rows.append(param_row)
# Convert the rows to a table
params_table_body = nodes.tbody()
params_table_body.extend(params_rows)
params_tgroup += params_table_body
params_table += params_tgroup
return params_table
class NFDocs(Directive):
# Class default overrides
required_arguments = 1