-module(ag_html@attributes).
-compile(no_auto_import).
-export([render_list/1, simple/2, with_value/2, class_list/1, hidden/1, autofocus/1, spellcheck/1, contenteditable/1, reversed/1, default/1, loop/1, controls/1, autoplay/1, required/1, readonly/1, novalidate/1, multiple/1, disabled/1, checked/1, defer/1, draggable/1, open/1, accept/1, accept_charset/1, accesskey/1, action/1, align/1, allow/1, alt/1, async/1, autocapitalize/1, autocomplete/1, buffered/1, capture/1, challenge/1, charset/1, cite/1, class/1, code/1, codebase/1, cols/1, colspan/1, content/1, contextmenu/1, coords/1, crossorigin/1, csp/1, datetime/1, decoding/1, dir/1, dirname/1, download/1, enctype/1, enterkeyhint/1, for/1, form/1, formaction/1, formenctype/1, formmethod/1, formnovalidate/1, formtarget/1, headers/1, high/1, href/1, hreflang/1, http_equiv/1, icon/1, id/1, importance/1, integrity/1, ismap/1, itemprop/1, keytype/1, kind/1, label/1, lang/1, language/1, list/1, low/1, manifest/1, max/1, maxlength/1, minlength/1, media/1, method/1, min/1, muted/1, name/1, optimum/1, pattern/1, ping/1, placeholder/1, poster/1, preload/1, radiogroup/1, referrerpolicy/1, rel/1, role/1, rows/1, rowspan/1, sandbox/1, scope/1, scoped/1, selected/1, shape/1, size/1, sizes/1, slot/1, span/1, src/1, srcdoc/1, srclang/1, srcset/1, start/1, step/1, style/1, summary/1, tabindex/1, target/1, title/1, translate/1, type_/1, usemap/1, value/1, height/1, width/1, wrap/1]).
-export_type([attribute/0]).
-opaque attribute() :: {simple, binary(), boolean()} |
{with_value, binary(), binary()}.
-spec render(attribute()) -> gleam@string_builder:string_builder().
render(Attribute) ->
case Attribute of
{simple, Name, true} ->
gleam@string_builder:from_string(Name);
{simple, _@1, false} ->
gleam@string_builder:from_string(<<""/utf8>>);
{with_value, Name@1, Value} ->
_pipe = Name@1,
_pipe@1 = gleam@string_builder:from_string(_pipe),
_pipe@2 = gleam@string_builder:append(_pipe@1, <<"=\""/utf8>>),
_pipe@3 = gleam@string_builder:append_builder(
_pipe@2,
escape(Value)
),
gleam@string_builder:append(_pipe@3, <<"\""/utf8>>)
end.
-spec render_list(list(attribute())) -> gleam@string_builder:string_builder().
render_list(Attributes) ->
case Attributes of
[] ->
gleam@string_builder:from_string(<<""/utf8>>);
Other ->
_pipe = Other,
_pipe@1 = gleam@list:map(_pipe, fun render/1),
_pipe@2 = gleam@string_builder:join(_pipe@1, <<" "/utf8>>),
gleam@string_builder:prepend(_pipe@2, <<" "/utf8>>)
end.
-spec escape(binary()) -> gleam@string_builder:string_builder().
escape(Text) ->
ag_html@string_utils:map(Text, fun(G) -> case G of
<<"<"/utf8>> ->
<<"<"/utf8>>;
<<">"/utf8>> ->
<<">"/utf8>>;
<<"&"/utf8>> ->
<<"&"/utf8>>;
<<"'"/utf8>> ->
<<"'"/utf8>>;
<<"\""/utf8>> ->
<<"""/utf8>>;
_@1 ->
G
end end).
-spec simple(binary(), boolean()) -> attribute().
simple(Name, Enabled) ->
{simple, Name, Enabled}.
-spec with_value(binary(), binary()) -> attribute().
with_value(Name, Value) ->
{with_value, Name, Value}.
-spec class_list(list({binary(), boolean()})) -> attribute().
class_list(Classes) ->
_pipe = Classes,
_pipe@1 = gleam@list:filter(_pipe, fun gleam@pair:second/1),
_pipe@2 = gleam@list:map(_pipe@1, fun gleam@pair:first/1),
_pipe@3 = gleam@string:join(_pipe@2, <<" "/utf8>>),
class(_pipe@3).
-spec hidden(boolean()) -> attribute().
hidden(Enabled) ->
simple(<<"hidden"/utf8>>, Enabled).
-spec autofocus(boolean()) -> attribute().
autofocus(Enabled) ->
simple(<<"autofocus"/utf8>>, Enabled).
-spec spellcheck(boolean()) -> attribute().
spellcheck(Enabled) ->
simple(<<"spellcheck"/utf8>>, Enabled).
-spec contenteditable(boolean()) -> attribute().
contenteditable(Enabled) ->
simple(<<"contenteditable"/utf8>>, Enabled).
-spec reversed(boolean()) -> attribute().
reversed(Enabled) ->
simple(<<"reversed"/utf8>>, Enabled).
-spec default(boolean()) -> attribute().
default(Enabled) ->
simple(<<"default"/utf8>>, Enabled).
-spec loop(boolean()) -> attribute().
loop(Enabled) ->
simple(<<"loop"/utf8>>, Enabled).
-spec controls(boolean()) -> attribute().
controls(Enabled) ->
simple(<<"controls"/utf8>>, Enabled).
-spec autoplay(boolean()) -> attribute().
autoplay(Enabled) ->
simple(<<"autoplay"/utf8>>, Enabled).
-spec required(boolean()) -> attribute().
required(Enabled) ->
simple(<<"required"/utf8>>, Enabled).
-spec readonly(boolean()) -> attribute().
readonly(Enabled) ->
simple(<<"readonly"/utf8>>, Enabled).
-spec novalidate(boolean()) -> attribute().
novalidate(Enabled) ->
simple(<<"novalidate"/utf8>>, Enabled).
-spec multiple(boolean()) -> attribute().
multiple(Enabled) ->
simple(<<"multiple"/utf8>>, Enabled).
-spec disabled(boolean()) -> attribute().
disabled(Enabled) ->
simple(<<"disabled"/utf8>>, Enabled).
-spec checked(boolean()) -> attribute().
checked(Enabled) ->
simple(<<"checked"/utf8>>, Enabled).
-spec defer(boolean()) -> attribute().
defer(Enabled) ->
simple(<<"defer"/utf8>>, Enabled).
-spec draggable(boolean()) -> attribute().
draggable(Enabled) ->
simple(<<"draggable"/utf8>>, Enabled).
-spec open(boolean()) -> attribute().
open(Enabled) ->
simple(<<"open"/utf8>>, Enabled).
-spec accept(binary()) -> attribute().
accept(Value) ->
with_value(<<"accept"/utf8>>, Value).
-spec accept_charset(binary()) -> attribute().
accept_charset(Value) ->
with_value(<<"accept-charset"/utf8>>, Value).
-spec accesskey(binary()) -> attribute().
accesskey(Value) ->
with_value(<<"accesskey"/utf8>>, Value).
-spec action(binary()) -> attribute().
action(Value) ->
with_value(<<"action"/utf8>>, Value).
-spec align(binary()) -> attribute().
align(Value) ->
with_value(<<"align"/utf8>>, Value).
-spec allow(binary()) -> attribute().
allow(Value) ->
with_value(<<"allow"/utf8>>, Value).
-spec alt(binary()) -> attribute().
alt(Value) ->
with_value(<<"alt"/utf8>>, Value).
-spec async(binary()) -> attribute().
async(Value) ->
with_value(<<"async"/utf8>>, Value).
-spec autocapitalize(binary()) -> attribute().
autocapitalize(Value) ->
with_value(<<"autocapitalize"/utf8>>, Value).
-spec autocomplete(binary()) -> attribute().
autocomplete(Value) ->
with_value(<<"autocomplete"/utf8>>, Value).
-spec buffered(binary()) -> attribute().
buffered(Value) ->
with_value(<<"buffered"/utf8>>, Value).
-spec capture(binary()) -> attribute().
capture(Value) ->
with_value(<<"capture"/utf8>>, Value).
-spec challenge(binary()) -> attribute().
challenge(Value) ->
with_value(<<"challenge"/utf8>>, Value).
-spec charset(binary()) -> attribute().
charset(Value) ->
with_value(<<"charset"/utf8>>, Value).
-spec cite(binary()) -> attribute().
cite(Value) ->
with_value(<<"cite"/utf8>>, Value).
-spec class(binary()) -> attribute().
class(Value) ->
with_value(<<"class"/utf8>>, Value).
-spec code(binary()) -> attribute().
code(Value) ->
with_value(<<"code"/utf8>>, Value).
-spec codebase(binary()) -> attribute().
codebase(Value) ->
with_value(<<"codebase"/utf8>>, Value).
-spec cols(integer()) -> attribute().
cols(Value) ->
with_value(<<"cols"/utf8>>, gleam@int:to_string(Value)).
-spec colspan(integer()) -> attribute().
colspan(Value) ->
with_value(<<"colspan"/utf8>>, gleam@int:to_string(Value)).
-spec content(binary()) -> attribute().
content(Value) ->
with_value(<<"content"/utf8>>, Value).
-spec contextmenu(binary()) -> attribute().
contextmenu(Value) ->
with_value(<<"contextmenu"/utf8>>, Value).
-spec coords(binary()) -> attribute().
coords(Value) ->
with_value(<<"coords"/utf8>>, Value).
-spec crossorigin(binary()) -> attribute().
crossorigin(Value) ->
with_value(<<"crossorigin"/utf8>>, Value).
-spec csp(binary()) -> attribute().
csp(Value) ->
with_value(<<"csp"/utf8>>, Value).
-spec datetime(binary()) -> attribute().
datetime(Value) ->
with_value(<<"datetime"/utf8>>, Value).
-spec decoding(binary()) -> attribute().
decoding(Value) ->
with_value(<<"decoding"/utf8>>, Value).
-spec dir(binary()) -> attribute().
dir(Value) ->
with_value(<<"dir"/utf8>>, Value).
-spec dirname(binary()) -> attribute().
dirname(Value) ->
with_value(<<"dirname"/utf8>>, Value).
-spec download(binary()) -> attribute().
download(Value) ->
with_value(<<"download"/utf8>>, Value).
-spec enctype(binary()) -> attribute().
enctype(Value) ->
with_value(<<"enctype"/utf8>>, Value).
-spec enterkeyhint(binary()) -> attribute().
enterkeyhint(Value) ->
with_value(<<"enterkeyhint"/utf8>>, Value).
-spec for(binary()) -> attribute().
for(Value) ->
with_value(<<"for"/utf8>>, Value).
-spec form(binary()) -> attribute().
form(Value) ->
with_value(<<"form"/utf8>>, Value).
-spec formaction(binary()) -> attribute().
formaction(Value) ->
with_value(<<"formaction"/utf8>>, Value).
-spec formenctype(binary()) -> attribute().
formenctype(Value) ->
with_value(<<"formenctype"/utf8>>, Value).
-spec formmethod(binary()) -> attribute().
formmethod(Value) ->
with_value(<<"formmethod"/utf8>>, Value).
-spec formnovalidate(binary()) -> attribute().
formnovalidate(Value) ->
with_value(<<"formnovalidate"/utf8>>, Value).
-spec formtarget(binary()) -> attribute().
formtarget(Value) ->
with_value(<<"formtarget"/utf8>>, Value).
-spec headers(binary()) -> attribute().
headers(Value) ->
with_value(<<"headers"/utf8>>, Value).
-spec high(binary()) -> attribute().
high(Value) ->
with_value(<<"high"/utf8>>, Value).
-spec href(binary()) -> attribute().
href(Value) ->
with_value(<<"href"/utf8>>, Value).
-spec hreflang(binary()) -> attribute().
hreflang(Value) ->
with_value(<<"hreflang"/utf8>>, Value).
-spec http_equiv(binary()) -> attribute().
http_equiv(Value) ->
with_value(<<"http-equiv"/utf8>>, Value).
-spec icon(binary()) -> attribute().
icon(Value) ->
with_value(<<"icon"/utf8>>, Value).
-spec id(binary()) -> attribute().
id(Value) ->
with_value(<<"id"/utf8>>, Value).
-spec importance(binary()) -> attribute().
importance(Value) ->
with_value(<<"importance"/utf8>>, Value).
-spec integrity(binary()) -> attribute().
integrity(Value) ->
with_value(<<"integrity"/utf8>>, Value).
-spec ismap(binary()) -> attribute().
ismap(Value) ->
with_value(<<"ismap"/utf8>>, Value).
-spec itemprop(binary()) -> attribute().
itemprop(Value) ->
with_value(<<"itemprop"/utf8>>, Value).
-spec keytype(binary()) -> attribute().
keytype(Value) ->
with_value(<<"keytype"/utf8>>, Value).
-spec kind(binary()) -> attribute().
kind(Value) ->
with_value(<<"kind"/utf8>>, Value).
-spec label(binary()) -> attribute().
label(Value) ->
with_value(<<"label"/utf8>>, Value).
-spec lang(binary()) -> attribute().
lang(Value) ->
with_value(<<"lang"/utf8>>, Value).
-spec language(binary()) -> attribute().
language(Value) ->
with_value(<<"language"/utf8>>, Value).
-spec list(binary()) -> attribute().
list(Value) ->
with_value(<<"list"/utf8>>, Value).
-spec low(binary()) -> attribute().
low(Value) ->
with_value(<<"low"/utf8>>, Value).
-spec manifest(binary()) -> attribute().
manifest(Value) ->
with_value(<<"manifest"/utf8>>, Value).
-spec max(binary()) -> attribute().
max(Value) ->
with_value(<<"max"/utf8>>, Value).
-spec maxlength(integer()) -> attribute().
maxlength(Value) ->
with_value(<<"maxlength"/utf8>>, gleam@int:to_string(Value)).
-spec minlength(integer()) -> attribute().
minlength(Value) ->
with_value(<<"minlength"/utf8>>, gleam@int:to_string(Value)).
-spec media(binary()) -> attribute().
media(Value) ->
with_value(<<"media"/utf8>>, Value).
-spec method(binary()) -> attribute().
method(Value) ->
with_value(<<"method"/utf8>>, Value).
-spec min(binary()) -> attribute().
min(Value) ->
with_value(<<"min"/utf8>>, Value).
-spec muted(binary()) -> attribute().
muted(Value) ->
with_value(<<"muted"/utf8>>, Value).
-spec name(binary()) -> attribute().
name(Value) ->
with_value(<<"name"/utf8>>, Value).
-spec optimum(binary()) -> attribute().
optimum(Value) ->
with_value(<<"optimum"/utf8>>, Value).
-spec pattern(binary()) -> attribute().
pattern(Value) ->
with_value(<<"pattern"/utf8>>, Value).
-spec ping(binary()) -> attribute().
ping(Value) ->
with_value(<<"ping"/utf8>>, Value).
-spec placeholder(binary()) -> attribute().
placeholder(Value) ->
with_value(<<"placeholder"/utf8>>, Value).
-spec poster(binary()) -> attribute().
poster(Value) ->
with_value(<<"poster"/utf8>>, Value).
-spec preload(binary()) -> attribute().
preload(Value) ->
with_value(<<"preload"/utf8>>, Value).
-spec radiogroup(binary()) -> attribute().
radiogroup(Value) ->
with_value(<<"radiogroup"/utf8>>, Value).
-spec referrerpolicy(binary()) -> attribute().
referrerpolicy(Value) ->
with_value(<<"referrerpolicy"/utf8>>, Value).
-spec rel(binary()) -> attribute().
rel(Value) ->
with_value(<<"rel"/utf8>>, Value).
-spec role(binary()) -> attribute().
role(Value) ->
with_value(<<"role"/utf8>>, Value).
-spec rows(binary()) -> attribute().
rows(Value) ->
with_value(<<"rows"/utf8>>, Value).
-spec rowspan(integer()) -> attribute().
rowspan(Value) ->
with_value(<<"rowspan"/utf8>>, gleam@int:to_string(Value)).
-spec sandbox(binary()) -> attribute().
sandbox(Value) ->
with_value(<<"sandbox"/utf8>>, Value).
-spec scope(binary()) -> attribute().
scope(Value) ->
with_value(<<"scope"/utf8>>, Value).
-spec scoped(binary()) -> attribute().
scoped(Value) ->
with_value(<<"scoped"/utf8>>, Value).
-spec selected(binary()) -> attribute().
selected(Value) ->
with_value(<<"selected"/utf8>>, Value).
-spec shape(binary()) -> attribute().
shape(Value) ->
with_value(<<"shape"/utf8>>, Value).
-spec size(integer()) -> attribute().
size(Value) ->
with_value(<<"size"/utf8>>, gleam@int:to_string(Value)).
-spec sizes(binary()) -> attribute().
sizes(Value) ->
with_value(<<"sizes"/utf8>>, Value).
-spec slot(binary()) -> attribute().
slot(Value) ->
with_value(<<"slot"/utf8>>, Value).
-spec span(binary()) -> attribute().
span(Value) ->
with_value(<<"span"/utf8>>, Value).
-spec src(binary()) -> attribute().
src(Value) ->
with_value(<<"src"/utf8>>, Value).
-spec srcdoc(binary()) -> attribute().
srcdoc(Value) ->
with_value(<<"srcdoc"/utf8>>, Value).
-spec srclang(binary()) -> attribute().
srclang(Value) ->
with_value(<<"srclang"/utf8>>, Value).
-spec srcset(binary()) -> attribute().
srcset(Value) ->
with_value(<<"srcset"/utf8>>, Value).
-spec start(integer()) -> attribute().
start(Value) ->
with_value(<<"start"/utf8>>, gleam@int:to_string(Value)).
-spec step(binary()) -> attribute().
step(Value) ->
with_value(<<"step"/utf8>>, Value).
-spec style(binary()) -> attribute().
style(Value) ->
with_value(<<"style"/utf8>>, Value).
-spec summary(binary()) -> attribute().
summary(Value) ->
with_value(<<"summary"/utf8>>, Value).
-spec tabindex(integer()) -> attribute().
tabindex(Value) ->
with_value(<<"tabindex"/utf8>>, gleam@int:to_string(Value)).
-spec target(binary()) -> attribute().
target(Value) ->
with_value(<<"target"/utf8>>, Value).
-spec title(binary()) -> attribute().
title(Value) ->
with_value(<<"title"/utf8>>, Value).
-spec translate(binary()) -> attribute().
translate(Value) ->
with_value(<<"translate"/utf8>>, Value).
-spec type_(binary()) -> attribute().
type_(Value) ->
with_value(<<"type"/utf8>>, Value).
-spec usemap(binary()) -> attribute().
usemap(Value) ->
with_value(<<"usemap"/utf8>>, Value).
-spec value(binary()) -> attribute().
value(Value) ->
with_value(<<"value"/utf8>>, Value).
-spec height(integer()) -> attribute().
height(Value) ->
with_value(<<"height"/utf8>>, gleam@int:to_string(Value)).
-spec width(integer()) -> attribute().
width(Value) ->
with_value(<<"width"/utf8>>, gleam@int:to_string(Value)).
-spec wrap(binary()) -> attribute().
wrap(Value) ->
with_value(<<"wrap"/utf8>>, Value).