-module(roundabout@generate_helpers). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/roundabout/generate_helpers.gleam"). -export([get_function_arguments/3, generate_helpers_rec/2]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/roundabout/generate_helpers.gleam", 111). ?DOC(false). -spec get_function_arguments( list(roundabout@node:info()), list(roundabout@node:segment()), roundabout@node:info() ) -> list(roundabout@node:segment()). get_function_arguments(Ancestors, Acc, Info) -> Current_segments = begin _pipe = Acc, gleam@list:filter_map(_pipe, fun(Segment) -> case Segment of {seg_lit, _} -> {error, <<""/utf8>>}; {seg_param, Param} -> New_name = <<<<(roundabout@type_name:snake( erlang:element(2, Info) ))/binary, "_"/utf8>>/binary, (roundabout@parameter:name(Param))/binary>>, gleam@result:'try'( roundabout@parameter:new( New_name, roundabout@parameter:kind(Param) ), fun(New_param) -> _pipe@1 = {seg_param, New_param}, {ok, _pipe@1} end ) end end) end, New_segments = begin _pipe@2 = erlang:element(3, Info), gleam@list:filter_map(_pipe@2, fun(Segment@1) -> case Segment@1 of {seg_lit, _} -> {error, nil}; {seg_param, Param@1} -> New_name@1 = (<<<<(roundabout@type_name:snake( erlang:element(2, Info) ))/binary, "_"/utf8>>/binary, (roundabout@parameter:name(Param@1))/binary>>), gleam@result:'try'( begin _pipe@3 = roundabout@parameter:new( New_name@1, roundabout@parameter:kind(Param@1) ), gleam@result:replace_error(_pipe@3, nil) end, fun(New_param@1) -> {ok, {seg_param, New_param@1}} end ) end end) end, Next_acc = lists:append(New_segments, Current_segments), case Ancestors of [Next_ancestor | Rest_ancestors] -> get_function_arguments(Rest_ancestors, Next_acc, Next_ancestor); _ -> Next_acc end. -file("src/roundabout/generate_helpers.gleam", 63). -spec generate_path_helper( list(roundabout@node:info()), roundabout@node:node_() ) -> glam@doc:document(). generate_path_helper(Ancestors, Cont) -> Function_name_prefix = roundabout@common:get_function_name( Ancestors, erlang:element(2, Cont) ), Route_function_name = <>, Path_function_name = <>, Function_arguments = get_function_arguments( Ancestors, [], erlang:element(2, Cont) ), This_function_arguments = begin _pipe = Function_arguments, _pipe@2 = gleam@list:filter_map(_pipe, fun(Segment) -> case Segment of {seg_lit, _} -> {error, nil}; {seg_param, Name} -> _pipe@1 = roundabout@parameter:full(Name), {ok, _pipe@1} end end), gleam@string:join(_pipe@2, <<", "/utf8>>) end, Callee_arguments = begin _pipe@3 = Function_arguments, _pipe@4 = gleam@list:filter_map( _pipe@3, fun(Segment@1) -> case Segment@1 of {seg_lit, _} -> {error, nil}; {seg_param, Name@1} -> {ok, roundabout@parameter:name(Name@1)} end end ), gleam@string:join(_pipe@4, <<", "/utf8>>) end, Body = begin _pipe@5 = glam@doc:from_string( <<<<<>/binary, Callee_arguments/binary>>/binary, ")"/utf8>> ), _pipe@6 = glam@doc:append(_pipe@5, roundabout@common:pipe_join()), glam@doc:append(_pipe@6, glam@doc:from_string(<<"route_to_path"/utf8>>)) end, glam@doc:concat( [glam@doc:from_string( <<<<<<<<"pub fn "/utf8, Path_function_name/binary>>/binary, "("/utf8>>/binary, This_function_arguments/binary>>/binary, ") -> String {"/utf8>> ), glam@doc:nest_docs([{line, 1}, Body], 2), {line, 1}, glam@doc:from_string(<<"}"/utf8>>), glam@doc:lines(2)] ). -file("src/roundabout/generate_helpers.gleam", 167). -spec generate_route_helper_body( list(roundabout@node:info()), list(glam@doc:document()), roundabout@node:info() ) -> list(glam@doc:document()). generate_route_helper_body(Ancestors, Acc, Info) -> Params = begin _pipe = erlang:element(3, Info), _pipe@2 = gleam@list:filter_map(_pipe, fun(Segment) -> case Segment of {seg_lit, _} -> {error, nil}; {seg_param, Param} -> _pipe@1 = (<<<<(roundabout@type_name:snake( erlang:element(2, Info) ))/binary, "_"/utf8>>/binary, (roundabout@parameter:name(Param))/binary>>), {ok, _pipe@1} end end), (fun(Entries) -> case gleam@list:is_empty(Acc) of true -> Entries; false -> lists:append(Entries, [<<"_"/utf8>>]) end end)(_pipe@2) end, Params@1 = case gleam@list:is_empty(Params) of true -> <<""/utf8>>; false -> <<<<"("/utf8, (gleam@string:join(Params, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> end, Type_name = roundabout@common:get_type_name(Ancestors, Info), New_line = glam@doc:from_string(<>), Next_acc = case Type_name of <<""/utf8>> -> Acc; _ -> lists:append(Acc, [New_line]) end, case Ancestors of [Next_ancestor | Rest_ancestors] -> generate_route_helper_body(Rest_ancestors, Next_acc, Next_ancestor); _ -> Next_acc end. -file("src/roundabout/generate_helpers.gleam", 35). -spec generate_route_helper( list(roundabout@node:info()), roundabout@node:node_() ) -> glam@doc:document(). generate_route_helper(Ancestors, Cont) -> Function_name = <<(roundabout@common:get_function_name( Ancestors, erlang:element(2, Cont) ))/binary, "_route"/utf8>>, Function_arguments = begin _pipe = get_function_arguments(Ancestors, [], erlang:element(2, Cont)), _pipe@2 = gleam@list:filter_map(_pipe, fun(Segment) -> case Segment of {seg_lit, _} -> {error, nil}; {seg_param, Param} -> _pipe@1 = roundabout@parameter:full(Param), {ok, _pipe@1} end end), gleam@string:join(_pipe@2, <<", "/utf8>>) end, Body = begin _pipe@3 = generate_route_helper_body( Ancestors, [], erlang:element(2, Cont) ), glam@doc:join(_pipe@3, roundabout@common:pipe_join()) end, glam@doc:concat( [glam@doc:from_string( <<<<<<<<"pub fn "/utf8, Function_name/binary>>/binary, "("/utf8>>/binary, Function_arguments/binary>>/binary, ") -> Route {"/utf8>> ), glam@doc:nest_docs([{line, 1}, Body], 2), {line, 1}, glam@doc:from_string(<<"}"/utf8>>), glam@doc:lines(2)] ). -file("src/roundabout/generate_helpers.gleam", 28). ?DOC(" helpers\n"). -spec generate_helpers(list(roundabout@node:info()), roundabout@node:node_()) -> glam@doc:document(). generate_helpers(Ancestors, Node) -> glam@doc:concat( [generate_route_helper(Ancestors, Node), generate_path_helper(Ancestors, Node)] ). -file("src/roundabout/generate_helpers.gleam", 11). ?DOC(false). -spec generate_helpers_rec( list(roundabout@node:info()), roundabout@node:node_() ) -> glam@doc:document(). generate_helpers_rec(Ancestors, Node) -> case gleam@list:is_empty(erlang:element(3, Node)) of true -> generate_helpers(Ancestors, Node); false -> Next_ancestors = gleam@list:prepend( Ancestors, erlang:element(2, Node) ), _pipe = gleam@list:map( erlang:element(3, Node), fun(Node@1) -> generate_helpers_rec(Next_ancestors, Node@1) end ), glam@doc:concat(_pipe) end.