-module(render). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([render_element/1]). -spec attributes_to_list(list(elements:html_attribute())) -> binary(). attributes_to_list(Attributes) -> _pipe = Attributes, _pipe@1 = gleam@list:map( _pipe, fun(Attr) -> <<<<<<<<(erlang:element(2, Attr))/binary, "="/utf8>>/binary, "\""/utf8>>/binary, (erlang:element(3, Attr))/binary>>/binary, "\""/utf8>> end ), gleam@string:join(_pipe@1, <<" "/utf8>>). -spec append_if(binary(), fun(() -> boolean()), fun(() -> binary())) -> binary(). append_if(Text, Predicate, Value_func) -> case Predicate() of true -> gleam@string:append(Text, Value_func()); false -> Text end. -spec render_element(elements:html_element()) -> binary(). render_element(Element) -> case Element of {html_element, Tag, Attributes, Children} -> Html = begin _pipe = <<"<"/utf8>>, _pipe@1 = append_if( _pipe, fun() -> Tag =:= <<"html"/utf8>> end, fun() -> <<"!DOCTYPE html><"/utf8>> end ), _pipe@2 = gleam@string:append(_pipe@1, Tag), append_if( _pipe@2, fun() -> erlang:length(Attributes) > 0 end, fun() -> <<" "/utf8, (attributes_to_list(Attributes))/binary>> end ) end, case Children of [] -> _pipe@3 = Html, gleam@string:append(_pipe@3, <<" />"/utf8>>); _ -> Html_childen = begin _pipe@4 = Children, _pipe@5 = gleam@list:map(_pipe@4, fun render_element/1), _pipe@6 = gleam@string:join(_pipe@5, <<""/utf8>>), _pipe@7 = gleam@string:append(_pipe@6, <<">), _pipe@8 = gleam@string:append(_pipe@7, Tag), gleam@string:append(_pipe@8, <<">"/utf8>>) end, _pipe@9 = Html, _pipe@10 = gleam@string:append(_pipe@9, <<">"/utf8>>), gleam@string:append(_pipe@10, Html_childen) end; {text, Value} -> Value end.