Module

context

Content-aware context mapping for Patitas AST nodes.

Maps AST node types to the template context paths they affect. This defines how content structure maps to template variables, enabling reactive systems (like Purr) to determine which template blocks need re-rendering when specific content nodes change.

The mapping is conservative — it may over-identify affected context paths (causing unnecessary re-renders) but never under-identify (causing stale content). When a node type isn't in the map, the fallback covers it.

Example:

from patitas.context import context_paths_for
from patitas.nodes import Heading

paths = context_paths_for(heading_node)
# frozenset({"page.toc", "page.headings", "page.body"})

Thread Safety:

All data is immutable (frozensets). Safe to call from any thread.

Functions

context_paths_for 1 frozenset[str]
Return the template context paths affected by this node type. Uses the node's …
def context_paths_for(node: Node) -> frozenset[str]

Return the template context paths affected by this node type.

Uses the node's class name to look up affected paths. Returns the conservative fallback for unknown node types.

Parameters
Name Type Description
node Node

Any Patitas AST node.

Returns
frozenset[str]