summaryrefslogtreecommitdiffstats
path: root/rtemsqual/sphinxcontent.py
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-01 14:54:20 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-03 10:22:46 +0200
commite382283c183499a03599e4b075030d41eba1338b (patch)
tree113e2d9aff653e0417eb2d3358524113a7af66f2 /rtemsqual/sphinxcontent.py
parentitems: Add ItemGetValueContext (diff)
downloadrtems-central-e382283c183499a03599e4b075030d41eba1338b.tar.bz2
items: Move item get value customization
Diffstat (limited to 'rtemsqual/sphinxcontent.py')
-rw-r--r--rtemsqual/sphinxcontent.py33
1 files changed, 9 insertions, 24 deletions
diff --git a/rtemsqual/sphinxcontent.py b/rtemsqual/sphinxcontent.py
index 4ec5ceec..97639c78 100644
--- a/rtemsqual/sphinxcontent.py
+++ b/rtemsqual/sphinxcontent.py
@@ -26,8 +26,7 @@
from contextlib import contextmanager
import re
-from typing import Any, Dict, Callable, Iterable, Iterator, List, Optional, \
- Union
+from typing import Any, Iterable, Iterator, List, Optional, Union
from rtemsqual.content import Content, make_lines
from rtemsqual.items import Item, ItemGetValueContext, ItemMapper
@@ -210,34 +209,20 @@ class SphinxContent(Content):
self.prepend([f".. SPDX-License-Identifier: {self._license}", ""])
-def _get_ref_term(value: Any, key: str) -> str:
- return f":term:`{value[key]}`"
+def _get_ref_term(ctx: ItemGetValueContext) -> Any:
+ return f":term:`{ctx.value[ctx.key]}`"
-def _get_ref_term_plural(value: Any, key: str) -> str:
+def _get_ref_term_plural(ctx: ItemGetValueContext) -> Any:
try:
- return f":term:`{value[key]} <{value['term']}>`"
+ return f":term:`{ctx.value[ctx.key]} <{ctx.value['term']}>`"
except KeyError:
- return f":term:`{value['term']}s <{value['term']}>`"
+ return f":term:`{ctx.value['term']}s <{ctx.value['term']}>`"
class SphinxMapper(ItemMapper):
- """ Sphinx mapper. """
+ """ Sphinx item mapper. """
def __init__(self, item: Item):
super().__init__(item)
- self._get_ref = {
- "glossary/term:/term": _get_ref_term,
- "glossary/term:/plural": _get_ref_term_plural
- } # type: Dict[str, Callable[[Any, str], str]]
-
- def add_get_reference(self, type_path_key: str,
- get_ref: Callable[[Any, str], str]) -> None:
- """
- Adds a function to get a reference to the specified path for items of
- the specified type.
- """
- self._get_ref[type_path_key] = get_ref
-
- def get_value(self, ctx: ItemGetValueContext) -> Any:
- """ Gets a value by key and optional index. """
- return self._get_ref[ctx.type_path_key](ctx.value, ctx.key)
+ self.add_get_value("glossary/term:/term", _get_ref_term)
+ self.add_get_value("glossary/term:/plural", _get_ref_term_plural)