-module(sketch_css@utils). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([remove_last_segment/1, at/2, outputs/2, remove_trailing_underscore/1, directories/3]). -export_type([directories/0, outputs/0]). -type directories() :: {directories, binary(), binary(), binary()}. -type outputs() :: {outputs, binary(), binary(), binary(), binary()}. -file("/Users/doctor/Workspace/sketch/sketch_css/src/sketch_css/utils.gleam", 48). -spec remove_last_segment(binary()) -> binary(). remove_last_segment(Path) -> Segments = gleam@string:split(Path, <<"/"/utf8>>), Segments@1 = gleam@list:take(Segments, erlang:length(Segments) - 1), gleam@string:join(Segments@1, <<"/"/utf8>>). -file("/Users/doctor/Workspace/sketch/sketch_css/src/sketch_css/utils.gleam", 54). -spec at(list(XQT), integer()) -> {ok, XQT} | {error, nil}. at(List, Index) -> gleam@bool:guard(Index < 0, {error, nil}, fun() -> case List of [] -> {error, nil}; [Elem | _] when Index =:= 0 -> {ok, Elem}; [_ | Rest] -> at(Rest, Index - 1) end end). -file("/Users/doctor/Workspace/sketch/sketch_css/src/sketch_css/utils.gleam", 64). -spec outputs(directories(), binary()) -> outputs(). outputs(Directories, Name) -> Dst_file = gleam@string:join( [erlang:element(3, Directories), Name], <<"/"/utf8>> ), Dst_file@1 = gleam@string:join([Dst_file, <<"css"/utf8>>], <<"."/utf8>>), Interface_file = gleam@string:join( [erlang:element(4, Directories), Name], <<"/"/utf8>> ), Interface_file@1 = gleam@string:join( [Interface_file, <<"gleam"/utf8>>], <<"."/utf8>> ), Dst = remove_last_segment(Dst_file@1), Interface = remove_last_segment(Interface_file@1), {outputs, Dst, Dst_file@1, Interface, Interface_file@1}. -file("/Users/doctor/Workspace/sketch/sketch_css/src/sketch_css/utils.gleam", 74). -spec remove_trailing_underscore(binary()) -> binary(). remove_trailing_underscore(Label) -> case gleam_stdlib:string_ends_with(Label, <<"_"/utf8>>) of false -> Label; true -> _pipe = gleam@string:drop_end(Label, 1), remove_trailing_underscore(_pipe) end. -file("/Users/doctor/Workspace/sketch/sketch_css/src/sketch_css/utils.gleam", 99). -spec read_config_directory(sketch_css@uniconfig:config(), binary()) -> gleam@option:option({binary(), binary()}). read_config_directory(Config, Key) -> _pipe = erlang:element(4, Config), _pipe@1 = tom:get_string(_pipe, [Key]), _pipe@2 = gleam@option:from_result(_pipe@1), gleam@option:map( _pipe@2, fun(_capture) -> gleam@pair:new(erlang:element(2, Config), _capture) end ). -file("/Users/doctor/Workspace/sketch/sketch_css/src/sketch_css/utils.gleam", 83). -spec read_directory( binary(), gleam@option:option(binary()), binary(), gleam@option:option(sketch_css@uniconfig:config()), binary() ) -> binary(). read_directory(Key, Flag, Cwd, Config, Default) -> _pipe = Flag, _pipe@1 = gleam@option:map( _pipe, fun(_capture) -> gleam@pair:new(Cwd, _capture) end ), _pipe@3 = gleam@option:lazy_unwrap( _pipe@1, fun() -> _pipe@2 = gleam@option:then( Config, fun(_capture@1) -> read_config_directory(_capture@1, Key) end ), gleam@option:unwrap(_pipe@2, {Cwd, Default}) end ), (fun(Res) -> gleam@string:join( [erlang:element(1, Res), erlang:element(2, Res)], <<"/"/utf8>> ) end)(_pipe@3). -file("/Users/doctor/Workspace/sketch/sketch_css/src/sketch_css/utils.gleam", 34). -spec directories( gleam@option:option(binary()), gleam@option:option(binary()), gleam@option:option(binary()) ) -> {ok, directories()} | {error, snag:snag()}. directories(Src, Dst, Interface) -> Config = begin _pipe = sketch_css@uniconfig:read(<<"sketch_css"/utf8>>), gleam@option:from_result(_pipe) end, gleam@result:map( sketch_css@fs:cwd(), fun(Cwd) -> Src@1 = read_directory( <<"src"/utf8>>, Src, Cwd, Config, <<"src"/utf8>> ), Dst@1 = read_directory( <<"dst"/utf8>>, Dst, Cwd, Config, <<"public/styles"/utf8>> ), {directories, Src@1, Dst@1, (read_directory( <<"interface"/utf8>>, Interface, Cwd, Config, <<"src/sketch/styles"/utf8>> ))} end ).