betty.document module

Manage documents.

A document is a singular file, such as an HTML page or a JSON file.

final class betty.document.Breadcrumb

Bases: LinkedDataDumpable[PortableMapping]

A breadcrumb.

__init__(label: str, resource: object | None, /)
async dump_linked_data(project: Project, /) PortableMapping

Dump this instance to JSON-LD.

label: Final[str]

The localized, human-readable label.

resource_url: Final[object | None]

The resource URL.

final class betty.document.Breadcrumbs

Bases: LinkedDataDumpable[PortableMapping], Iterable[Breadcrumb], Sized

A trail of navigational breadcrumbs.

__init__()
append(label: str, resource_url: object | None = None, /) None

Append a breadcrumb to the trail.

async dump_linked_data(project: Project, /) PortableMapping

Dump this instance to JSON-LD.

final class betty.document.Citer

Bases: object

Track citations when they are first used.

__init__()
cite(citation: Citation, /) int

Reference a citation.

Returns:

The citation’s sequential reference number.

final class betty.document.Document

Bases: object

A document.

__init__(resource: object = None, resource_url: object = None, /, *, breadcrumbs: Breadcrumbs | None = None, citer: Citer | None = None, entity_contexts: EntityContexts | None = None, context: Context | None = None, localizer: Localizer | None = None, media_type: ResolvableMediaType | None = None, title: Localizable | None = None, **document_vars: Any)
breadcrumbs: Final[Breadcrumbs]

The breadcrumbs.

citer: Final[Citer]

The citer.

context: Final[Context | None]

The job context.

copy(*, media_type: ResolvableMediaType | None = None, resource: object = None, resource_url: object = None, **document_vars: Any) Self

Create a copy of this document, with the given fields added.

entity_contexts: Final[EntityContexts]

The entity contexts.

localizer: Final[Localizer]

The localizer.

media_type: Final[MediaType | None]

The media type.

resource: Final[object]

The resource itself.

resource_url: Final[object]

The URL-generatable version of the resource itself.

This may be the resource itself or a completely different type of value.

title: Final[Localizable | None]

The human-readable title.

class betty.document.DocumentProvider

Bases: Plugin[DocumentProviderDefinition]

Provide new documents.

new_document_vars() DocumentVars

Create new variables for a new betty.document.Document.

Keys are the variable names, and values are variable values.

final class betty.document.DocumentProviderDefinition

Bases: PluginClsDefinition[DocumentProvider]

The document provider plugin type.

Plugin type ID

document-provider

Definition

@DocumentProviderDefinition(...)

Built-in document providers:

webpack (Webpack)
__init__(plugin_id: ResolvableMachineName, *, auto: bool = False, requires: Requires = ())
static type() PluginTypeDefinition[Self]

The plugin type definition.

final class betty.document.DocumentProviderManufacturer

Bases: PluginManufacturer[DocumentProviderDefinition, DocumentProvider]

The document provider manufacturer.

final class betty.document.EntityContexts

Bases: object

Track the current entity contexts.

To allow templates to respond to their environment, this class allows our templates to set and get one entity per entity type for the current context.

Use cases include rendering an entity label as plain text if the template is in that entity’s context, but as a hyperlink if the template is not in the entity’s context.

__init__(*entities: Entity) None