Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kecho committed Jul 29, 2023
1 parent 0e7962b commit 6dc46d2
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 2,998 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,43 @@ html
.treedot
{
float: left;
color:#00ff03;
margin-right:10px;
}

.treelink
{
color:#b7b7ff;
}

.treename
{
}

.membertable
{
font-size:12px;
}

.h3title
{
color:#b7b7ff;
padding-top:20px;
font-size:20px;
}

.subtitle
{
color:#00ff03;
font-size:10px;
}

.head
{
float:top;
}
.foot
{
float:bottom;
}

87 changes: 56 additions & 31 deletions Source/scripts/doctool/doctool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
import importlib
import argparse

def get_publicsymbols(mod, allsymbols):
return [(nm, getattr(mod, nm)) for nm in allsymbols if not (nm.startswith("__"))]

def get_funcsymbols(publicsymbols):
return [(nm, s) for (nm, s) in publicsymbols if callable(s) and type(s) != type]

def get_subtypesymbols(publicsymbols):
return [(nm, s) for (nm, s) in publicsymbols if (type(s) == type and not type(s).__name__.startswith("Enum") and not nm.startswith("Enum"))]

def get_membersymbols(publicsymbols):
return [(nm, s) for (nm, s) in publicsymbols if (not type(s).__name__.startswith("Enum")) and (not type(s) == type) and (not callable(s))]

def get_enumsymbols(publicsymbols):
return [(nm[4:], s) for (nm, s) in publicsymbols if (nm.startswith("Enum"))]


def html_header(module_name):
print(
"""
Expand Down Expand Up @@ -64,12 +80,10 @@ def html_doc_bar_item_name(name, can_expand=True, is_expanded=True):
return """<div class="treelink"><div class="treedot">%s</div><span class="treename">%s</span></div>""" % (('-' if is_expanded else '+') if can_expand else "", name)

def html_class_doc_bar(class_name, class_obj, lvl = 0):
allsymbols = dir(class_obj)
publicsymbols = [(nm, getattr(class_obj, nm)) for nm in allsymbols if not (nm.startswith("__") or nm.startswith("Enum"))]
methodsymbols = [(nm, s) for (nm, s) in publicsymbols if callable(s) and type(s) != type]
subtypesymbols = [(nm, s) for (nm, s) in publicsymbols if (type(s) == type and not type(s).__name__.startswith("Enum"))]
members = [(nm, s) for (nm, s) in publicsymbols if (not type(s).__name__.startswith("Enum")) and (not type(s) == type) and (not callable(s))]
hasChildren = len(members) > 0 or len(subtypesymbols) > 0 or len(methodsymbols) > 0
publicsymbols = get_publicsymbols(class_obj, dir(class_obj))
methodsymbols = get_funcsymbols(publicsymbols)
subtypesymbols = get_subtypesymbols(publicsymbols)
hasChildren = len(subtypesymbols) > 0 or len(methodsymbols) > 0
s = html_doc_bar_item_name(class_name, True, not hasChildren)
if hasChildren:
if (lvl > 0):
Expand All @@ -78,12 +92,6 @@ def html_class_doc_bar(class_name, class_obj, lvl = 0):
else:
s += """
<ul style="display:none">"""
for (nm, symb) in members:
s += """
<li>"""
s += html_class_doc_bar(nm, symb, lvl + 1)
s += """
</li>"""
for (nm, symb) in methodsymbols:
s += """
<li>"""
Expand All @@ -104,11 +112,10 @@ def html_doc_bar(mod):
print("""
<div class="sidebar">""", end="")

allsymbols = dir(mod)
publicsymbols = [(nm, getattr(mod, nm)) for nm in allsymbols if not (nm.startswith("__") or nm.startswith("Enum"))]
funcsymbols = [(nm, s) for (nm, s) in publicsymbols if callable(s) and type(s) != type]
typesymbols = [(nm, s) for (nm, s) in publicsymbols if (type(s) == type and not type(s).__name__.startswith("Enum"))]
enumsymbols = [(nm, s) for (nm, s) in publicsymbols if (type(s).__name__.startswith("Enum"))]
publicsymbols = get_publicsymbols(mod, dir(mod))
funcsymbols = get_funcsymbols(publicsymbols)
typesymbols = get_subtypesymbols(publicsymbols)
enumsymbols = get_enumsymbols(publicsymbols)
print("""
<ul><li>""", end="")
print(html_doc_bar_item_name("Functions"), end="")
Expand Down Expand Up @@ -163,27 +170,45 @@ def html_doc_bar(mod):
print("""
</div>""", end="")

def html_recurse_doc(parent_name, obj_name, obj):
outs = """<h3 id="%s">%s</h3>""" % (obj_name, parent_name + obj_name)
def html_member_table(members):
if len(members) == 0:
return ""

out = '<table class="membertable">'
for (nm, s) in members:
out += "<tr>"
out += "<td>%s</td>" % (nm)
out += "<td>%s</td>" % (s.__doc__)
out += "</tr>"
out += "</table>"
return out


def html_recurse_doc(parent_name, obj_name, obj, subtitle=""):
outs = """<div id="%s" class="h3title">%s</div>""" % (obj_name, parent_name + obj_name)
if subtitle != "":
outs += """<div class="subtitle">%s</div>""" % (subtitle)
outs += "<pre>%s</pre>" % (obj.__doc__)
outs += "<br/>"
allsymbols = dir(obj)
publicsymbols = [(nm, getattr(obj, nm)) for nm in allsymbols if not (nm.startswith("__") or nm.startswith("Enum"))]
funcsymbols = [(nm, s) for (nm, s) in publicsymbols if callable(s) and type(s) != type]
typesymbols = [(nm, s) for (nm, s) in publicsymbols if (type(s) == type and not type(s).__name__.startswith("Enum"))]
enumsymbols = [(nm, s) for (nm, s) in publicsymbols if (type(s).__name__.startswith("Enum"))]
members = [(nm, s) for (nm, s) in publicsymbols if (not type(s).__name__.startswith("Enum")) and (not type(s) == type) and (not callable(s))]
publicsymbols = get_publicsymbols(obj, dir(obj))
funcsymbols = get_funcsymbols(publicsymbols)
typesymbols = get_subtypesymbols(publicsymbols)
enumsymbols = get_enumsymbols(publicsymbols)
members = get_membersymbols(publicsymbols)
new_parent_name = parent_name + obj_name + "."

for (nm, s) in members:
outs += ("<div>%s</div><br/>" % nm)
is_enum = type(obj).__name__.startswith("Enum")

if is_enum:
for (nm, s) in members:
outs += ("<div>%s</div><br/>" % nm)
else: outs += html_member_table(members)

for (nm, s) in funcsymbols:
outs += html_recurse_doc(new_parent_name, nm, s)
outs += html_recurse_doc(new_parent_name, nm, s, "function")
for (nm, s) in typesymbols:
outs += html_recurse_doc(new_parent_name, nm, s)
outs += html_recurse_doc(new_parent_name, nm, s, "type")
for (nm, s) in enumsymbols:
outs += html_recurse_doc(new_parent_name, nm, s)
outs += html_recurse_doc(new_parent_name, nm, s, "enum")
return outs

def html_doc_content(mod):
Expand Down
2 changes: 1 addition & 1 deletion docs/_data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ main:
- title: Tutorial
url: /tutorial
- title: API Docs
url: /coalpy.gpu.html
url: /apidocs/0.50/coalpy.gpu.html
- title: GitHub
url: https://github.com/kecho/coalpy
Loading

0 comments on commit 6dc46d2

Please sign in to comment.