diff --git a/autodoc/autodoc.py b/autodoc/autodoc.py index e2ecc4d..a73f05e 100644 --- a/autodoc/autodoc.py +++ b/autodoc/autodoc.py @@ -1,7 +1,9 @@ """ Autodoc functions """ + import os +from datetime import datetime import common as doc from doc_state import * @@ -20,18 +22,26 @@ def __doc_app_state__(state, tab=" │ "): def __doc_application__(label, app): mdapp = f'\n## Real-time application "{label[1:]}"\n\n' mdapp += f"Below are descrbed the states and threads of the real-time application {label[1:]}.\n" - mdapp += "```\n" - mdapp += f'╭{"─"*(len(label)-1)}╮\n' - mdapp += f"│{label[1:]}│\n" - mdapp += f'╰┬{"─"*(len(label)-2)}╯\n' + + mdapp += "\n" + # mdapp += "```\n" + # mdapp += f'╭{"─"*(len(label)-1)}╮\n' + # mdapp += f"│{label[1:]}│\n" + # mdapp += f'╰┬{"─"*(len(label)-2)}╯\n' states = app["+States"] - for i, (label, obj) in enumerate(states.items()): - ch = "├─▷" if i < len(states) - 1 else "╰─▷" - tab = " │ " if i < len(states) - 1 else " " - if label[0] == "+": - mdapp += f" {ch} {label[1:]}\n" - mdapp += __doc_app_state__(obj, tab) - mdapp += "```\n" + + for i, (state, obj) in enumerate(states.items()): + if state[0] == "+": + mdapp += f" - {state[1:]}\n" + for thread in obj["+Threads"]: + if thread[0] == "+": + mdapp += f" - {thread[1:]}\n" + # ch = "├─▷" if i < len(states) - 1 else "╰─▷" + # tab = " │ " if i < len(states) - 1 else " " + # if label[0] == "+": + # mdapp += f" {ch} {label[1:]}\n" + # mdapp += __doc_app_state__(obj, tab) + # mdapp += "```\n" for label, obj in states.items(): if label[0] == "+": mdapp += f'\n### State "{label[1:]}"\n' @@ -44,13 +54,29 @@ def document(fname, args, config): doc.set_path(os.path.join(args.destination, fname)) if not os.path.isdir(doc.path()): os.mkdir(doc.path()) + now = datetime.now() # current date and time + today = now.strftime("%d/%m/%Y") + mddoc = "---\n" + mddoc += "toc: true\n" + mddoc += f"title: {fname} Documentation\n" + mddoc += "author: MARTe AutoDOC\n" + mddoc += "titlepage: true\n" + mddoc += f"date: {today}\n" + mddoc += "---\n\n" - mddoc = f"# {fname}\n" + mddoc += f"# {fname}\n" for label, obj in config.items(): if "Class" in obj: if obj["Class"] == "RealTimeApplication": mddoc += __doc_application__(label, obj) if obj["Class"] == "StateMachine": mddoc += f'\n## State-Machine "{label[1:]}"' - with open(os.path.join(doc.path(), f"{fname}.md"), "w") as file: + fpath = os.path.join(doc.path(), f"{fname}.md") + pdfpath = os.path.join(doc.path(), f"{fname}.pdf") + logging.info("Writing markdown...") + with open(fpath, "w") as file: file.write(mddoc) + logging.info("Generating pdf...") + os.system( + f"pandoc -H pandoc/disable_float.tex --template eisvogel --resource-path={doc.path()} -s {fpath} -o {pdfpath}" + ) diff --git a/autodoc/doc_state.py b/autodoc/doc_state.py index e972359..c0afb8f 100644 --- a/autodoc/doc_state.py +++ b/autodoc/doc_state.py @@ -519,5 +519,5 @@ def doc_state(label, state, app): os.system( f"dot -Tsvg -o{os.path.join(doc.path(), fname)}.svg {os.path.join(doc.path(), fname)}.dot" ) - mdstate += f"![{fname}]({fname}.svg)\n" + mdstate += f"![{fname} state]({fname}.svg)\n" return mdstate diff --git a/pandoc/disable_float.tex b/pandoc/disable_float.tex new file mode 100644 index 0000000..92bd004 --- /dev/null +++ b/pandoc/disable_float.tex @@ -0,0 +1,8 @@ +\usepackage{float} +\let\origfigure\figure +\let\endorigfigure\endfigure +\renewenvironment{figure}[1][2] { + \expandafter\origfigure\expandafter[H] +} { + \endorigfigure +}