Skip to content

Commit 5349902

Browse files
kartbenaescolar
authored andcommitted
doc: boards: extensions: store board_catalog in Sphinx domain
Load the board catalog only once at build-inited time so that it's cached and enabled things like boards, vendors, and socs to eventually become first class Sphinx objects. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent f75f2bf commit 5349902

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

doc/_extensions/zephyr/domain/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,16 @@ def run(self):
578578
if self.env.app.builder.format == "html":
579579
self.env.domaindata["zephyr"]["has_board_catalog"][self.env.docname] = True
580580

581-
# As it is not expected that more than one board-catalog directive is used across
582-
# the documentation, and since the generation is only taking a few seconds, we don't
583-
# store the catalog in the domain data. It might change in the future if the generation
584-
# becomes more expensive.
585-
board_catalog = get_catalog()
581+
domain_data = self.env.domaindata["zephyr"]
586582
renderer = SphinxRenderer([TEMPLATES_DIR])
587-
rendered = renderer.render("board-catalog.html", {"catalog": board_catalog})
583+
rendered = renderer.render(
584+
"board-catalog.html",
585+
{
586+
"boards": domain_data["boards"],
587+
"vendors": domain_data["vendors"],
588+
"socs": domain_data["socs"],
589+
},
590+
)
588591
return [nodes.raw("", rendered, format="html")]
589592
else:
590593
return [nodes.paragraph(text="Board catalog is only available in HTML.")]
@@ -804,6 +807,13 @@ def install_static_assets_as_needed(
804807
app.add_js_file("js/board-catalog.js")
805808

806809

810+
def load_board_catalog_into_domain(app: Sphinx) -> None:
811+
board_catalog = get_catalog()
812+
app.env.domaindata["zephyr"]["boards"] = board_catalog["boards"]
813+
app.env.domaindata["zephyr"]["vendors"] = board_catalog["vendors"]
814+
app.env.domaindata["zephyr"]["socs"] = board_catalog["socs"]
815+
816+
807817
def setup(app):
808818
app.add_config_value("zephyr_breathe_insert_related_samples", False, "env")
809819

@@ -820,6 +830,8 @@ def setup(app):
820830
"builder-inited",
821831
(lambda app: app.config.html_static_path.append(RESOURCES_DIR.as_posix())),
822832
)
833+
app.connect("builder-inited", load_board_catalog_into_domain)
834+
823835
app.connect("html-page-context", install_static_assets_as_needed)
824836
app.connect("env-updated", compute_sample_categories_hierarchy)
825837

doc/_extensions/zephyr/domain/templates/board-card.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
data-vendor="{{ board.vendor }}"
1717
data-socs="{{ board.socs | join(" ") }}"
1818
tabindex="0">
19-
<div class="vendor">{{ catalog.vendors[board.vendor] }}</div>
19+
<div class="vendor">{{ vendors[board.vendor] }}</div>
2020
{% if board.image -%}
2121
<img alt="A picture of the {{ board.full_name }} board"
2222
src="../_images/{{ board.image.split('/')[-1] }}" class="picture" />

doc/_extensions/zephyr/domain/templates/board-catalog.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
<option value="" disabled selected>Select a vendor</option>
3939
{# Only show those vendors that have actual boards in the catalog.
4040
Note: as sorting per vendor name is not feasible in Jinja, the option list is sorted in the JavaScript code later #}
41-
{% for vendor in (catalog.boards | items | map(attribute='1.vendor') | unique ) -%}
42-
<option value="{{ vendor }}">{{ catalog.vendors[vendor] }}</option>
41+
{% for vendor in (boards | items | map(attribute='1.vendor') | unique ) -%}
42+
<option value="{{ vendor }}">{{ vendors[vendor] }}</option>
4343
{% endfor %}
4444
</select>
4545
</div>
@@ -82,11 +82,11 @@
8282
<div id="nb-matches" style="text-align: center"></div>
8383

8484
<div id="catalog">
85-
{% for board_name, board in catalog.boards | items | sort(attribute='1.full_name') -%}
85+
{% for board_name, board in boards | items | sort(attribute='1.full_name') -%}
8686
{% include "board-card.html" %}
8787
{% endfor %}
8888
</div>
8989

9090
<script>
91-
socs_data = {{ catalog.socs | tojson }};
91+
socs_data = {{ socs | tojson }};
9292
</script>

0 commit comments

Comments
 (0)