Skip to content

Commit 7674a8f

Browse files
committed
Updated docs to use jinja template for component doc links
1 parent d4474e2 commit 7674a8f

File tree

3 files changed

+72
-92
lines changed

3 files changed

+72
-92
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% if current_project != 'the labscript suite' %}
2+
.. toctree::
3+
:maxdepth: 2
4+
:hidden:
5+
6+
The labscript suite <{{intersphinx_mapping['labscript-suite'][0]}}>
7+
8+
{% endif %}
9+
*labscript suite* components
10+
============================
11+
12+
The *labscript suite* is modular by design, and is comprised of:
13+
14+
.. list-table:: Python libraries
15+
:widths: 10 90
16+
:header-rows: 0
17+
18+
{% for prog, item in programs.items() if item.type == 'lib' %}
19+
* - .. image:: {{item.img}}
20+
:target: {{intersphinx_mapping['%s' | format(prog)][0]}}
21+
:class: labscript-suite-icon
22+
- |{{prog}}|_ --- {{item.desc}}
23+
{% endfor %}
24+
25+
.. list-table:: Graphical applications
26+
:widths: 10 90
27+
:header-rows: 0
28+
29+
{% for prog, item in programs.items() if item.type == 'gui' %}
30+
* - .. image:: {{item.img}}
31+
:target: {{intersphinx_mapping['%s' | format(prog)][0]}}
32+
:class: labscript-suite-icon
33+
- |{{prog}}|_ --- {{item.desc}}
34+
{% endfor %}
35+
36+
.. toctree::
37+
:maxdepth: 2
38+
:hidden:
39+
40+
{% for prog in programs|sort if prog != current_project %}
41+
{{prog}} <{{intersphinx_mapping['%s' | format(prog)][0]}}>
42+
{% endfor %}
43+
44+
{% for prog in programs %}
45+
.. |{{prog}}| replace:: **{{prog}}**
46+
.. _{{prog}}: {{intersphinx_mapping['%s' | format(prog)][0]}}
47+
{% endfor %}

docs/source/conf.py

Lines changed: 11 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pathlib import Path
1515
from m2r import MdInclude
1616
from recommonmark.transform import AutoStructify
17+
from jinja2 import FileSystemLoader, Environment
1718

1819
# -- Project information (unique to each project) -------------------------------------
1920

@@ -186,59 +187,6 @@
186187
# Customize the html_theme
187188
html_theme_options = {'navigation_depth': 3}
188189

189-
# Template for generating the components.rst file
190-
# fmt:off
191-
components_rst_template = \
192-
"""
193-
{metapackage_toctree}
194-
195-
*labscript suite* components
196-
============================
197-
198-
The *labscript suite* is modular by design, and is comprised of:
199-
200-
.. list-table:: Python libraries
201-
:widths: 10 90
202-
:header-rows: 0
203-
204-
{lib}
205-
206-
.. list-table:: Graphical applications
207-
:widths: 10 90
208-
:header-rows: 0
209-
210-
{gui}
211-
212-
.. toctree::
213-
:maxdepth: 2
214-
:hidden:
215-
216-
{toctree_entires}
217-
218-
{rst_defs}
219-
"""
220-
221-
components_rst_table_template = \
222-
""" * - .. image:: {img}
223-
:target: {target}
224-
:class: labscript-suite-icon
225-
- |{prog}|_ --- {desc}
226-
"""
227-
228-
components_rst_link_template = \
229-
""".. |{prog}| replace:: **{prog}**
230-
.. _{prog}: {target}
231-
"""
232-
233-
components_rst_metapackage_template = \
234-
""".. toctree::
235-
:maxdepth: 2
236-
:hidden:
237-
238-
Metapackage documentation <{}>
239-
"""
240-
# fmt:on
241-
242190
# Use m2r only for mdinclude and recommonmark for everything else
243191
# https://github.com/readthedocs/recommonmark/issues/191#issuecomment-622369992
244192
def setup(app):
@@ -260,43 +208,14 @@ def setup(app):
260208

261209
# generate the components.rst file dynamically so it points to stable/latest
262210
# of subprojects correctly
263-
components_rst_table = {
264-
"lib": "",
265-
"gui": "",
266-
}
267-
components_rst_link = ""
268-
components_rst_toctree = ""
269-
components_rst_metapackage = ""
270-
if project != 'the labscript suite':
271-
components_rst_metapackage = components_rst_metapackage_template.format(
272-
intersphinx_mapping['labscript-suite'][0]
273-
)
274-
metapackage_img = img_path + "/labscript-suite-rectangular-transparent_138nx70n.svg"
275-
for ls_prog, data in labscript_suite_programs.items():
276-
components_rst_table[data['type']] += components_rst_table_template.format(
277-
prog=ls_prog,
278-
labscript_suite_doc_version=labscript_suite_doc_version,
279-
target=intersphinx_mapping[ls_prog][0],
280-
**data
281-
)
282-
components_rst_link += components_rst_link_template.format(
283-
prog=ls_prog,
284-
labscript_suite_doc_version=labscript_suite_doc_version,
285-
target=intersphinx_mapping[ls_prog][0],
286-
)
287-
for ls_prog in sorted(labscript_suite_programs):
288-
if ls_prog != project:
289-
components_rst_toctree += " {} <{}>\n".format(
290-
ls_prog, intersphinx_mapping[ls_prog][0]
291-
)
292-
293-
components_rst = components_rst_template.format(
294-
toctree_entires=components_rst_toctree,
295-
rst_defs=components_rst_link,
296-
labscript_suite_doc_version=labscript_suite_doc_version,
297-
metapackage_toctree=components_rst_metapackage,
298-
**components_rst_table
299-
)
300-
211+
loader = FileSystemLoader(Path(__file__).resolve().parent / templates_path[0])
212+
env = Environment(loader=loader)
213+
template = env.get_template('components.rst')
301214
with open(Path(__file__).resolve().parent / 'components.rst', 'w') as f:
302-
f.write(components_rst)
215+
f.write(
216+
template.render(
217+
intersphinx_mapping=intersphinx_mapping,
218+
programs=labscript_suite_programs,
219+
current_project=project,
220+
)
221+
)

docs/source/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@
1515
introduction
1616
connection_table
1717
api_reference/index
18+
19+
.. toctree::
20+
:maxdepth: 2
21+
:hidden:
22+
:caption: FURTHER DOCUMENTATION
23+
1824
components
25+
26+
.. toctree::
27+
:maxdepth: 2
28+
:hidden:
29+
:caption: LINKS
30+
1931
Home Page <http://labscriptsuite.org>
2032
Source Code <https://github.com/labscript-suite/labscript>
2133
BitBucket Archive <http://bitbucket-archive.labscriptsuite.org/#!/labscript_suite/labscript>
2234

35+
.. todolist::
36+
2337

0 commit comments

Comments
 (0)