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.

property label: str

The localized, human-readable label.

property resource_url: 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.

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)
property breadcrumbs: Breadcrumbs

The breadcrumbs.

property citer: Citer

The citer.

property context: 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.

property entity_contexts: EntityContexts

The entity contexts.

property localizer: Localizer

The localizer.

property media_type: MediaType | None

The media type.

property resource: object

The resource itself.

property resource_url: object

The URL-generatable version of the resource itself.

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

property title: 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.

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