# Generates a static webpage for the public C-API of `celeritas-core` # # TODO: # - remove prefixes like 'static' and 'inline' # - parse docstrings from source import re import os from pathlib import Path # --- HTML Fragments page_start = """ Celeritas core API
""" page_header = """

CELERITAS CORE API DOCS

""" page_footer = """ """ page_end = """
""" def emit_function_sig(signature: str) -> str: return f"""
  • {signature}
  • """ categories = { "Core": "src/core", "Render": "src/new_render", "Maths": "src/maths", "RAL": "src/ral", "Systems": "src/systems", } def find_pub_functions_in_folder(folder_path): functions = [] for filename in os.listdir(folder_path): filepath = os.path.join(folder_path, filename) if os.path.isfile(filepath): file_funcs = find_pub_functions_in_file(filepath) functions.extend(file_funcs) return functions def find_pub_functions_in_file(file_path): pattern = r'PUB\s+(\w+\s+)*(\w+)\s+(\w+)\s*\((.*?)\)' with open(file_path, 'r') as file: content = file.read() matches = re.finditer(pattern, content, re.MULTILINE) # Collect all the functions into an array functions = [] for match in matches: signature = match.group(0) if signature.startswith("PUB "): signature = signature[4:] if signature.startswith("c_static_inline "): signature = signature[16:] print(signature) functions.append(signature) return functions def generate_html(): html_filepath = "index.html" script_dir = Path(__file__).resolve().parent grandparent_dir = script_dir.parents[1] with open(html_filepath, 'w') as export_file: export_file.write(page_start) export_file.write(page_header) # TODO: make the actual content for category in categories.keys(): folder = os.path.join(grandparent_dir, categories[category]) category_funcs = find_pub_functions_in_folder(folder) export_file.write(f"

    {category}

    ") export_file.write("") export_file.write(page_end) if __name__ == "__main__": generate_html()