Skip to content

Commit

Permalink
Update dependencies and configure logger backend
Browse files Browse the repository at this point in the history
  • Loading branch information
eliknebel committed Feb 27, 2024
1 parent 950fe61 commit 16b2845
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 333 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gleam 0.32.4
gleam 0.34.1
nodejs 19.7.0
erlang 26.0.2
10 changes: 5 additions & 5 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ gleam = ">= 0.32.0"
#]

[dependencies]
gleam_stdlib = "~> 0.32"
gleam_stdlib = "~> 0.35"
gleam_http = "~> 3.5"
mist = "~> 0.14"
sprocket = "~> 0.1.10"
mist = "~> 0.17"
sprocket = "~> 0.2.0"
#sprocket = { path = "../sprocket" }
gleam_erlang = "~> 0.22"
gleam_json = "~> 0.6"
gleam_crypto = "~> 0.4"
glint = "~> 0.11.4"
gleam_otp = "~> 0.7"
ids = "~> 0.10"
simplifile = "~> 1.0"
birl = "~> 1.5"

[dev-dependencies]
gleeunit = "~> 0.10"
gleeunit = "~> 1.0"
38 changes: 18 additions & 20 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_community_ansi", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "8B5A9677BC5A2738712BBAF2BA289B1D8195FDF962BBC769569976AD5E9794E1" },
{ name = "gleam_community_colour", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "036C206886AFB9F153C552700A7A0B4D2864E3BC96A20C77E5F34A013C051BE3" },
{ name = "birl", version = "1.5.0", build_tools = ["gleam"], requirements = ["ranger", "gleam_stdlib"], otp_app = "birl", source = "hex", outer_checksum = "23BFE5AB0D7D9E4ECC5BB89B7ABDDF8E976D98C65D2E173D116E6AAFBF24E633" },
{ name = "gleam_crypto", version = "0.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "8DACF0294E82A49ACD755E68EA3C118FD9F71DEF741E049E49E79993A257B698" },
{ name = "gleam_erlang", version = "0.23.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "C21CFB816C114784E669FFF4BBF433535EEA9960FA2F216209B8691E87156B96" },
{ name = "gleam_http", version = "3.5.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "AECDA43AFD523D07A8F09068598A6E271C505278A0CB6F9C7A2E4365EAE8D11E" },
{ name = "gleam_json", version = "0.7.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB405BD93A8828BCD870463DE29375E7B2D252D9D124C109E5B618AAC00B86FC" },
{ name = "gleam_otp", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "18EF8242A5E54BA92F717C7222F03B3228AEE00D1F286D4C56C3E8C18AA2588E" },
{ name = "gleam_stdlib", version = "0.32.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "ABF00CDCCB66FABBCE351A50060964C4ACE798F95A0D78622C8A7DC838792577" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "glint", version = "0.11.4", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "snag", "gleam_community_colour", "gleam_stdlib"], otp_app = "glint", source = "hex", outer_checksum = "9508BF037E35F549C51F9F1D2CC4736CEA7F7A49E21CCA9B4540452C7D6CC4C5" },
{ name = "glisten", version = "0.9.2", build_tools = ["gleam"], requirements = ["gleam_otp", "gleam_erlang", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "C960B6CF25D4AABAB01211146E9B57E11827B9C49E4175217E0FB7EF5BCB0FF7" },
{ name = "ids", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang", "gleam_otp"], otp_app = "ids", source = "hex", outer_checksum = "912A21722E07E68117B92863D05B15BE97E5AEF4ECF47C2F567CECCD5A4F5739" },
{ name = "mist", version = "0.14.3", build_tools = ["gleam"], requirements = ["glisten", "gleam_erlang", "gleam_otp", "gleam_http", "gleam_stdlib"], otp_app = "mist", source = "hex", outer_checksum = "191F4CC2CFEE55C5DABD04D76E8C191A2ABB9E0C38C6AE504323609FE72899DD" },
{ name = "simplifile", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0BD6F0E7DA1A7E11D18B8AD48453225CAFCA4C8CFB4513D217B372D2866C501C" },
{ name = "snag", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "8FD70D8FB3728E08AC425283BB509BB0F012BE1AE218424A597CDE001B0EE589" },
{ name = "sprocket", version = "0.1.10", build_tools = ["gleam"], requirements = ["glint", "gleam_erlang", "gleam_http", "ids", "gleam_json", "gleam_otp", "gleam_crypto", "gleam_stdlib"], otp_app = "sprocket", source = "hex", outer_checksum = "F188AEEB70F042A4286183F3F95DF975171EDFE45DE83BE276E3C66666F48BDA" },
{ name = "gleam_erlang", version = "0.24.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "26BDB52E61889F56A291CB34167315780EE4AA20961917314446542C90D1C1A0" },
{ name = "gleam_http", version = "3.5.3", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "C2FC3322203B16F897C1818D9810F5DEFCE347F0751F3B44421E1261277A7373" },
{ name = "gleam_json", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB405BD93A8828BCD870463DE29375E7B2D252D9D124C109E5B618AAC00B86FC" },
{ name = "gleam_otp", version = "0.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "5FADBBEC5ECF3F8B6BE91101D432758503192AE2ADBAD5602158977341489F71" },
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "glisten", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang", "gleam_otp"], otp_app = "glisten", source = "hex", outer_checksum = "73BC09C8487C2FFC0963BFAB33ED2F0D636FDFA43B966E65C1251CBAB8458099" },
{ name = "ids", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang", "gleam_otp"], otp_app = "ids", source = "hex", outer_checksum = "C0772022F69E6C91825115F6C7053F1AE2F5567A31650229B7B8749F8F429F3C" },
{ name = "mist", version = "0.17.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glisten", "gleam_erlang", "gleam_http", "gleam_otp"], otp_app = "mist", source = "hex", outer_checksum = "DA8ACEE52C1E4892A75181B3166A4876D8CBC69D555E4770250BC84C80F75524" },
{ name = "ranger", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "28E615AE7590ED922AF1510DDF606A2ECBBC2A9609AF36D412EDC925F06DFD20" },
{ name = "simplifile", version = "1.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "C93A62CE23B2E44F969DC3134F9EE899C362B0A2F4181233CDD5D759F82EE486" },
{ name = "sprocket", version = "0.2.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_otp", "gleam_stdlib", "ids", "gleam_json", "gleam_crypto", "gleam_erlang"], otp_app = "sprocket", source = "hex", outer_checksum = "0D7D165D622451BC67DBEA26F195DED39165E96113B142FF200F9F727AFFF19D" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
]

[requirements]
birl = { version = "~> 1.5"}
gleam_crypto = { version = "~> 0.4" }
gleam_erlang = { version = "~> 0.22" }
gleam_http = { version = "~> 3.5" }
gleam_json = { version = "~> 0.6" }
gleam_otp = { version = "~> 0.7" }
gleam_stdlib = { version = "~> 0.32" }
gleeunit = { version = "~> 0.10" }
glint = { version = "~> 0.11.4" }
gleam_stdlib = { version = "~> 0.35" }
gleeunit = { version = "~> 1.0" }
ids = { version = "~> 0.10" }
mist = { version = "~> 0.14" }
mist = { version = "~> 0.17" }
simplifile = { version = "~> 1.0" }
sprocket = { version = "~> 0.1.10" }
sprocket = { version = "~> 0.2.0" }
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"build": "gleam build && yarn run client:build && yarn run tailwind:build"
},
"dependencies": {
"sprocket-js": "^0.1.6"
"sprocket-js": "^0.1.9"
}
}
}
4 changes: 2 additions & 2 deletions src/app/app_context.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sprocket/cassette.{type Cassette}
import sprocket.{type CSRFValidator}

pub type AppContext {
AppContext(secret_key_base: String, ca: Cassette)
AppContext(secret_key_base: String, validate_csrf: CSRFValidator)
}
13 changes: 5 additions & 8 deletions src/app/components/clock.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import gleam/io
import gleam/int
import gleam/erlang
import gleam/option.{type Option, None, Some}
import sprocket/context.{type Context, WithDeps, dep}
import sprocket/component.{render}
import sprocket/hooks.{effect, reducer}
import sprocket/html/elements.{span, text}
import sprocket/html/elements.{fragment, span, text}
import sprocket/internal/utils/timer.{interval}

type Model {
Expand Down Expand Up @@ -57,7 +58,6 @@ pub fn clock(ctx: Context, props: ClockProps) {
fn() {
let interval_duration = case time_unit {
erlang.Millisecond -> 1
erlang.Second -> 1000
_ -> 1000
}

Expand All @@ -74,16 +74,13 @@ pub fn clock(ctx: Context, props: ClockProps) {
WithDeps([dep(time), dep(time_unit)]),
)

let current_time = format_unix_timestamp(time, time_unit)
let current_time = int.to_string(time)

render(
ctx,
case label {
fragment(case label {
Some(label) -> [span([], [text(label)]), span([], [text(current_time)])]
None -> [text(current_time)]
},
}),
)
}

@external(erlang, "sprocket_starter_ffi", "format_unix_timestamp")
pub fn format_unix_timestamp(a: Int, b: erlang.TimeUnit) -> String
120 changes: 52 additions & 68 deletions src/app/components/counter.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,32 @@ pub fn counter(ctx: Context, props: CounterProps) {

render(
ctx,
[
div(
[class("flex flex-row m-4")],
[
component(
button,
StyledButtonProps(
class: "rounded-l",
label: "-",
on_click: fn() { dispatch(UpdateCounter(count - 1)) },
),
),
component(
display,
DisplayProps(
count: count,
on_reset: Some(fn() {
case enable_reset {
True -> dispatch(ResetCounter)
False -> Nil
}
}),
),
),
component(
button,
StyledButtonProps(
class: "rounded-r",
label: "+",
on_click: fn() { dispatch(UpdateCounter(count + 1)) },
),
),
],
div([class("flex flex-row m-4")], [
component(
button,
StyledButtonProps(class: "rounded-l", label: "-", on_click: fn() {
dispatch(UpdateCounter(count - 1))
}),
),
],
component(
display,
DisplayProps(
count: count,
on_reset: Some(fn() {
case enable_reset {
True -> dispatch(ResetCounter)
False -> Nil
}
}),
),
),
component(
button,
StyledButtonProps(class: "rounded-r", label: "+", on_click: fn() {
dispatch(UpdateCounter(count + 1))
}),
),
]),
)
}

Expand All @@ -89,20 +80,18 @@ pub fn button(ctx: Context, props: ButtonProps) {

render(
ctx,
[
button_text(
[
attributes.on_click(handle_click),
classes([
class,
Some(
"p-1 px-2 border dark:border-gray-500 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 active:bg-gray-300 dark:active:bg-gray-600",
),
]),
],
label,
),
],
button_text(
[
attributes.on_click(handle_click),
classes([
class,
Some(
"p-1 px-2 border dark:border-gray-500 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 active:bg-gray-300 dark:active:bg-gray-600",
),
]),
],
label,
),
)
}

Expand All @@ -113,28 +102,23 @@ pub type DisplayProps {
pub fn display(ctx: Context, props: DisplayProps) {
let DisplayProps(count: count, on_reset: on_reset) = props

use ctx, client_doubleclick <- double_click(
ctx,
fn() {
case on_reset {
Some(on_reset) -> on_reset()
None -> Nil
}
},
)
use ctx, client_doubleclick <- double_click(ctx, fn() {
case on_reset {
Some(on_reset) -> on_reset()
None -> Nil
}
})

render(
ctx,
[
span(
[
client_doubleclick(),
class(
"p-1 px-2 w-10 bg-white dark:bg-gray-900 border-t border-b dark:border-gray-500 align-center text-center select-none",
),
],
[text(int.to_string(count))],
),
],
span(
[
client_doubleclick(),
class(
"p-1 px-2 w-10 bg-white dark:bg-gray-900 border-t border-b dark:border-gray-500 align-center text-center select-none",
),
],
[text(int.to_string(count))],
),
)
}
38 changes: 15 additions & 23 deletions src/app/components/hello_button.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn update(model: Model, msg: Msg) -> Model {
case msg {
NoOp -> model
SayHello ->
Model(..model, selection: Some(int.random(0, list.length(model.options))))
Model(..model, selection: Some(int.random(list.length(model.options))))
}
}

Expand Down Expand Up @@ -52,32 +52,24 @@ pub fn hello_button(ctx: Context, _props: HelloButtonProps) {

render(
ctx,
[
div(
[],
div([], [
button(
[
button(
[
class(
"p-2 bg-blue-500 hover:bg-blue-600 active:bg-blue-700 text-white rounded",
),
on_click(say_hello),
],
[text("Say Hello!")],
class(
"p-2 bg-blue-500 hover:bg-blue-600 active:bg-blue-700 text-white rounded",
),
..case hello {
None -> []
Some(hello) -> [
span([class("ml-2")], [text(pair.second(hello))]),
span(
[class("ml-2 text-gray-400 bold")],
[text(pair.first(hello))],
),
]
}
on_click(say_hello),
],
[text("Say Hello!")],
),
],
..case hello {
None -> []
Some(hello) -> [
span([class("ml-2")], [text(pair.second(hello))]),
span([class("ml-2 text-gray-400 bold")], [text(pair.first(hello))]),
]
}
]),
)
}

Expand Down
12 changes: 7 additions & 5 deletions src/app/router.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import gleam/bytes_builder.{type BytesBuilder}
import gleam/string
import gleam/bit_array
import gleam/result
import gleam/option.{None}
import gleam/erlang
import gleam/http.{Get}
import gleam/http/request.{type Request}
Expand All @@ -16,22 +17,23 @@ import app/utils/common.{mist_response}
import app/app_context.{type AppContext}
import app/views/index_view.{IndexViewProps, index_view}
import app/page_route
import mist_sprocket
import mist_sprocket.{component}

pub fn router(app_ctx: AppContext) {
pub fn router(app: AppContext) {
fn(request: Request(Connection)) -> Response(ResponseData) {
use <- rescue_crashes()

case request.method, request.path_segments(request) {
Get, _ ->
mist_sprocket.live(
component(
request,
app_ctx.ca,
index_view,
IndexViewProps(
route: page_route.from_string(request.path),
csrf: csrf.generate(app_ctx.secret_key_base),
csrf: csrf.generate(app.secret_key_base),
),
app.validate_csrf,
None,
)

_, _ ->
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/logger.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub type Level {
/// want, rather than the more verbose Erlang default format.
///
@external(erlang, "sprocket_starter_ffi", "configure_logger_backend")
pub fn configure_backend() -> Nil
pub fn configure_backend(level: Level) -> Nil

@external(erlang, "logger", "log")
fn erlang_log(a: Level, b: String) -> Dynamic
Expand Down
Loading

0 comments on commit 16b2845

Please sign in to comment.