summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-12 14:05:05 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-12 21:04:47 +0200
commit0174da56742c82322d5c04167bf76b217903247d (patch)
tree966c54529e3434761cb09d992e5d25ffae217656
parentmodules: Update rtems-docs (diff)
downloadrtems-central-0174da56742c82322d5c04167bf76b217903247d.tar.bz2
content: Improve plural of terms
-rw-r--r--rtemsspec/content.py5
-rw-r--r--rtemsspec/sphinxcontent.py8
-rw-r--r--rtemsspec/tests/spec-sphinx/z.yml4
-rw-r--r--rtemsspec/tests/test_content_sphinx.py3
4 files changed, 13 insertions, 7 deletions
diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index bffcacff..98cb5ebe 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -1042,7 +1042,10 @@ def get_value_plural(ctx: ItemGetValueContext) -> Any:
try:
return ctx.value[ctx.key]
except KeyError:
- return f"{ctx.value['term']}s"
+ term = ctx.value["term"]
+ if term.endswith("y"):
+ return f"{term[:-1]}ies"
+ return f"{term}s"
class ExpressionMapper:
diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py
index 5e530ff3..1d72ae7c 100644
--- a/rtemsspec/sphinxcontent.py
+++ b/rtemsspec/sphinxcontent.py
@@ -27,7 +27,8 @@
from contextlib import contextmanager
from typing import Any, Iterable, Iterator, List, Optional, Sequence, Union
-from rtemsspec.content import Content, make_lines, to_camel_case
+from rtemsspec.content import Content, get_value_plural, make_lines, \
+ to_camel_case
from rtemsspec.items import Item, ItemGetValue, ItemGetValueContext, ItemMapper
GenericContent = Union[str, List[str], "Content"]
@@ -203,10 +204,7 @@ def _get_ref_term(ctx: ItemGetValueContext) -> Any:
def _get_ref_term_plural(ctx: ItemGetValueContext) -> Any:
- try:
- return f":term:`{ctx.value[ctx.key]} <{ctx.value['term']}>`"
- except KeyError:
- return f":term:`{ctx.value['term']}s <{ctx.value['term']}>`"
+ return f":term:`{get_value_plural(ctx)} <{ctx.value['term']}>`"
def _get_appl_config_option(ctx: ItemGetValueContext) -> Any:
diff --git a/rtemsspec/tests/spec-sphinx/z.yml b/rtemsspec/tests/spec-sphinx/z.yml
new file mode 100644
index 00000000..d8fcbe80
--- /dev/null
+++ b/rtemsspec/tests/spec-sphinx/z.yml
@@ -0,0 +1,4 @@
+term: z
+glossary-type: term
+links: []
+type: glossary
diff --git a/rtemsspec/tests/test_content_sphinx.py b/rtemsspec/tests/test_content_sphinx.py
index 85d1e151..20fa258a 100644
--- a/rtemsspec/tests/test_content_sphinx.py
+++ b/rtemsspec/tests/test_content_sphinx.py
@@ -296,7 +296,8 @@ def test_substitute(tmpdir):
with pytest.raises(ValueError, match=match):
mapper.substitute("${x:/y}")
assert mapper.substitute("${x:/term}") == ":term:`y`"
- assert mapper.substitute("${x:/plural}") == ":term:`ys <y>`"
+ assert mapper.substitute("${x:/plural}") == ":term:`ies <y>`"
+ assert mapper.substitute("${z:/plural}") == ":term:`zs <z>`"
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`"