Skip to content

Commit ace6510

Browse files
committed
puml_utils: add shared PlantUML RST wrapper
1 parent 88c12bc commit ace6510

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

bazel/rules/rules_score/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ exports_files([
2929
"templates/unit.template.rst",
3030
"templates/component.template.rst",
3131
"templates/fmea.template.rst",
32+
"templates/puml_diagram.template.rst",
3233
])
3334

3435
compile_pip_requirements(
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
"""Shared helper for generating RST wrapper pages for PlantUML diagram files."""
15+
16+
def make_puml_rst_wrappers(ctx, puml_files, output_dir, template, strip_prefix = "", filename_prefix = ""):
17+
"""Generate a thin RST wrapper page for each PlantUML diagram file.
18+
19+
The wrapper embeds the diagram via ``.. uml::`` so it appears as a
20+
proper toctree entry while keeping the source ``.puml`` file separate.
21+
22+
Args:
23+
ctx: Rule context.
24+
puml_files: Iterable of File objects whose extension is ``puml`` or
25+
``plantuml``.
26+
output_dir: String prefix for declared output files
27+
(e.g. ``ctx.label.name``).
28+
template: The ``puml_diagram.template.rst`` File (from
29+
``ctx.file._puml_rst_template``).
30+
strip_prefix: Optional filename stem prefix to strip before deriving
31+
the human-readable title (e.g. ``"fta_"``).
32+
filename_prefix: Optional prefix prepended to the output RST filename
33+
stem (e.g. ``"detail_"``).
34+
35+
Returns:
36+
List of declared ``.rst`` output Files, one per input diagram.
37+
"""
38+
wrappers = []
39+
for f in puml_files:
40+
if f.extension not in ("puml", "plantuml"):
41+
continue
42+
stem = f.basename[:-(len(f.extension) + 1)]
43+
if strip_prefix and stem.startswith(strip_prefix):
44+
stem = stem[len(strip_prefix):]
45+
title = stem.replace("_", " ").title()
46+
wrapper = ctx.actions.declare_file(
47+
"{}/{}{}.rst".format(output_dir, filename_prefix, stem),
48+
)
49+
ctx.actions.expand_template(
50+
template = template,
51+
output = wrapper,
52+
substitutions = {
53+
"{title}": title,
54+
"{underline}": "=" * len(title),
55+
"{basename}": f.basename,
56+
},
57+
)
58+
wrappers.append(wrapper)
59+
return wrappers
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
14+
15+
{title}
16+
{underline}
17+
18+
.. uml:: {basename}

0 commit comments

Comments
 (0)