Current section
Files
Jump to
Current section
Files
src/sprocket@html@attribute.erl
-module(sprocket@html@attribute).
-compile([no_auto_import, nowarn_unused_vars]).
-export([attribute/2, event/2, on_click/1, on_change/1, on_input/1, lang/1, charset/1, http_equiv/1, name/1, content/1, id/1, class/1, classes/1, href/1, rel/1, integrity/1, crossorigin/1, referrerpolicy/1, src/1, placeholder/1, input_type/1, value/1, target/1, data/2]).
-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_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 lang(binary()) -> attribute().
lang(Value) ->
attribute(<<"lang"/utf8>>, Value).
-spec charset(binary()) -> attribute().
charset(Value) ->
attribute(<<"charset"/utf8>>, Value).
-spec http_equiv(binary()) -> attribute().
http_equiv(Value) ->
attribute(<<"http-equiv"/utf8>>, Value).
-spec name(binary()) -> attribute().
name(Value) ->
attribute(<<"name"/utf8>>, Value).
-spec content(binary()) -> attribute().
content(Value) ->
attribute(<<"content"/utf8>>, Value).
-spec id(binary()) -> attribute().
id(Value) ->
attribute(<<"id"/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 href(binary()) -> attribute().
href(Value) ->
attribute(<<"href"/utf8>>, Value).
-spec rel(binary()) -> attribute().
rel(Value) ->
attribute(<<"rel"/utf8>>, Value).
-spec integrity(binary()) -> attribute().
integrity(Value) ->
attribute(<<"integrity"/utf8>>, Value).
-spec crossorigin(binary()) -> attribute().
crossorigin(Value) ->
attribute(<<"crossorigin"/utf8>>, Value).
-spec referrerpolicy(binary()) -> attribute().
referrerpolicy(Value) ->
attribute(<<"referrerpolicy"/utf8>>, Value).
-spec src(binary()) -> attribute().
src(Value) ->
attribute(<<"src"/utf8>>, Value).
-spec placeholder(binary()) -> attribute().
placeholder(Value) ->
attribute(<<"placeholder"/utf8>>, Value).
-spec input_type(binary()) -> attribute().
input_type(Value) ->
attribute(<<"type"/utf8>>, Value).
-spec value(binary()) -> attribute().
value(Value) ->
attribute(<<"value"/utf8>>, Value).
-spec target(binary()) -> attribute().
target(Value) ->
attribute(<<"target"/utf8>>, Value).
-spec data(binary(), binary()) -> attribute().
data(Name, Value) ->
attribute(<<"data-"/utf8, Name/binary>>, Value).