from typing import Union from .logger import logger def image(src): return f'' def video(src): return f'' def short_desc(desc): return f'{desc}' def coll(text: str): return f"{text}_collapsed" descriptions = { } sizes = ['1.4','1.2','1'] def as_html(entry, depth=0): if isinstance(entry, dict): size = 0.8 if depth < 2 else 1 html = '' for k in entry: if k == "collapsed": continue collapse_single = k.endswith("_collapsed") if collapse_single: name = k[:-len("_collapsed")] else: name = k collapse_flag = ' VHS_precollapse' if entry.get("collapsed", False) or collapse_single else '' html += f'[-]{name}: {as_html(entry[k], depth=depth+1)}' return html if isinstance(entry, list): html = '' for i in entry: html += f'{as_html(i, depth=depth)}' return html return str(entry) def register_description(node_id: str, desc: Union[list, dict]): descriptions[node_id] = desc def format_descriptions(nodes): for k in descriptions: if k.endswith("_collapsed"): k = k[:-len("_collapsed")] nodes[k].DESCRIPTION = as_html(descriptions[k]) # undocumented_nodes = [] # for k in nodes: # if not hasattr(nodes[k], "DESCRIPTION"): # undocumented_nodes.append(k) # if len(undocumented_nodes) > 0: # logger.info(f"Undocumented nodes: {undocumented_nodes}") class DocHelper: def __init__(self): self.actual_dict = {} def add(self, add_dict): self.actual_dict.update(add_dict) return self def get(self): return self.actual_dict @staticmethod def combine(*args): docs = DocHelper() for doc in args: docs.add(doc) return docs.get()