gdDocumentation0.8.0

API reference

GD.html

Entry for HTML entities, tags, and templates with context-sensitive escaping for text, attributes, URLs, styles, and scripts.

Methods

fill

fill(tpl: String, data: Dictionary, partials: Dictionary = {  }) -> String, Err

Render template source with a dictionary in one call. Use template() and execute() when the same template is rendered repeatedly.

Parameters

NameTypeDefaultDescription
tplStringRequiredTemplate source.
dataDictionaryRequiredValues for template expressions.
partialsDictionary{ }Named template fragments.

Return value

String, Err

Rendered text.

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

Parsing or rendering failures return Err.

See also

template

template(tpl: String, partials: Dictionary = {  }) -> GDHTMLTemplate, Err

Parse a template once and reuse the returned object for repeated rendering. This separates template construction errors from per-render data errors.

Parameters

NameTypeDefaultDescription
tplStringRequiredTemplate source text.
partialsDictionary{ }Named template fragments available during rendering.

Return value

GDHTMLTemplate, Err

A reusable GDHTMLTemplate.

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

Invalid template syntax returns Err.

See also

attr

attr(value: String) -> String

Escape an HTML attribute value safely.

Parameters

NameTypeDefaultDescription
valueStringRequiredValue to store, serialize, validate or pass to the operation described above.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

tag

tag(name: String, body: String, attrs: Dictionary = {  }) -> String

Build an HTML tag from its name, body, and attributes.

Parameters

NameTypeDefaultDescription
nameStringRequiredName used to register or look up the corresponding entry.
bodyStringRequiredContent to write or include in the response.
attrsDictionary{ }Named attributes to encode in markup or document metadata.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

escape

escape(text: String) -> String

Escape HTML text.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

unescape

unescape(text: String) -> String

Decode HTML entities into text.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

escape_async

escape_async(text: String) -> await String

Dispatch HTML processing to CPU workers.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

unescape_async

unescape_async(text: String) -> await String

Dispatch HTML entity decoding to a CPU worker.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

attr_async

attr_async(value: String) -> await String

Dispatch HTML attribute escaping to a CPU worker.

Parameters

NameTypeDefaultDescription
valueStringRequiredValue to store, serialize, validate or pass to the operation described above.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

tag_async

tag_async(name: String, body: String, attrs: Dictionary = {  }) -> await String

Dispatch HTML tag construction to a CPU worker.

Parameters

NameTypeDefaultDescription
nameStringRequiredName used to register or look up the corresponding entry.
bodyStringRequiredContent to write or include in the response.
attrsDictionary{ }Named attributes to encode in markup or document metadata.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

fill_async

fill_async(tpl: String, data: Dictionary, partials: Dictionary = {  }) -> await String, Err

Render template source with a dictionary in one call. Use template() and execute() when the same template is rendered repeatedly.

Parameters

NameTypeDefaultDescription
tplStringRequiredTemplate source.
dataDictionaryRequiredValues for template expressions.
partialsDictionary{ }Named template fragments.

Return value

await String, Err

Rendered text.

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

Parsing or rendering failures return Err.

See also