Changeset a5f3cc1 in rtems-central for rtemsqual/glossary.py
- Timestamp:
- May 6, 2020, 8:31:57 AM (10 months ago)
- Branches:
- master
- Children:
- 833470c
- Parents:
- fa46b668
- git-author:
- Sebastian Huber <sebastian.huber@…> (05/06/20 08:31:57)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (05/28/20 08:37:29)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtemsqual/glossary.py
rfa46b668 ra5f3cc1 27 27 import glob 28 28 import re 29 from typing import Dict29 from typing import Any, Dict, Optional 30 30 31 from rtemsqual.content import MacroToSphinx, SphinxContent32 from rtemsqual.items import Item, ItemCache 31 from rtemsqual.content import SphinxContent, SphinxMapper 32 from rtemsqual.items import Item, ItemCache, ItemMapper 33 33 34 34 ItemMap = Dict[str, Item] … … 55 55 with content.indent(): 56 56 content.append(":sorted:") 57 macro_to_sphinx = MacroToSphinx()58 macro_to_sphinx.set_terms(terms)59 57 for item in sorted(terms.values(), 60 58 key=lambda x: x["glossary-term"].lower()): 61 text = macro_to_sphinx.substitute(item["text"].strip())62 59 content.register_license_and_copyrights_of_item(item) 63 60 with content.indent(): 61 text = SphinxMapper(item).substitute(item["text"]) 64 62 content.add_definition_item(item["glossary-term"], text) 65 63 content.add_licence_and_copyrights() … … 83 81 84 82 85 def _resolve_glossary_term(document_terms: ItemMap, project_terms: ItemMap, 86 term: Item) -> None: 87 for match in re.findall(r"@@|@([a-z]+){([^}]+)}", term["text"]): 88 if match[1] and match[1] not in document_terms: 89 new_term = project_terms[match[1]] 90 document_terms[match[1]] = new_term 91 _resolve_glossary_term(document_terms, project_terms, new_term) 83 class _GlossaryMapper(ItemMapper): 84 def __init__(self, item: Item, document_terms: ItemMap): 85 super().__init__(item) 86 self._document_terms = document_terms 87 88 def get_value(self, item: Item, _path: str, _value: Any, key: str, 89 _index: Optional[int]) -> Any: 90 """ Recursively adds glossary terms to the document terms. """ 91 if key == "glossary-term": 92 if item.uid not in self._document_terms: 93 self._document_terms[item.uid] = item 94 _GlossaryMapper(item, 95 self._document_terms).substitute(item["text"]) 96 # The value of this substitute is unused. 97 return "" 92 98 93 99 94 def _resolve_glossary_terms(document_terms: ItemMap, 95 project_terms: ItemMap) -> None: 100 def _resolve_glossary_terms(document_terms: ItemMap) -> None: 96 101 for term in list(document_terms.values()): 97 _ resolve_glossary_term(document_terms, project_terms, term)102 _GlossaryMapper(term, document_terms).substitute(term["text"]) 98 103 99 104 … … 107 112 for path in config["rest-source-paths"]: 108 113 _find_glossary_terms(path, document_terms, project_terms) 109 _resolve_glossary_terms(document_terms , project_terms)114 _resolve_glossary_terms(document_terms) 110 115 content = _generate_glossary_content(document_terms) 111 116 content.write(config["target"])
Note: See TracChangeset
for help on using the changeset viewer.