Packages
lustre
3.1.3
5.7.1
5.7.0
5.6.0
5.5.2
5.5.1
5.5.0
5.4.0
5.3.5
5.3.4
5.3.3
5.3.2
5.3.1
5.3.0
5.2.1
5.2.0
5.1.1
5.1.0
5.0.3
5.0.2
5.0.1
5.0.0
4.6.4
4.6.3
4.6.2
4.6.1
4.6.0
4.5.1
4.5.0
4.4.4
4.4.3
4.4.1
4.4.0
4.3.6
4.3.5
4.3.4
4.3.3
4.3.2
4.3.1
4.3.0
4.2.6
4.2.5
4.2.4
4.2.3
4.2.2
4.2.1
4.2.0
4.1.8
4.1.7
4.1.6
4.1.5
4.1.4
4.1.3
4.1.2
4.1.1
4.1.0
4.0.0
4.0.0-rc1
4.0.0-rc.2
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.12
3.0.11
3.0.10
3.0.9
3.0.8
3.0.7
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
3.0.0-rc.8
3.0.0-rc.7
3.0.0-rc.6
3.0.0-rc.5
3.0.0-rc.4
3.0.0-rc.3
3.0.0-rc.2
3.0.0-rc.1
2.0.1
2.0.0
1.3.0
1.2.0
1.1.0
1.0.0
Create HTML templates, single page applications, Web Components, and real-time server components in Gleam!
Current section
Files
Jump to
Current section
Files
src/lustre@try.erl
-module(lustre@try).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([main/0]).
-export_type([options/0]).
-type options() :: {options, binary(), integer(), boolean()}.
-spec host_flag() -> glint@flag:flag_builder(binary()).
host_flag() ->
_pipe = glint@flag:string(),
_pipe@1 = glint@flag:default(_pipe, <<"localhost"/utf8>>),
glint@flag:description(_pipe@1, <<"The host to run the server on"/utf8>>).
-spec port_flag() -> glint@flag:flag_builder(integer()).
port_flag() ->
_pipe = glint@flag:int(),
_pipe@1 = glint@flag:default(_pipe, 1234),
glint@flag:description(_pipe@1, <<"The port to run the server on"/utf8>>).
-spec include_styles_flag() -> glint@flag:flag_builder(boolean()).
include_styles_flag() ->
_pipe = glint@flag:bool(),
_pipe@1 = glint@flag:default(_pipe, false),
glint@flag:description(
_pipe@1,
<<"Include lustre_ui's default stylesheet in your app."/utf8>>
).
-spec on_start(binary(), integer()) -> nil.
on_start(Host, Port) ->
Address = <<<<<<"http://"/utf8, Host/binary>>/binary, ":"/utf8>>/binary,
(gleam@int:to_string(Port))/binary>>,
gleam@io:println(
<<"✨ Server has been started at "/utf8,
(gleam_community@ansi:bold(Address))/binary>>
).
-spec on_port_taken(integer()) -> nil.
on_port_taken(Port) ->
gleam@io:println(
<<<<"🚨 Port "/utf8,
(gleam_community@ansi:bold(gleam@int:to_string(Port)))/binary>>/binary,
" already in use, using next available port"/utf8>>
).
-spec main() -> nil.
main() ->
Args = erlang:element(4, argv:load()),
Program = begin
_pipe = glint:new(),
_pipe@1 = glint:with_name(_pipe, <<"gleam run -m lustre/try"/utf8>>),
_pipe@2 = glint:with_pretty_help(_pipe@1, glint:default_pretty_help()),
glint:add(
_pipe@2,
[],
begin
_pipe@3 = glint:command(
fun(Input) ->
{command_input, _, Flags} = Input,
_assert_subject = glint@flag:get_int(
Flags,
<<"port"/utf8>>
),
{ok, Port} = 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 => <<"lustre/try"/utf8>>,
function => <<"main"/utf8>>,
line => 37})
end,
_assert_subject@1 = glint@flag:get_string(
Flags,
<<"host"/utf8>>
),
{ok, Host} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"lustre/try"/utf8>>,
function => <<"main"/utf8>>,
line => 38})
end,
_assert_subject@2 = glint@flag:get_bool(
Flags,
<<"include-styles"/utf8>>
),
{ok, Include_styles} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@2,
module => <<"lustre/try"/utf8>>,
function => <<"main"/utf8>>,
line => 39})
end,
Options = {options, Host, Port, Include_styles},
http_ffi:exec(<<"gleam build --target js"/utf8>>),
http_ffi:serve(
Options,
fun(_capture) -> on_start(Host, _capture) end,
fun on_port_taken/1
)
end
),
_pipe@4 = glint:flag(_pipe@3, <<"host"/utf8>>, host_flag()),
_pipe@5 = glint:flag(_pipe@4, <<"port"/utf8>>, port_flag()),
glint:flag(
_pipe@5,
<<"include-styles"/utf8>>,
include_styles_flag()
)
end
)
end,
glint:run(Program, Args).