htmy.renderer.default
Renderer
The default renderer.
It resolves component trees by converting them to a linked list of resolved component parts before combining them to the final string.
Source code in htmy/renderer/default.py
__init__(default_context=None, *, string_formatter=xml_format_string)
Initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default_context
|
Context | None
|
The default context to use for rendering if |
None
|
string_formatter
|
Callable[[str], str]
|
Callable that should be used to format plain strings. By default an XML-safe string formatter will be used. |
xml_format_string
|
Source code in htmy/renderer/default.py
render(component, context=None)
async
Renders the given component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
Component
|
The component to render. |
required |
context
|
Context | None
|
An optional rendering context. |
None
|
Returns:
Type | Description |
---|---|
str
|
The rendered string. |
Source code in htmy/renderer/default.py
_ComponentRenderer
ComponentType
renderer that converts a component tree into a linked list of resolved (str
) nodes.
Source code in htmy/renderer/default.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
_async_todos = deque()
instance-attribute
Async node - context tuples that need to be rendered.
_error_boundary_todos = deque()
instance-attribute
Node context tuples where node.component
is an ErrorBoundary
.
_root = root
instance-attribute
The root node in the linked list the renderer constructs.
_string_formatter = string_formatter
instance-attribute
The string formatter to use.
_sync_todos = deque()
instance-attribute
Sync node - context tuples that need to be rendered (node.component
is an HTMYComponentType
).
__init__(component, context, *, string_formatter)
Initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
ComponentType
|
The component to render. |
required |
context
|
Context
|
The base context to use for rendering the component. |
required |
string_formatter
|
Callable[[str], str]
|
The string formatter to use. |
required |
Source code in htmy/renderer/default.py
_extend_context(component, context)
async
Returns a new context from the given component and context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
ContextProvider
|
A |
required |
context
|
Context
|
The current rendering context. |
required |
Source code in htmy/renderer/default.py
_process_async_node(node, context)
async
Processes the given node. node.component
must be an async component.
Source code in htmy/renderer/default.py
_process_error_boundary(node, context)
async
Processes a single node whose component is an ErrorBoundary
.
Source code in htmy/renderer/default.py
_process_node_result(parent_node, component, context)
Processes the result of a single node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_node
|
_Node
|
The node that was resolved. |
required |
component
|
Component
|
The (awaited if async) result of |
required |
context
|
Context
|
The context that was used for rendering |
required |
Source code in htmy/renderer/default.py
_schedule_node(node, child_context)
Schedules the given node for rendering with the given child context.
node.component
must be an HTMYComponentType
(single component and not str
).
Source code in htmy/renderer/default.py
run()
async
Runs the component renderer.
Source code in htmy/renderer/default.py
_Node
A single node in the linked list the renderer constructs to resolve a component tree.
Source code in htmy/renderer/default.py
__init__(component, next=None)
Initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
ComponentType
|
The component in this node. |
required |
next
|
_Node | None
|
The next component in the list, if there is one. |
None
|
Source code in htmy/renderer/default.py
iter_nodes(*, include_self=True)
Iterates over all following nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_self
|
bool
|
Whether the node on which this method is called should also be included in the iterator. |
True
|
Source code in htmy/renderer/default.py
_render_component(component, *, context, string_formatter)
async
Renders the given component with the given settings.