diff --git a/mkdoxy/doxygen.py b/mkdoxy/doxygen.py index a56f4be8..39c70c00 100644 --- a/mkdoxy/doxygen.py +++ b/mkdoxy/doxygen.py @@ -5,6 +5,7 @@ from mkdoxy.cache import Cache from mkdoxy.constants import Kind, Visibility from mkdoxy.node import Node +from mkdoxy.project import ProjectContext from mkdoxy.xml_parser import XmlParser log: logging.Logger = logging.getLogger("mkdocs") @@ -19,13 +20,13 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache): xml = ElementTree.parse(path_xml).getroot() self.parser = parser - self.cache = cache + self.ctx = ProjectContext(cache) - self.root = Node("root", None, self.cache, self.parser, None) - self.groups = Node("root", None, self.cache, self.parser, None) - self.files = Node("root", None, self.cache, self.parser, None) - self.pages = Node("root", None, self.cache, self.parser, None) - self.examples = Node("root", None, self.cache, self.parser, None) + self.root = Node("root", None, self.ctx, self.parser, None) + self.groups = Node("root", None, self.ctx, self.parser, None) + self.files = Node("root", None, self.ctx, self.parser, None) + self.pages = Node("root", None, self.ctx, self.parser, None) + self.examples = Node("root", None, self.ctx, self.parser, None) for compound in xml.findall("compound"): kind = Kind.from_str(compound.get("kind")) @@ -34,7 +35,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache): node = Node( os.path.join(index_path, f"{refid}.xml"), None, - self.cache, + self.ctx, self.parser, self.root, ) @@ -44,7 +45,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache): node = Node( os.path.join(index_path, f"{refid}.xml"), None, - self.cache, + self.ctx, self.parser, self.root, ) @@ -54,7 +55,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache): node = Node( os.path.join(index_path, f"{refid}.xml"), None, - self.cache, + self.ctx, self.parser, self.root, ) @@ -64,7 +65,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache): node = Node( os.path.join(index_path, f"{refid}.xml"), None, - self.cache, + self.ctx, self.parser, self.root, ) @@ -74,7 +75,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache): node = Node( os.path.join(index_path, f"{refid}.xml"), None, - self.cache, + self.ctx, self.parser, self.root, ) diff --git a/mkdoxy/generatorSnippets.py b/mkdoxy/generatorSnippets.py index f3b24a5d..f981e638 100644 --- a/mkdoxy/generatorSnippets.py +++ b/mkdoxy/generatorSnippets.py @@ -152,7 +152,7 @@ def incorrect_argument(self, project: str, argument: str, config: dict, snippet: project, config, f"Incorrect argument: {argument}" if argument else f"Add argument to snippet: {project}", - f"Argument have to be based on this diagram → **:::doxy.{project}.**", + f"Argument have to be based on this diagram → **:::doxy.{project}.**", "A list of available arguments:", "\n".join(self.doxy_arguments.keys()), "yaml", @@ -162,14 +162,12 @@ def incorrect_argument(self, project: str, argument: str, config: dict, snippet: def replace_markdown(self, start: int, end: int, replacement: str): self.markdown = self.markdown[:start] + replacement + "\n" + self.markdown[end:] - def _recurs_setLinkPrefixNode(self, node: Node, linkPrefix: str): - node.setLinkPrefix(linkPrefix) - if node.kind.is_parent(): - self._recurs_setLinkPrefixNodes(node.children, linkPrefix) + def _setLinkPrefixNode(self, node: Node, linkPrefix: str): + node.project.linkPrefix = linkPrefix - def _recurs_setLinkPrefixNodes(self, nodes: [Node], linkPrefix: str): - for node in nodes: - self._recurs_setLinkPrefixNode(node, linkPrefix) + def _setLinkPrefixNodes(self, nodes: list[Node], linkPrefix: str): + if nodes: + nodes[0].project.linkPrefix = linkPrefix def is_project_exist(self, project: str): return project in self.projects @@ -249,7 +247,7 @@ def doxyCode(self, snippet, project: str, config): f"{snippet}", "yaml", ) - self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") return self.generatorBase[project].code(node, config, progCode) return self.doxyError( project, @@ -281,7 +279,7 @@ def doxyFunction(self, snippet, project: str, config: dict): return self.doxyNodeIsNone(project, config, snippet) if isinstance(node, Node): - self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") return self.generatorBase[project].function(node, config) return self.doxyError( project, @@ -304,7 +302,7 @@ def doxyClass(self, snippet, project: str, config: dict): return self.doxyNodeIsNone(project, config, snippet) if isinstance(node, Node): - self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") return self.generatorBase[project].member(node, config) return self.doxyError( project, @@ -327,7 +325,7 @@ def doxyClassMethod(self, snippet, project: str, config): return self.doxyNodeIsNone(project, config, snippet) if isinstance(node, Node): - self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/") return self.generatorBase[project].function(node, config) return self.doxyError( project, @@ -345,7 +343,7 @@ def doxyClassList(self, snippet, project: str, config): if errorMsg: return errorMsg nodes = self.doxygen[project].root.children - self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") return self.generatorBase[project].annotated(nodes, config) def doxyClassIndex(self, snippet, project: str, config): @@ -353,7 +351,7 @@ def doxyClassIndex(self, snippet, project: str, config): if errorMsg: return errorMsg nodes = self.doxygen[project].root.children - self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") return self.generatorBase[project].classes(nodes, config) def doxyClassHierarchy(self, snippet, project: str, config): @@ -361,7 +359,7 @@ def doxyClassHierarchy(self, snippet, project: str, config): if errorMsg: return errorMsg nodes = self.doxygen[project].root.children - self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") return self.generatorBase[project].hierarchy(nodes, config) def doxyNamespaceList(self, snippet, project: str, config): @@ -369,7 +367,7 @@ def doxyNamespaceList(self, snippet, project: str, config): if errorMsg: return errorMsg nodes = self.doxygen[project].root.children - self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") return self.generatorBase[project].namespaces(nodes, config) def doxyFileList(self, snippet, project: str, config): @@ -377,7 +375,7 @@ def doxyFileList(self, snippet, project: str, config): if errorMsg: return errorMsg nodes = self.doxygen[project].files.children - self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") + self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/") return self.generatorBase[project].fileindex(nodes, config) def doxyNodeIsNone(self, project: str, config: dict, snippet: str) -> str: diff --git a/mkdoxy/node.py b/mkdoxy/node.py index 26b66bad..41323070 100644 --- a/mkdoxy/node.py +++ b/mkdoxy/node.py @@ -3,9 +3,9 @@ from xml.etree import ElementTree from xml.etree.ElementTree import Element as Element -from mkdoxy.cache import Cache from mkdoxy.constants import OVERLOAD_OPERATORS, Kind, Visibility from mkdoxy.markdown import escape +from mkdoxy.project import ProjectContext from mkdoxy.property import Property from mkdoxy.utils import split_safe from mkdoxy.xml_parser import XmlParser @@ -18,18 +18,18 @@ def __init__( self, xml_file: str, xml: Element, - cache: Cache, + project: ProjectContext, parser: XmlParser, parent: "Node", refid: str = None, debug: bool = False, ): self._children: ["Node"] = [] - self._cache: Cache = cache + self._cache = project.cache self._parser: XmlParser = parser self._parent = parent self.debug = debug - self.linkPrefix = "" + self.project = project if xml_file == "root": self._refid = "root" @@ -91,9 +91,6 @@ def __init__( def __repr__(self): return f"Node: {self.name} refid: {self._refid}" - def setLinkPrefix(self, linkPrefix: str): - self.linkPrefix = linkPrefix - def add_child(self, child: "Node"): self._children.append(child) @@ -113,7 +110,7 @@ def _check_for_children(self): child = Node( os.path.join(self._dirname, f"{refid}.xml"), None, - self._cache, + self.project, self._parser, self, ) @@ -138,7 +135,7 @@ def _check_for_children(self): child = Node( os.path.join(self._dirname, f"{refid}.xml"), None, - self._cache, + self.project, self._parser, self, ) @@ -146,7 +143,7 @@ def _check_for_children(self): child = Node( os.path.join(self._dirname, f"{refid}.xml"), Element("compounddef"), - self._cache, + self.project, self._parser, self, refid=refid, @@ -168,7 +165,7 @@ def _check_for_children(self): child = Node( os.path.join(self._dirname, f"{refid}.xml"), None, - self._cache, + self.project, self._parser, self, ) @@ -188,7 +185,7 @@ def _check_for_children(self): child = Node( os.path.join(self._dirname, f"{refid}.xml"), None, - self._cache, + self.project, self._parser, self, ) @@ -209,7 +206,7 @@ def _check_for_children(self): child = Node( os.path.join(self._dirname, f"{refid}.xml"), None, - self._cache, + self.project, self._parser, self, ) @@ -228,7 +225,7 @@ def _check_for_children(self): continue except Exception: pass - child = Node(None, memberdef, self._cache, self._parser, self) + child = Node(None, memberdef, self.project, self._parser, self) self.add_child(child) # for detaileddescription in self._xml.findall('detaileddescription'): @@ -477,14 +474,14 @@ def anchor(self) -> str: @property def url(self) -> str: if self.is_parent or self.is_group or self.is_file or self.is_dir or self.is_page: - return self.linkPrefix + self._refid + ".md" + return self.project.linkPrefix + self._refid + ".md" else: return f"{self._parent.url}#{self.anchor}" @property def base_url(self) -> str: def prefix(page: str): - return self.linkPrefix + page + return self.project.linkPrefix + page if self.is_group: return prefix("modules.md") @@ -509,13 +506,13 @@ def base_name(self) -> str: @property def url_source(self) -> str: if self.is_parent or self.is_group or self.is_file or self.is_dir: - return self.linkPrefix + self._refid + "_source.md" + return self.project.linkPrefix + self._refid + "_source.md" else: - return self.linkPrefix + self._refid + ".md" + return self.project.linkPrefix + self._refid + ".md" @property def filename(self) -> str: - return self.linkPrefix + self._refid + ".md" + return self.project.linkPrefix + self._refid + ".md" @property def root(self) -> "Node": diff --git a/mkdoxy/project.py b/mkdoxy/project.py new file mode 100644 index 00000000..d87068a0 --- /dev/null +++ b/mkdoxy/project.py @@ -0,0 +1,7 @@ +from mkdoxy.cache import Cache + + +class ProjectContext: + def __init__(self, cache: Cache) -> None: + self.cache = cache + self.linkPrefix: str = ""