Packages

A DSL for generating HTML in Gleam

Current section

Files

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

src/html_dsl@types@html.erl

-module(html_dsl@types@html).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([body_to_string/1, is_html/1, html_to_string/1, 'div'/2, img/3, a/3, h1/2, h2/2, h3/2, h4/2, h5/2, h6/2, p/2, span/2, br/0, hr/0, body/2, force/1, html/3, component/1, header/2, footer/2, nav/2, section/2, article/2, aside/2, main/2, button/2]).
-export_type([html/0, body/0]).
-opaque html() :: {html, binary()} | {component, binary()} | nil.
-opaque body() :: {body, binary()}.
-spec body_to_string(body()) -> binary().
body_to_string(Body) ->
case Body of
{body, Content} ->
Content
end.
-spec is_html(html()) -> boolean().
is_html(Html) ->
case Html of
{html, _} ->
true;
_ ->
false
end.
-spec html_to_string(html()) -> binary().
html_to_string(Html) ->
case Html of
{html, Content} ->
Content;
{component, Content@1} ->
Content@1;
nil ->
<<""/utf8>>
end.
-spec 'div'(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
'div'(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<div"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</div>"/utf8>>.
-spec img(
binary(),
binary(),
gleam@option:option(html_dsl@types@attribute:attribute())
) -> binary().
img(Src, Alt, Attributes) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
Src@1 = html_dsl@utils@check:illegal_string_check(Src),
Alt@1 = html_dsl@utils@check:illegal_string_check(Alt),
<<<<<<<<<<<<"<img src=\""/utf8, Src@1/binary>>/binary, "\" alt=\""/utf8>>/binary,
Alt@1/binary>>/binary,
"\""/utf8>>/binary,
Att_str/binary>>/binary,
"/>"/utf8>>.
-spec a(
binary(),
gleam@option:option(html_dsl@types@attribute:attribute()),
binary()
) -> binary().
a(Href, Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
Href@1 = html_dsl@utils@check:illegal_string_check(Href),
<<<<<<<<<<<<"<a href=\""/utf8, Href@1/binary>>/binary, "\""/utf8>>/binary,
Att_str/binary>>/binary,
">"/utf8>>/binary,
Inner/binary>>/binary,
"</a>"/utf8>>.
-spec h1(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
h1(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<h1"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</h1>"/utf8>>.
-spec h2(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
h2(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<h2"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</h2>"/utf8>>.
-spec h3(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
h3(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<h3"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</h3>"/utf8>>.
-spec h4(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
h4(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<h4"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</h4>"/utf8>>.
-spec h5(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
h5(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<h5"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</h5>"/utf8>>.
-spec h6(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
h6(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<h6"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</h6>"/utf8>>.
-spec p(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
p(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<p"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</p>"/utf8>>.
-spec span(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
span(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<span"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</span>"/utf8>>.
-spec br() -> binary().
br() ->
<<"<br>"/utf8>>.
-spec hr() -> binary().
hr() ->
<<"<hr>"/utf8>>.
-spec body(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> body().
body(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
{body,
<<<<<<<<"<body"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</body>"/utf8>>}.
-spec force({ok, html()} | {error, binary()}) -> html().
force(Result) ->
case Result of
{ok, Html} ->
Html;
{error, S} ->
gleam@io:print(S),
nil
end.
-spec html(binary(), html_dsl@types@html@head:head(), body()) -> {ok, html()} |
{error, binary()}.
html(Lang, Head, Body) ->
Lang@1 = html_dsl@utils@check:illegal_string_check(Lang),
case html_dsl@types@html@head:resolve(Head) of
{ok, Head@1} ->
{ok,
{html,
<<<<<<<<<<"<!DOCTYPE html><html lang=\""/utf8,
Lang@1/binary>>/binary,
"\">"/utf8>>/binary,
(case Head@1 of
<<""/utf8>> ->
<<""/utf8>>;
_ ->
Head@1
end)/binary>>/binary,
(body_to_string(Body))/binary>>/binary,
"</html>"/utf8>>}};
{error, S} ->
{error, <<"Error: `Head` cannot resolve -> "/utf8, S/binary>>}
end.
-spec component(binary()) -> html().
component(Content) ->
{component, Content}.
-spec header(
gleam@option:option(html_dsl@types@attribute:attribute()),
binary()
) -> binary().
header(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<header"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</header>"/utf8>>.
-spec footer(
gleam@option:option(html_dsl@types@attribute:attribute()),
binary()
) -> binary().
footer(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<footer"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</footer>"/utf8>>.
-spec nav(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
nav(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<nav"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</nav>"/utf8>>.
-spec section(
gleam@option:option(html_dsl@types@attribute:attribute()),
binary()
) -> binary().
section(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<section"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</section>"/utf8>>.
-spec article(
gleam@option:option(html_dsl@types@attribute:attribute()),
binary()
) -> binary().
article(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<article"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</article>"/utf8>>.
-spec aside(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
aside(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<aside"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</aside>"/utf8>>.
-spec main(gleam@option:option(html_dsl@types@attribute:attribute()), binary()) -> binary().
main(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<main"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</main>"/utf8>>.
-spec button(
gleam@option:option(html_dsl@types@attribute:attribute()),
binary()
) -> binary().
button(Attributes, Inner) ->
Att_str = html_dsl@types@attribute:attribute_to_string(Attributes),
<<<<<<<<"<button"/utf8, Att_str/binary>>/binary, ">"/utf8>>/binary,
Inner/binary>>/binary,
"</button>"/utf8>>.