Current section
Files
Jump to
Current section
Files
src/nakai.erl
-module(nakai).
-compile(no_auto_import).
-export([const_component/1, component/2, fragment/1, nothing/0, render/1, render_with_document_attrs/2, render_with_doctype/2]).
-spec const_component(fun(() -> nakai@html:node_(HCW))) -> nakai@html:node_(HCW).
const_component(Func) ->
{component, Func}.
-spec component(fun((HCZ) -> nakai@html:node_(HDA)), HCZ) -> nakai@html:node_(HDA).
component(Func, Props) ->
{component, fun() -> Func(Props) end}.
-spec fragment(list(nakai@html:node_(HDD))) -> nakai@html:node_(HDD).
fragment(Children) ->
{fragment, Children}.
-spec nothing() -> nakai@html:node_(any()).
nothing() ->
nothing.
-spec render(nakai@html:node_(any())) -> binary().
render(Root) ->
_pipe = gleam@string_builder:concat(
[nakai@render:render_doctype(nakai@html:doctype(<<"html"/utf8>>)),
gleam@string_builder:from_string(<<"\n"/utf8>>),
nakai@render:render_root(Root, []),
gleam@string_builder:from_string(<<"\n"/utf8>>)]
),
gleam@string_builder:to_string(_pipe).
-spec render_with_document_attrs(
nakai@html:node_(HDL),
list(nakai@html@attrs:attr(HDL))
) -> binary().
render_with_document_attrs(Root, Attrs) ->
_pipe = gleam@string_builder:concat(
[nakai@render:render_doctype(nakai@html:doctype(<<"html"/utf8>>)),
gleam@string_builder:from_string(<<"\n"/utf8>>),
nakai@render:render_root(Root, Attrs),
gleam@string_builder:from_string(<<"\n"/utf8>>)]
),
gleam@string_builder:to_string(_pipe).
-spec render_with_doctype(nakai@html@doctype:doctype(), nakai@html:node_(any())) -> binary().
render_with_doctype(Doctype, Root) ->
_pipe = gleam@string_builder:concat(
[nakai@render:render_doctype(Doctype),
gleam@string_builder:from_string(<<"\n"/utf8>>),
nakai@render:render_root(Root, []),
gleam@string_builder:from_string(<<"\n"/utf8>>)]
),
gleam@string_builder:to_string(_pipe).