-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateClassAsciidoc.py
45 lines (32 loc) · 1.16 KB
/
GenerateClassAsciidoc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import inspect
def generate_asciidoc_from_class(cls):
# Create a header for the class
docstrings = [f"== Class: {cls.__name__}\n"]
# Get all methods and attributes of the class
for name, method in inspect.getmembers(cls, predicate=inspect.isfunction):
# Get the docstring
docstring = inspect.getdoc(method)
# Add method name as section
docstrings.append(f"=== Method: `{name}`")
# Add the docstring content, or a placeholder if no docstring is available
if docstring:
docstrings.append(f"\n{docstring}\n")
else:
docstrings.append("\n_No docstring available_\n")
# Return the formatted AsciiDoc
return "\n".join(docstrings)
# Example usage with a sample class
class MyClass:
"""This is MyClass"""
def method_one(self):
"""This method does something."""
pass
def method_two(self, param):
"""This method takes a parameter."""
pass
def method_without_docstring(self):
pass
if __name__ == "__main__":
from SalletNodePackage.BitcoinNodeObject import *
adoc = generate_asciidoc_from_class(Node)
print(adoc)