|
cwist
Modern C web framework with libttak runtime
|
HTML element builder and renderer. More...


Go to the source code of this file.
Classes | |
| struct | cwist_html_element |
Typedefs | |
| typedef struct cwist_html_element | cwist_html_element_t |
Functions | |
Element creation and destruction | |
| cwist_html_element_t * | cwist_html_element_create (const char *tag) |
| Create a new HTML element. | |
| void | cwist_html_element_destroy (cwist_html_element_t *el) |
| Destroy an HTML element and its children. | |
Attribute manipulation | |
| void | cwist_html_element_add_attr (cwist_html_element_t *el, const char *key, const char *value) |
| Add an attribute to an element. | |
| void | cwist_html_element_set_id (cwist_html_element_t *el, const char *id) |
| Set the id attribute. | |
| void | cwist_html_element_add_class (cwist_html_element_t *el, const char *class_name) |
| Add a CSS class. | |
Content and children | |
| void | cwist_html_element_set_text (cwist_html_element_t *el, const char *text) |
| Set inner text. | |
| void | cwist_html_element_add_child (cwist_html_element_t *el, cwist_html_element_t *child) |
| Add a child element. | |
Rendering | |
| cwist_sstring * | cwist_html_render (cwist_html_element_t *el) |
| Render the element tree to an HTML string. | |
HTML element builder and renderer.
Definition in file builder.h.
| void cwist_html_element_add_attr | ( | cwist_html_element_t * | el, |
| const char * | key, | ||
| const char * | value | ||
| ) |
Add an attribute to an element.
Add an attribute to an element.
| el | Element to update. |
| key | Attribute name, for example "class". |
| value | Attribute value stored as a cJSON string node. |
Definition at line 61 of file builder.c.
References cwist_html_element::attributes.
Referenced by cwist_html_element_add_class(), cwist_html_element_set_id(), and cwist_http_response_add_oob().
| void cwist_html_element_add_child | ( | cwist_html_element_t * | el, |
| cwist_html_element_t * | child | ||
| ) |
Add a child element.
Add a child element.
| el | Parent element that will own the child. |
| child | Child node to append. |
Definition at line 124 of file builder.c.
References cwist_html_element::child_count, cwist_html_element::children, and cwist_realloc().
| void cwist_html_element_add_class | ( | cwist_html_element_t * | el, |
| const char * | class_name | ||
| ) |
Add a CSS class.
Add a CSS class.
| el | Element to update. |
| class_name | Class token to append or initialise. |
Definition at line 85 of file builder.c.
References cwist_html_element::attributes, cwist_html_element_add_attr(), cwist_sstring_append(), cwist_sstring_assign(), cwist_sstring_create(), cwist_sstring_destroy(), and cwist_sstring::data.
| cwist_html_element_t * cwist_html_element_create | ( | const char * | tag | ) |
Create a new HTML element.
Create a new HTML element.
| tag | Tag name to copy into the node, such as "div" or "span". |
Definition at line 19 of file builder.c.
References cwist_html_element::attributes, cwist_html_element::child_count, cwist_html_element::children, cwist_alloc(), cwist_sstring_assign(), cwist_sstring_create(), cwist_html_element::inner_text, and cwist_html_element::tag.
| void cwist_html_element_destroy | ( | cwist_html_element_t * | el | ) |
Destroy an HTML element and its children.
Destroy an HTML element and its children.
| el | Element tree root to release. NULL is ignored. |
Definition at line 37 of file builder.c.
References cwist_html_element::attributes, cwist_html_element::child_count, cwist_html_element::children, cwist_free(), cwist_html_element_destroy(), cwist_sstring_destroy(), cwist_html_element::inner_text, and cwist_html_element::tag.
Referenced by cwist_html_component_instantiate(), cwist_html_element_destroy(), cwist_http_response_add_oob(), cwist_http_response_set_html(), and cwist_http_response_set_view().
| void cwist_html_element_set_id | ( | cwist_html_element_t * | el, |
| const char * | id | ||
| ) |
Set the id attribute.
Set the id attribute.
| el | Element to update. |
| id | Identifier value to assign. |
Definition at line 76 of file builder.c.
References cwist_html_element_add_attr().
| void cwist_html_element_set_text | ( | cwist_html_element_t * | el, |
| const char * | text | ||
| ) |
Set inner text.
Set inner text.
| el | Element to update. |
| text | Plain-text payload to store. |
Definition at line 108 of file builder.c.
References cwist_sstring_assign(), cwist_sstring_create(), and cwist_html_element::inner_text.
| cwist_sstring * cwist_html_render | ( | cwist_html_element_t * | el | ) |
Render the element tree to an HTML string.
Void elements (area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr; any letter case) are written as a start tag only: they get no end tag, and text or children attached to them are not rendered.
Render the element tree to an HTML string.
| el | Root element to serialise. |
Definition at line 219 of file builder.c.
References cwist_sstring_assign(), and cwist_sstring_create().