httk.serve.web.widgets.core¶
The public contracts for static httk-serve widgets.
Attributes¶
Largest individual trusted widget asset accepted by |
|
The deliberately small content-type vocabulary for internal widget assets. |
|
Classes¶
Declare an immutable, deployment-relative asset from trusted widget code. |
|
Provide immutable request and page information to a widget. |
|
Return explicitly trusted HTML and its declared widget assets. |
|
Define the advanced immutable widget protocol. |
|
Adapt a module-level |
|
Register built-in widgets whose aliases do not resolve site widgets. |
Functions¶
|
Wrap a callable as a |
|
Mark a widget's reviewed HTML output as trusted. |
Module Contents¶
- httk.serve.web.widgets.core.MAX_WIDGET_ASSET_BYTES = 1000000[source]¶
Largest individual trusted widget asset accepted by
WidgetAsset.
- httk.serve.web.widgets.core.SUPPORTED_WIDGET_ASSET_CONTENT_TYPES[source]¶
The deliberately small content-type vocabulary for internal widget assets.
- class httk.serve.web.widgets.core.WidgetAsset[source]¶
Declare an immutable, deployment-relative asset from trusted widget code.
pathis relative to/_httk/serve/assets/and is never interpreted as a filesystem path. The engine serves only assets it has registered while rendering this site instance.- Parameters:
path – Safe path below
/_httk/serve/assets/.content – Immutable asset bytes.
content_type – Supported asset content type.
- class httk.serve.web.widgets.core.WidgetContext[source]¶
Provide immutable request and page information to a widget.
- Parameters:
route – Route containing the widget.
render_mode –
servefor live rendering orpublishfor static output.widget_id – Stable identifier for this widget placement.
query – Request query values.
postvars – Parsed request body values.
page – Page metadata and context.
source_path – Source file containing the widget invocation.
url_for – Builder for site-relative URLs.
absolute_url_for – Builder for absolute site URLs.
table_runtime – Engine-local table runtime when available.
- query: collections.abc.Mapping[str, str][source]¶
- postvars: collections.abc.Mapping[str, str][source]¶
- source_path: pathlib.Path[source]¶
- url_for: collections.abc.Callable[[str], str][source]¶
- absolute_url_for: collections.abc.Callable[[str], str][source]¶
- class httk.serve.web.widgets.core.WidgetRenderResult[source]¶
Return explicitly trusted HTML and its declared widget assets.
- Parameters:
html – Trusted HTML output.
assets – Immutable assets used by the output.
- assets: tuple[WidgetAsset, Ellipsis] = ()[source]¶
- class httk.serve.web.widgets.core.Widget[source]¶
Bases:
ProtocolDefine the advanced immutable widget protocol.
- class httk.serve.web.widgets.core.FunctionWidget[source]¶
Adapt a module-level
renderfacade to the widget protocol.- Parameters:
name – Canonical widget name.
render_function – Function used to render the widget.
source – Source identifier for diagnostics and discovery.
- render_function: WidgetRenderer[source]¶
- render(context, **props)[source]¶
Render the widget through its wrapped callable.
- Parameters:
context (WidgetContext) – Immutable widget invocation context.
**props (object) – Literal widget properties.
- Returns:
HTML string or explicitly trusted render result.
- Return type:
- httk.serve.web.widgets.core.function_widget(render, *, name='', source='')[source]¶
Wrap a callable as a
FunctionWidget.Site-local modules normally need no wrapper: a module-level
renderis discovered automatically. The helper is useful for explicit definitions.- Parameters:
render (WidgetRenderer) – Function used to render the widget.
name (str) – Canonical widget name.
source (str) – Source identifier for diagnostics and discovery.
- Returns:
Immutable function-backed widget.
- Return type:
- httk.serve.web.widgets.core.trusted_html(value)[source]¶
Mark a widget’s reviewed HTML output as trusted.
- Parameters:
value (str) – HTML reviewed by the widget author.
- Returns:
Trusted widget render result.
- Return type:
- class httk.serve.web.widgets.core.WidgetRegistry[source]¶
Register built-in widgets whose aliases do not resolve site widgets.
- register(widget, *, alias=None)[source]¶
Register one built-in widget and optional display alias.
- Parameters:
- Raises:
ValueError – If the name or alias is already registered.