diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-03-09 08:45:52 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-03-10 09:41:34 +0100 |
commit | cf72a499f35b9bfa77b7ee3a9b0dd4a0ad7d9326 (patch) | |
tree | b2ce846c6cf33d9868343e8b71a2a69a90bb59da | |
parent | util: Add function to run commands (diff) | |
download | rtems-central-cf72a499f35b9bfa77b7ee3a9b0dd4a0ad7d9326.tar.bz2 |
sphinxcontent: Add SphinxInterfaceMapper
-rw-r--r-- | rtemsspec/applconfig.py | 4 | ||||
-rw-r--r-- | rtemsspec/glossary.py | 4 | ||||
-rw-r--r-- | rtemsspec/interfacedoc.py | 4 | ||||
-rw-r--r-- | rtemsspec/sphinxcontent.py | 26 | ||||
-rw-r--r-- | rtemsspec/tests/spec-sphinx/a.yml | 13 | ||||
-rw-r--r-- | rtemsspec/tests/test_content_sphinx.py | 1 |
6 files changed, 42 insertions, 10 deletions
diff --git a/rtemsspec/applconfig.py b/rtemsspec/applconfig.py index 07a74907..364b1225 100644 --- a/rtemsspec/applconfig.py +++ b/rtemsspec/applconfig.py @@ -29,7 +29,7 @@ from typing import Any, Dict, List, Optional from rtemsspec.content import CContent, get_value_double_colon, \ get_value_doxygen_function, get_value_doxygen_group, get_value_hash -from rtemsspec.sphinxcontent import SphinxContent, SphinxMapper +from rtemsspec.sphinxcontent import SphinxContent, SphinxInterfaceMapper from rtemsspec.items import EmptyItem, Item, ItemCache, ItemGetValueContext, \ ItemMapper @@ -471,7 +471,7 @@ def generate(config: dict, item_cache: ItemCache) -> None: :param item_cache: The specification item cache containing the application configuration groups and options. """ - sphinx_mapper = SphinxMapper(EmptyItem()) + sphinx_mapper = SphinxInterfaceMapper(EmptyItem()) _add_sphinx_get_values(sphinx_mapper) doxygen_mapper = ItemMapper(EmptyItem()) _add_doxygen_get_values(doxygen_mapper) diff --git a/rtemsspec/glossary.py b/rtemsspec/glossary.py index 64fcbc6b..f42781b1 100644 --- a/rtemsspec/glossary.py +++ b/rtemsspec/glossary.py @@ -28,7 +28,7 @@ import glob import re from typing import Any, Dict, NamedTuple -from rtemsspec.sphinxcontent import SphinxContent, SphinxMapper +from rtemsspec.sphinxcontent import SphinxContent, SphinxInterfaceMapper from rtemsspec.items import Item, ItemCache, ItemGetValueContext, ItemMapper ItemMap = Dict[str, Item] @@ -59,7 +59,7 @@ def _generate_glossary_content(terms: ItemMap, header: str, content.add(":sorted:") for item in sorted(terms.values(), key=lambda x: x["term"].lower()): content.register_license_and_copyrights_of_item(item) - text = SphinxMapper(item).substitute(item["text"]) + text = SphinxInterfaceMapper(item).substitute(item["text"]) content.add_definition_item(item["term"], text) content.add_licence_and_copyrights() content.write(target) diff --git a/rtemsspec/interfacedoc.py b/rtemsspec/interfacedoc.py index 3c575e14..0787c208 100644 --- a/rtemsspec/interfacedoc.py +++ b/rtemsspec/interfacedoc.py @@ -32,7 +32,7 @@ from typing import Any, Dict, List, Tuple from rtemsspec.content import CContent from rtemsspec.sphinxcontent import get_label, get_reference, SphinxContent, \ - SphinxMapper + SphinxInterfaceMapper from rtemsspec.items import Item, ItemCache, ItemGetValueContext, ItemMapper ItemMap = Dict[str, Item] @@ -68,7 +68,7 @@ def _get_param(ctx: ItemGetValueContext) -> Any: return f"``{_sanitize_name(ctx.value[ctx.key])}``" -class _Mapper(SphinxMapper): +class _Mapper(SphinxInterfaceMapper): def __init__(self, item: Item, group_uids: List[str]): super().__init__(item) self._group_uids = set(group_uids) diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py index 2d214021..1a00b79c 100644 --- a/rtemsspec/sphinxcontent.py +++ b/rtemsspec/sphinxcontent.py @@ -209,6 +209,10 @@ def _get_appl_config_option(ctx: ItemGetValueContext) -> Any: return f":ref:`{ctx.value[ctx.key]}`" +def _get_value_sphinx_data(ctx: ItemGetValueContext) -> Any: + return f":c:data:`{ctx.value[ctx.key]}`" + + def _get_value_sphinx_macro(ctx: ItemGetValueContext) -> Any: return f":c:macro:`{ctx.value[ctx.key]}`" @@ -244,13 +248,13 @@ class SphinxMapper(ItemMapper): self.add_get_value("glossary/term:/term", _get_ref_term) self.add_get_value("glossary/term:/plural", _get_ref_term_plural) self.add_get_value("interface/appl-config-option/feature-enable:/name", - _get_appl_config_option) + _get_value_sphinx_data) self.add_get_value("interface/appl-config-option/feature:/name", - _get_appl_config_option) + _get_value_sphinx_data) self.add_get_value("interface/appl-config-option/initializer:/name", - _get_appl_config_option) + _get_value_sphinx_data) self.add_get_value("interface/appl-config-option/integer:/name", - _get_appl_config_option) + _get_value_sphinx_data) self.add_get_value("interface/define:/name", _get_value_sphinx_macro) self.add_get_value("interface/enum:/name", _get_value_sphinx_type) self.add_get_value("interface/enumerator:/name", @@ -267,3 +271,17 @@ class SphinxMapper(ItemMapper): _get_value_sphinx_function) self.add_get_value("interface/unspecified-type:/name", _get_value_sphinx_unspecified_type) + + +class SphinxInterfaceMapper(SphinxMapper): + """ Sphinx item mapper for the interface documentation. """ + def __init__(self, item: Item, recursive: bool = False): + super().__init__(item, recursive) + self.add_get_value("interface/appl-config-option/feature-enable:/name", + _get_appl_config_option) + self.add_get_value("interface/appl-config-option/feature:/name", + _get_appl_config_option) + self.add_get_value("interface/appl-config-option/initializer:/name", + _get_appl_config_option) + self.add_get_value("interface/appl-config-option/integer:/name", + _get_appl_config_option) diff --git a/rtemsspec/tests/spec-sphinx/a.yml b/rtemsspec/tests/spec-sphinx/a.yml new file mode 100644 index 00000000..a3e406a4 --- /dev/null +++ b/rtemsspec/tests/spec-sphinx/a.yml @@ -0,0 +1,13 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +default: default a +description: description a +index-entries: [] +name: a +notes: null +appl-config-option-type: feature +copyrights: +- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) +enabled-by: true +interface-type: appl-config-option +links: [] +type: interface diff --git a/rtemsspec/tests/test_content_sphinx.py b/rtemsspec/tests/test_content_sphinx.py index f9235089..85d1e151 100644 --- a/rtemsspec/tests/test_content_sphinx.py +++ b/rtemsspec/tests/test_content_sphinx.py @@ -299,3 +299,4 @@ def test_substitute(tmpdir): assert mapper.substitute("${x:/plural}") == ":term:`ys <y>`" mapper.add_get_value("other:/name", lambda ctx: ctx.value[ctx.key]) assert mapper.substitute("${y:/name}") == "foobar" + assert mapper.substitute("${a:/name}") == ":c:data:`a`" |