Current section
Files
Jump to
Current section
Files
src/sprocket@html@attributes.erl
-module(sprocket@html@attributes).
-compile([no_auto_import, nowarn_unused_vars]).
-export([attribute/2, event/2, on_click/1, on_doubleclick/1, on_change/1, on_input/1, media/1, role/1, accept/1, accept_charset/1, action/1, alt/1, async/0, autocapitalize/1, autocomplete/1, autofocus/0, autoplay/0, capture/1, charset/1, checked/0, cite/1, class/1, classes/1, content/1, contenteditable/0, crossorigin/1, defer/0, disabled/0, draggable/0, for/1, formaction/1, height/1, href/1, http_equiv/1, id/1, input_type/1, integrity/1, lang/1, loop/0, method/1, name/1, placeholder/1, preload/0, property/1, readonly/0, referrerpolicy/1, rel/1, selected/0, src/1, style/1, tabindex/1, target/1, title/1, value/1, width/1]).
-export_type([attribute/0]).
-type attribute() :: {attribute, binary(), gleam@dynamic:dynamic()} |
{event,
binary(),
sprocket@internal@identifiable_callback:identifiable_callback()}.
-spec attribute(binary(), any()) -> attribute().
attribute(Name, Value) ->
{attribute, Name, gleam@dynamic:from(Value)}.
-spec event(
binary(),
sprocket@internal@identifiable_callback:identifiable_callback()
) -> attribute().
event(Name, Identifiable_cb) ->
{event, Name, Identifiable_cb}.
-spec on_click(sprocket@internal@identifiable_callback:identifiable_callback()) -> attribute().
on_click(Identifiable_cb) ->
event(<<"click"/utf8>>, Identifiable_cb).
-spec on_doubleclick(
sprocket@internal@identifiable_callback:identifiable_callback()
) -> attribute().
on_doubleclick(Identifiable_cb) ->
event(<<"doubleclick"/utf8>>, Identifiable_cb).
-spec on_change(sprocket@internal@identifiable_callback:identifiable_callback()) -> attribute().
on_change(Identifiable_cb) ->
event(<<"change"/utf8>>, Identifiable_cb).
-spec on_input(sprocket@internal@identifiable_callback:identifiable_callback()) -> attribute().
on_input(Identifiable_cb) ->
event(<<"input"/utf8>>, Identifiable_cb).
-spec media(binary()) -> attribute().
media(Value) ->
attribute(<<"media"/utf8>>, Value).
-spec role(binary()) -> attribute().
role(Value) ->
attribute(<<"role"/utf8>>, Value).
-spec accept(binary()) -> attribute().
accept(Value) ->
attribute(<<"accept"/utf8>>, Value).
-spec accept_charset(binary()) -> attribute().
accept_charset(Value) ->
attribute(<<"accept-charset"/utf8>>, Value).
-spec action(binary()) -> attribute().
action(Value) ->
attribute(<<"action"/utf8>>, Value).
-spec alt(binary()) -> attribute().
alt(Value) ->
attribute(<<"alt"/utf8>>, Value).
-spec async() -> attribute().
async() ->
attribute(<<"async"/utf8>>, <<"true"/utf8>>).
-spec autocapitalize(binary()) -> attribute().
autocapitalize(Value) ->
attribute(<<"autocapitalize"/utf8>>, Value).
-spec autocomplete(binary()) -> attribute().
autocomplete(Value) ->
attribute(<<"autocomplete"/utf8>>, Value).
-spec autofocus() -> attribute().
autofocus() ->
attribute(<<"autofocus"/utf8>>, <<"true"/utf8>>).
-spec autoplay() -> attribute().
autoplay() ->
attribute(<<"autoplay"/utf8>>, <<"true"/utf8>>).
-spec capture(binary()) -> attribute().
capture(Value) ->
attribute(<<"capture"/utf8>>, Value).
-spec charset(binary()) -> attribute().
charset(Value) ->
attribute(<<"charset"/utf8>>, Value).
-spec checked() -> attribute().
checked() ->
attribute(<<"checked"/utf8>>, <<"true"/utf8>>).
-spec cite(binary()) -> attribute().
cite(Value) ->
attribute(<<"cite"/utf8>>, Value).
-spec class(binary()) -> attribute().
class(Value) ->
attribute(<<"class"/utf8>>, Value).
-spec classes(list(gleam@option:option(binary()))) -> attribute().
classes(Value) ->
attribute(
<<"class"/utf8>>,
begin
_pipe = gleam@list:fold(
Value,
gleam@string_builder:new(),
fun(Sb, V) -> case V of
none ->
Sb;
{some, V@1} ->
case gleam@string_builder:is_empty(Sb) of
true ->
gleam@string_builder:append(Sb, V@1);
false ->
gleam@string_builder:append(
Sb,
<<" "/utf8, V@1/binary>>
)
end
end end
),
gleam@string_builder:to_string(_pipe)
end
).
-spec content(binary()) -> attribute().
content(Value) ->
attribute(<<"content"/utf8>>, Value).
-spec contenteditable() -> attribute().
contenteditable() ->
attribute(<<"contenteditable"/utf8>>, <<"true"/utf8>>).
-spec crossorigin(binary()) -> attribute().
crossorigin(Value) ->
attribute(<<"crossorigin"/utf8>>, Value).
-spec defer() -> attribute().
defer() ->
attribute(<<"defer"/utf8>>, <<"true"/utf8>>).
-spec disabled() -> attribute().
disabled() ->
attribute(<<"disabled"/utf8>>, <<"true"/utf8>>).
-spec draggable() -> attribute().
draggable() ->
attribute(<<"draggable"/utf8>>, <<"true"/utf8>>).
-spec for(binary()) -> attribute().
for(Value) ->
attribute(<<"for"/utf8>>, Value).
-spec formaction(binary()) -> attribute().
formaction(Value) ->
attribute(<<"formaction"/utf8>>, Value).
-spec height(binary()) -> attribute().
height(Value) ->
attribute(<<"height"/utf8>>, Value).
-spec href(binary()) -> attribute().
href(Value) ->
attribute(<<"href"/utf8>>, Value).
-spec http_equiv(binary()) -> attribute().
http_equiv(Value) ->
attribute(<<"http-equiv"/utf8>>, Value).
-spec id(binary()) -> attribute().
id(Value) ->
attribute(<<"id"/utf8>>, Value).
-spec input_type(binary()) -> attribute().
input_type(Value) ->
attribute(<<"type"/utf8>>, Value).
-spec integrity(binary()) -> attribute().
integrity(Value) ->
attribute(<<"integrity"/utf8>>, Value).
-spec lang(binary()) -> attribute().
lang(Value) ->
attribute(<<"lang"/utf8>>, Value).
-spec loop() -> attribute().
loop() ->
attribute(<<"loop"/utf8>>, <<"true"/utf8>>).
-spec method(binary()) -> attribute().
method(Value) ->
attribute(<<"method"/utf8>>, Value).
-spec name(binary()) -> attribute().
name(Value) ->
attribute(<<"name"/utf8>>, Value).
-spec placeholder(binary()) -> attribute().
placeholder(Value) ->
attribute(<<"placeholder"/utf8>>, Value).
-spec preload() -> attribute().
preload() ->
attribute(<<"preload"/utf8>>, <<"true"/utf8>>).
-spec property(binary()) -> attribute().
property(Value) ->
attribute(<<"property"/utf8>>, Value).
-spec readonly() -> attribute().
readonly() ->
attribute(<<"readonly"/utf8>>, <<"true"/utf8>>).
-spec referrerpolicy(binary()) -> attribute().
referrerpolicy(Value) ->
attribute(<<"referrerpolicy"/utf8>>, Value).
-spec rel(binary()) -> attribute().
rel(Value) ->
attribute(<<"rel"/utf8>>, Value).
-spec selected() -> attribute().
selected() ->
attribute(<<"selected"/utf8>>, <<"true"/utf8>>).
-spec src(binary()) -> attribute().
src(Value) ->
attribute(<<"src"/utf8>>, Value).
-spec style(binary()) -> attribute().
style(Value) ->
attribute(<<"style"/utf8>>, Value).
-spec tabindex(binary()) -> attribute().
tabindex(Value) ->
attribute(<<"tabindex"/utf8>>, Value).
-spec target(binary()) -> attribute().
target(Value) ->
attribute(<<"target"/utf8>>, Value).
-spec title(binary()) -> attribute().
title(Value) ->
attribute(<<"title"/utf8>>, Value).
-spec value(binary()) -> attribute().
value(Value) ->
attribute(<<"value"/utf8>>, Value).
-spec width(binary()) -> attribute().
width(Value) ->
attribute(<<"width"/utf8>>, Value).