Bases: Component
A link card to the page of value, captioned title or the value's folder name.
A link with nowhere to point is an authoring error, so the page fails to
build when value has no position or the page has no at.
for session in target.sessions.values():
cg.ui.PageLink(session)
cg.ui.PageLink(target.sessions.values()[-1].images[2], title="Latest detail")
Source code in capturegraph-lib/capturegraph/ui/page_link.py
| class PageLink(Component):
"""A link card to the page of ``value``, captioned ``title`` or the value's folder name.
A link with nowhere to point is an authoring error, so the page fails to
build when ``value`` has no position or the page has no ``at``.
```python
for session in target.sessions.values():
cg.ui.PageLink(session)
cg.ui.PageLink(target.sessions.values()[-1].images[2], title="Latest detail")
```
"""
value: object
title: str | None = None
def html(self, render: Render) -> str:
"""An ``<a>`` card to the value's page.
Raises:
ValueError: If ``value`` has no position in a target, or the page has no ``at``.
"""
kind = type(self.value).__name__
base = position(self.value)
if base is None:
raise ValueError(
f"PageLink to a {kind} with no position in a target: it was built in memory, "
f"computed by a recipe, or changed since it was loaded"
)
href = render.href(self.value)
if href is None:
raise ValueError(f"PageLink to a {kind}: the page has no `at` to link from")
return element("a", {"class": "cg-link", "href": href}, text(self.title or base.name))
|
html(render)
An <a> card to the value's page.
Raises:
| Type |
Description |
ValueError
|
If value has no position in a target, or the page has no at.
|
Source code in capturegraph-lib/capturegraph/ui/page_link.py
| def html(self, render: Render) -> str:
"""An ``<a>`` card to the value's page.
Raises:
ValueError: If ``value`` has no position in a target, or the page has no ``at``.
"""
kind = type(self.value).__name__
base = position(self.value)
if base is None:
raise ValueError(
f"PageLink to a {kind} with no position in a target: it was built in memory, "
f"computed by a recipe, or changed since it was loaded"
)
href = render.href(self.value)
if href is None:
raise ValueError(f"PageLink to a {kind}: the page has no `at` to link from")
return element("a", {"class": "cg-link", "href": href}, text(self.title or base.name))
|