Concepts
Plug-ins
A product creates a registry and registers plug-ins on it. There is no global registry.
const registry = createRegistry()
registry.use(myPlugin)A plug-in is a plain object. It declares its name, version, the Culm API versions it supports (api, currently [2]), when it runs and its trust tier, and it may carry:
Field
What it adds
Field
blocks
What it adds
Ready-made sections, described below
Field
sources
What it adds
Data sources: a name, the fields of a row and sample rows
Field
rules
What it adds
Extra validation. A rule is a named function from a document to a list of problems
Field
kinds
What it adds
Extra node kinds
Field
settingFns
What it adds
Named functions for the rare block setting that cannot be declared as data
Field
toolScript
What it adds
The script of a site's declared tools: one per site, in-page
Registering two things under one name is an error.
Blocks
A block has an id, a version, a name, a category and a list of looks. A look is a fixed tree of core nodes. insertBlock copies a look's tree into the site, gives every node its own id and tags the root with the block's name and version. From then on the nodes belong to the site, and each one can be edited on its own. A stored site never points back at a block.
A block's settings are data. A setting has a key, a label, a type and a list of actions:
Action
Does
Action
set
Does
Writes the value to one or more paths in the tree
Action
choose
Does
Each option maps to a bundle of writes and removals. Keys owned by any option are cleared first
Action
show
Does
Hides or shows named nodes depending on whether the value is empty
Action
filter
Does
Sets a list's filter to a field and value
applySetting validates the value, runs the actions and returns a new tree. readSettings reads the current values back from the same declaration. One setting can serve looks with different parts: a path whose node a look does not have is skipped.
Because a block with no functions is only data, it can be written as JSON.
Data
A list node repeats its child over the rows of a named source. The query lives in the tree: filter, exclude, sort, skip, limit, group and nested repeats over a row's own collection. Text and settings can bind to a field of the current row or to a single value.
Culm never fetches. The caller passes the rows:
compilePage(site, pageId, {
registry,
data: {
rows: { projects: [{ title: 'Alpha', years: '2024' }] },
values: { 'has.projects': true },
},
})Rows are checked against the source's declared fields before anything compiles.
Validation
const problems = validateSite(doc, registry)validateSite checks the shape of the document, every tree (kinds, settings, styles per kind, which kinds may sit where, ids, limits, bindings against the data sources, component references and cycles), fonts and named styles, and then runs every registered rule. It returns a list and does not throw.
A problem has a stable code, a message, and where they apply a nodeId, a path to the field, the allowed values and the rule that raised it.
Code
Means
Code
INVALID_DOCUMENT
Means
The document's shape, version or a site-level value is wrong
Code
INVALID_NODE
Means
A node's field, id, style or position is wrong
Code
UNKNOWN_KIND
Means
A node's kind is not registered
Code
UNKNOWN_COMPONENT
Means
An instance points at a component that is missing
Code
UNKNOWN_BLOCK
Means
A block or look is not registered
Code
UNKNOWN_SOURCE
Means
A list or binding names a data source or field that is not registered
Code
RESOURCE_LIMIT_EXCEEDED
Means
A node, depth or byte ceiling was passed
Code
POLICY_VIOLATION
Means
A product's own rule refused the document
Code
FETCH_FAILED
Means
A font or icon could not be fetched
Wording may change. Codes keep their meaning.
A field or setting that Culm does not know, or does not act on yet, is refused. Nothing is dropped silently.
Previous
Next