Packages

A DSL for generating HTML in Gleam

Current section

Files

Jump to
html_dsl src html_dsl@types@html@head.erl
Raw

src/html_dsl@types@html@head.erl

-module(html_dsl@types@html@head).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([resolve/1, head/0, head_to_string/1, 'end'/1, script/2, link/4, style/2, meta/3, charset/2, title/2]).
-export_type([head/0]).
-opaque head() :: {head, binary()} | {'end', binary()}.
-spec resolve(head()) -> {ok, binary()} | {error, binary()}.
resolve(Head) ->
case Head of
{head, S} ->
{error, S};
{'end', S@1} ->
{ok, S@1}
end.
-spec head() -> head().
head() ->
{head, <<"<head>"/utf8>>}.
-spec head_to_string(head()) -> binary().
head_to_string(Head) ->
case Head of
{head, S} ->
S;
{'end', _} ->
(erlang:error(#{gleam_error => panic,
message => <<"panic expression evaluated"/utf8>>,
module => <<"html_dsl/types/html/head"/utf8>>,
function => <<"head_to_string"/utf8>>,
line => 40}))(<<"Cannot end an End"/utf8>>)
end.
-spec 'end'(head()) -> head().
'end'(Root) ->
{'end', <<(head_to_string(Root))/binary, "</head>"/utf8>>}.
-spec script(head(), binary()) -> head().
script(Root, Src) ->
Src@1 = html_dsl@utils@check:illegal_string_check(Src),
{head,
<<<<<<(head_to_string(Root))/binary, "<script src=\""/utf8>>/binary,
Src@1/binary>>/binary,
"\"></script>"/utf8>>}.
-spec link(
head(),
binary(),
binary(),
gleam@option:option(html_dsl@types@attribute:attribute())
) -> head().
link(Root, Rel, Href, Attributes) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
Rel@1 = html_dsl@utils@check:illegal_string_check(Rel),
Href@1 = html_dsl@utils@check:illegal_string_check(Href),
{head,
<<<<<<<<<<<<<<(head_to_string(Root))/binary, "<link rel=\""/utf8>>/binary,
Rel@1/binary>>/binary,
"\" href=\""/utf8>>/binary,
Href@1/binary>>/binary,
"\""/utf8>>/binary,
Att_str/binary>>/binary,
">"/utf8>>}.
-spec style(head(), binary()) -> head().
style(Root, Src) ->
Src@1 = html_dsl@utils@check:illegal_string_check(Src),
{head,
<<<<<<(head_to_string(Root))/binary,
"<link rel=\"stylesheet\" href=\""/utf8>>/binary,
Src@1/binary>>/binary,
"\">"/utf8>>}.
-spec meta(head(), binary(), binary()) -> head().
meta(Root, Name, Content) ->
Name@1 = html_dsl@utils@check:illegal_string_check(Name),
{head,
<<<<<<<<<<(head_to_string(Root))/binary, "<meta name=\""/utf8>>/binary,
Name@1/binary>>/binary,
"\" content=\""/utf8>>/binary,
Content/binary>>/binary,
"\">"/utf8>>}.
-spec charset(head(), binary()) -> head().
charset(Root, Set) ->
Set@1 = html_dsl@utils@check:illegal_string_check(Set),
{head,
<<<<<<(head_to_string(Root))/binary, "<meta charset=\""/utf8>>/binary,
Set@1/binary>>/binary,
"\">"/utf8>>}.
-spec title(head(), binary()) -> head().
title(Root, Content) ->
Content@1 = html_dsl@utils@check:illegal_string_check(Content),
{head,
<<<<<<(head_to_string(Root))/binary, "<title>"/utf8>>/binary,
Content@1/binary>>/binary,
"</title>"/utf8>>}.