Skip to content

Commit 6d4102a

Browse files
authored
Add project API version on each HTML page. (#936)
Fixes #333
1 parent cac4486 commit 6d4102a

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ in development
7474
^^^^^^^^^^^^^^
7575

7676
* Allow suppressing the footer's buildtime altogether with option ``--buildtime=no``.
77+
* Add project version on each HTML page.
7778

7879
pydoctor 25.10.1
7980
^^^^^^^^^^^^^^^^

pydoctor/templatewriter/pages/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def slot_map(self) -> Dict[str, "Flattenable"]:
272272

273273
return dict(
274274
project=project_tag,
275+
project_version=f' {system.options.projectversion}' if system.options.projectversion else '',
275276
pydoctor_version=__version__,
276277
)
277278

pydoctor/test/test_templatewriter.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,45 @@ def test_index_contains_infos(tmp_path: Path, theme: str) -> None:
674674
for i in infos:
675675
assert i in page, page
676676

677+
@theme_param
678+
def test_project_version_shown_in_footer(tmp_path: Path, theme:str) -> None:
679+
"""
680+
Verify that when a project name and project version are provided, the
681+
generated HTML footer shows the project version.
682+
"""
683+
system = model.System(model.Options.from_args([
684+
'--project-version', '1.2.3',
685+
]))
686+
687+
builder = system.systemBuilder(system)
688+
builder.addModule(testpackages / "allgames")
689+
builder.addModule(testpackages / "basic")
690+
builder.buildModules()
691+
692+
w = writer.TemplateWriter(tmp_path, _template_lookup(theme))
693+
w.writeSummaryPages(system)
694+
695+
assert '1.2.3' in (tmp_path / 'index.html').read_text(encoding='utf-8')
696+
697+
@theme_param
698+
def test_project_version_is_None_not_in_footer(tmp_path: Path, theme:str) -> None:
699+
"""
700+
Verify that when a project version is NOT provided, the
701+
generated HTML footer doesn't show 'None' as the version.
702+
"""
703+
system = model.System(model.Options.from_args([]))
704+
705+
builder = system.systemBuilder(system)
706+
builder.addModule(testpackages / "allgames")
707+
builder.addModule(testpackages / "basic")
708+
builder.buildModules()
709+
710+
w = writer.TemplateWriter(tmp_path, _template_lookup(theme))
711+
w.writeSummaryPages(system)
712+
713+
assert 'API Documentation</a> for my project,\n' in (
714+
tmp_path / 'index.html').read_text(encoding='utf-8')
715+
677716
@pytest.mark.parametrize('_order', ["alphabetical", "source"])
678717
def test_objects_order_mixed_modules_and_packages(_order:str) -> None:
679718
"""

pydoctor/themes/base/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<meta name="pydoctor-template-version" content="4" />
44
<div class="container-fluid">
5-
<a href="index.html">API Documentation</a> for <t:slot name="project" />,
5+
<a href="index.html">API Documentation</a> for <t:slot name="project" /><t:slot name="project_version" />,
66
generated by <a href="https://github.com/twisted/pydoctor/">pydoctor</a>
77
<t:slot name="pydoctor_version" /><t:transparent fmt=" at %Y-%m-%d %H:%M:%S" t:render="buildtime" />
88
</div>

pydoctor/themes/readthedocs/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<meta name="pydoctor-template-version" content="4" />
44

55
<div class="container-fluid">
6-
<a href="index.html">API Documentation</a> for <t:slot name="project" />,
6+
<a href="index.html">API Documentation</a> for <t:slot name="project" /><t:slot name="project_version" />,
77
generated by <a href="https://github.com/twisted/pydoctor/">pydoctor</a>
88
<t:slot name="pydoctor_version" /><t:transparent fmt=" at %Y-%m-%d %H:%M:%S" t:render="buildtime" />
99
</div>

0 commit comments

Comments
 (0)