[rtems-central commit] glossary: Support custom glossary headers
Sebastian Huber
sebh at rtems.org
Mon Oct 26 13:09:22 UTC 2020
Module: rtems-central
Branch: master
Commit: 4fe26dc8759fd8cd71c86c20ee594768f01bd222
Changeset: http://git.rtems.org/rtems-central/commit/?id=4fe26dc8759fd8cd71c86c20ee594768f01bd222
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Oct 26 13:54:43 2020 +0100
glossary: Support custom glossary headers
---
config.yml | 4 +++-
rtemsspec/glossary.py | 20 +++++++++++---------
rtemsspec/tests/test_glossary.py | 6 ++++--
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/config.yml b/config.yml
index 07684cd..b9257dd 100644
--- a/config.yml
+++ b/config.yml
@@ -52,9 +52,11 @@ spec:
glossary:
project-groups:
- /glossary-general
+ project-header: Glossary
project-target: modules/rtems-docs/c-user/glossary.rst
documents:
- - rest-source-paths:
+ - header: Glossary
+ rest-source-paths:
- modules/rtems-docs/eng
target: modules/rtems-docs/eng/glossary.rst
appl-config:
diff --git a/rtemsspec/glossary.py b/rtemsspec/glossary.py
index 0ac150e..1a7a18c 100644
--- a/rtemsspec/glossary.py
+++ b/rtemsspec/glossary.py
@@ -50,9 +50,10 @@ def _gather_glossary_terms(item: Item, glossary: _Glossary) -> None:
glossary.term_to_item[term] = item
-def _generate_glossary_content(terms: ItemMap) -> SphinxContent:
+def _generate_glossary_content(terms: ItemMap, header: str,
+ target: str) -> None:
content = SphinxContent()
- content.add_header("Glossary", level=1)
+ content.add_header(header, level=1)
content.add(".. glossary::")
with content.indent():
content.add(":sorted:")
@@ -61,7 +62,7 @@ def _generate_glossary_content(terms: ItemMap) -> SphinxContent:
text = SphinxMapper(item).substitute(item["text"])
content.add_definition_item(item["term"], text)
content.add_licence_and_copyrights()
- return content
+ content.write(target)
_TERM = re.compile(r":term:`([^`]+)`")
@@ -103,9 +104,9 @@ def _resolve_glossary_terms(document_terms: ItemMap) -> None:
_GlossaryMapper(term, document_terms).substitute(term["text"])
-def _generate_project_glossary(target: str, glossary: _Glossary) -> None:
- content = _generate_glossary_content(glossary.uid_to_item)
- content.write(target)
+def _generate_project_glossary(glossary: _Glossary, header: str,
+ target: str) -> None:
+ _generate_glossary_content(glossary.uid_to_item, header, target)
def _generate_document_glossary(config: dict, glossary: _Glossary) -> None:
@@ -113,8 +114,8 @@ def _generate_document_glossary(config: dict, glossary: _Glossary) -> None:
for path in config["rest-source-paths"]:
_find_glossary_terms(path, document_terms, glossary)
_resolve_glossary_terms(document_terms)
- content = _generate_glossary_content(document_terms)
- content.write(config["target"])
+ _generate_glossary_content(document_terms, config["header"],
+ config["target"])
def generate(config: dict, item_cache: ItemCache) -> None:
@@ -134,7 +135,8 @@ def generate(config: dict, item_cache: ItemCache) -> None:
for group in config["project-groups"]:
_gather_glossary_terms(groups[group], project_glossary)
- _generate_project_glossary(config["project-target"], project_glossary)
+ _generate_project_glossary(project_glossary, config["project-header"],
+ config["project-target"])
for document_config in config["documents"]:
_generate_document_glossary(document_config, project_glossary)
diff --git a/rtemsspec/tests/test_glossary.py b/rtemsspec/tests/test_glossary.py
index 2682b5d..030e215 100644
--- a/rtemsspec/tests/test_glossary.py
+++ b/rtemsspec/tests/test_glossary.py
@@ -38,9 +38,11 @@ def test_glossary(tmpdir):
glossary_config = {}
glossary_config["project-groups"] = ["/g"]
+ glossary_config["project-header"] = "Project Glossary"
project_glossary = os.path.join(tmpdir, "project", "glossary.rst")
glossary_config["project-target"] = project_glossary
doc = {}
+ doc["header"] = "Glossary"
doc["rest-source-paths"] = [str(tmpdir)]
document_glossary = os.path.join(tmpdir, "document", "glossary.rst")
doc["target"] = document_glossary
@@ -52,8 +54,8 @@ def test_glossary(tmpdir):
.. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
-Glossary
-********
+Project Glossary
+****************
.. glossary::
:sorted:
More information about the vc
mailing list