|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from strictdoc.backend.sdoc.models.document import SDocDocument |
| 5 | +from strictdoc.backend.sdoc.models.node import SDocNode |
| 6 | +from strictdoc.core.document_iterator import DocumentCachingIterator |
| 7 | +from strictdoc.core.project_config import ProjectConfig |
| 8 | +from strictdoc.core.traceability_index import TraceabilityIndex |
| 9 | +from strictdoc.export.html.renderers.link_renderer import LinkRenderer |
| 10 | + |
| 11 | + |
| 12 | +class DoxygenGenerator: |
| 13 | + def __init__(self, project_config: ProjectConfig): |
| 14 | + self.project_config: ProjectConfig = project_config |
| 15 | + |
| 16 | + def export( |
| 17 | + self, |
| 18 | + *, |
| 19 | + traceability_index: TraceabilityIndex, |
| 20 | + path_to_output_dir: str, |
| 21 | + ) -> None: |
| 22 | + Path(path_to_output_dir).mkdir(parents=True, exist_ok=True) |
| 23 | + output_path = os.path.join(path_to_output_dir, "strictdoc.xml") |
| 24 | + |
| 25 | + link_renderer = LinkRenderer( |
| 26 | + root_path="NOT_RELEVANT", static_path="NOT_RELEVANT" |
| 27 | + ) |
| 28 | + |
| 29 | + def template_node(node_uid: str, path_to_html: str) -> str: |
| 30 | + return f"""\ |
| 31 | + <compound kind="page"> |
| 32 | + <name>{node_uid}</name> |
| 33 | + <filename>html/{path_to_html}</filename> |
| 34 | + </compound> |
| 35 | +""" |
| 36 | + |
| 37 | + template_all_nodes = "" |
| 38 | + |
| 39 | + assert traceability_index.document_tree is not None |
| 40 | + assert traceability_index.document_tree.document_list is not None |
| 41 | + |
| 42 | + document_: SDocDocument |
| 43 | + for document_ in traceability_index.document_tree.document_list: |
| 44 | + document_iterator = DocumentCachingIterator(document_) |
| 45 | + |
| 46 | + for node in document_iterator.all_content( |
| 47 | + print_fragments=False, |
| 48 | + print_fragments_from_files=False, |
| 49 | + ): |
| 50 | + if isinstance(node, SDocNode) and node.reserved_uid is not None: |
| 51 | + path_to_html = link_renderer.render_node_doxygen_link(node) |
| 52 | + template_all_nodes += template_node( |
| 53 | + node.reserved_uid, path_to_html |
| 54 | + ) |
| 55 | + |
| 56 | + template_xml = f"""\ |
| 57 | +<?xml version='1.0' encoding='UTF-8' standalone='yes' ?> |
| 58 | +<tagfile doxygen_version="1.9.8"> |
| 59 | +{template_all_nodes.rstrip()} |
| 60 | +</tagfile> |
| 61 | +""" |
| 62 | + with open(output_path, "w", encoding="utf8") as file: |
| 63 | + file.write(template_xml) |
0 commit comments