[rtems-central commit] sphinxcontent: Add add_image()

Sebastian Huber sebh at rtems.org
Tue May 9 13:45:26 UTC 2023


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri May  5 14:41:18 2023 +0200

sphinxcontent: Add add_image()

---

 rtemsspec/sphinxcontent.py             | 12 ++++++++++++
 rtemsspec/tests/test_content_sphinx.py | 16 ++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py
index dd2fb308..f9849fc1 100644
--- a/rtemsspec/sphinxcontent.py
+++ b/rtemsspec/sphinxcontent.py
@@ -105,6 +105,18 @@ class SphinxContent(Content):
         """ Adds a rubric. """
         self.add(f".. rubric:: {name}")
 
+    def add_image(self, base: str, width: Optional[str] = None) -> None:
+        """
+        Adds an image associated with the base file name.
+
+        The image will have the optional width.
+        """
+        options = [":align: center"]
+        if width is not None:
+            options.append(f":width: {width}")
+        with self.directive("image", base, options):
+            pass
+
     def add_index_entries(self, entries) -> None:
         """ Adds a list of index entries the content. """
         self.add([".. index:: " + entry for entry in make_lines(entries)])
diff --git a/rtemsspec/tests/test_content_sphinx.py b/rtemsspec/tests/test_content_sphinx.py
index 2176b332..82312157 100644
--- a/rtemsspec/tests/test_content_sphinx.py
+++ b/rtemsspec/tests/test_content_sphinx.py
@@ -191,6 +191,22 @@ def test_append():
 """
 
 
+def test_add_image():
+    content = SphinxContent()
+    content.add_image("abc")
+    assert str(content) == """.. image:: abc
+    :align: center
+"""
+    content.add_image("def", "50%")
+    assert str(content) == """.. image:: abc
+    :align: center
+
+.. image:: def
+    :align: center
+    :width: 50%
+"""
+
+
 def test_add_index_entries():
     content = SphinxContent()
     content.add_index_entries(["x", "y"])



More information about the vc mailing list