Packages

A meta-framework for lustre, enabling a full-stack experience

Current section

Files

Jump to
illustrious src illustrious@internal@router.erl
Raw

src/illustrious@internal@router.erl

-module(illustrious@internal@router).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([parse_path/1, push_path/1, replace_path/1, forward/0, back/0, get_current_path/0, register_callback/1]).
-spec parse_path(binary()) -> list(binary()).
parse_path(Full_path) ->
_assert_subject = gleam@regex:from_string(<<"/"/utf8>>),
{ok, Path_separator} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"illustrious/internal/router"/utf8>>,
function => <<"parse_path"/utf8>>,
line => 15})
end,
{Path, _} = begin
_pipe = gleam@string:split_once(Full_path, <<"?"/utf8>>),
gleam@result:unwrap(_pipe, {Full_path, <<""/utf8>>})
end,
Path_parts = begin
_pipe@1 = gleam@regex:split(Path_separator, Path),
gleam@list:filter(
_pipe@1,
fun(Part) -> gleam@string:length(Part) > 0 end
)
end,
Path_parts.
-spec push_path(binary()) -> nil.
push_path(_) ->
nil.
-spec replace_path(binary()) -> nil.
replace_path(_) ->
nil.
-spec forward() -> nil.
forward() ->
nil.
-spec back() -> nil.
back() ->
nil.
-spec priv_get_current_path() -> binary().
priv_get_current_path() ->
<<"/"/utf8>>.
-spec get_current_path() -> list(binary()).
get_current_path() ->
parse_path(priv_get_current_path()).
-spec priv_register_callback(fun((binary()) -> nil)) -> nil.
priv_register_callback(_) ->
nil.
-spec register_callback(fun((list(binary())) -> nil)) -> nil.
register_callback(Cb) ->
priv_register_callback(fun(Path) -> Cb(parse_path(Path)) end).