|
supla-device
|
RAII helper for emitting a single HTML tag. More...
#include <web_sender.h>
Public Member Functions | |
| HtmlTag (WebSender *sender, const char *tagName, bool paired=true) | |
| HtmlTag (const HtmlTag &)=delete | |
| HtmlTag & | operator= (const HtmlTag &)=delete |
| HtmlTag (HtmlTag &&other) noexcept | |
| HtmlTag & | operator= (HtmlTag &&other) noexcept |
| HtmlTag & | attr (const char *name, const char *value) |
| Append a quoted HTML attribute with escaped value. | |
| HtmlTag & | attr (const char *name, int value) |
| Append a quoted HTML attribute with integer value. | |
| HtmlTag & | attr (const char *name, int value, int precision) |
| Append a quoted HTML attribute with formatted numeric value. | |
| HtmlTag & | attrIf (const char *name, bool enabled) |
| Append a boolean HTML attribute when enabled. | |
| HtmlTag & | close () |
| Emit the closing > for the opening tag. | |
| HtmlTag & | finish () |
| Close the opening tag and mark it as finished. | |
| template<typename Fn> | |
| void | body (Fn &&fn) |
| Emit a paired body using a callback. | |
| void | body (char *text) |
| Emit a text body using escaped content. | |
| template<size_t N> | |
| void | body (const char(&text)[N]) |
| Emit a text body using escaped content. | |
| void | body (const char *text) |
| Emit a text body using escaped content. | |
| void | end () |
| Explicitly finish the tag. | |
RAII helper for emitting a single HTML tag.
The object starts a tag immediately in the constructor: HtmlTag(sender, "div") emits <div.
Attributes can then be appended with chained calls. The tag is closed by:
Typical usage:
For void elements such as <input>, use WebSender::voidTag().
| HtmlTag & Supla::HtmlTag::attr | ( | const char * | name, |
| int | value, | ||
| int | precision ) |
Append a quoted HTML attribute with formatted numeric value.
This is useful for attributes such as value, min, max or step when the number must be emitted with fixed precision.
| HtmlTag & Supla::HtmlTag::attrIf | ( | const char * | name, |
| bool | enabled ) |
Append a boolean HTML attribute when enabled.
Example: checked, selected, readonly.
|
inline |
Emit a paired body using a callback.
The helper closes the opening tag, executes the callback and then emits the corresponding closing tag.
| void Supla::HtmlTag::end | ( | ) |
Explicitly finish the tag.
For paired tags this emits the closing tag if needed. Calling this is optional for normal scope-based usage.
| HtmlTag & Supla::HtmlTag::finish | ( | ) |
Close the opening tag and mark it as finished.
For paired tags this prevents the destructor from emitting a closing tag. It is mainly useful for void tags and for low-level control when the caller wants to manage the content separately.