[rtems-central commit] content: Improve plural of terms

Sebastian Huber sebh at rtems.org
Wed May 12 19:05:11 UTC 2021


Module:    rtems-central
Branch:    master
Commit:    0174da56742c82322d5c04167bf76b217903247d
Changeset: http://git.rtems.org/rtems-central/commit/?id=0174da56742c82322d5c04167bf76b217903247d

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed May 12 14:05:05 2021 +0200

content: Improve plural of terms

---

 rtemsspec/content.py                   | 5 ++++-
 rtemsspec/sphinxcontent.py             | 8 +++-----
 rtemsspec/tests/spec-sphinx/z.yml      | 4 ++++
 rtemsspec/tests/test_content_sphinx.py | 3 ++-
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index bffcacf..98cb5eb 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 5e530ff..1d72ae7 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 0000000..d8fcbe8
--- /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 85d1e15..20fa258 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`"



More information about the vc mailing list