Packages

Zero-flash SSR + claim for Lustre/Gleam on the BEAM.

Current section

Files

Jump to
glamour src glamour@app.erl
Raw

src/glamour@app.erl

-module(glamour@app).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glamour/app.gleam").
-export([new/4, with_selector/2, with_state_script_id/2, selector/1, state_script_id/1]).
-export_type([spec/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.
-type spec(OCP, OCQ) :: {spec,
lustre:app(OCP, OCP, OCQ),
fun((OCP) -> lustre@vdom@vnode:element(OCQ)),
fun((OCP) -> gleam@json:json()),
gleam@dynamic@decode:decoder(OCP),
binary(),
binary()}.
-file("src/glamour/app.gleam", 29).
?DOC(
" Create a new Glamour spec using the provided Lustre application, JSON\n"
" encoder, and decoder. The default mount selector is `#app` and the embedded\n"
" state script id is `glamour-state`.\n"
).
-spec new(
lustre:app(OCR, OCR, OCS),
fun((OCR) -> lustre@vdom@vnode:element(OCS)),
fun((OCR) -> gleam@json:json()),
gleam@dynamic@decode:decoder(OCR)
) -> spec(OCR, OCS).
new(App, View, Encode, Decoder) ->
{spec,
App,
View,
Encode,
Decoder,
<<"#app"/utf8>>,
<<"glamour-state"/utf8>>}.
-file("src/glamour/app.gleam", 46).
?DOC(" Change the CSS selector Glamour should target when claiming the DOM.\n").
-spec with_selector(spec(ODA, ODB), binary()) -> spec(ODA, ODB).
with_selector(Spec, Selector) ->
{spec,
erlang:element(2, Spec),
erlang:element(3, Spec),
erlang:element(4, Spec),
erlang:element(5, Spec),
Selector,
erlang:element(7, Spec)}.
-file("src/glamour/app.gleam", 54).
?DOC(" Change the id used for the embedded JSON script tag.\n").
-spec with_state_script_id(spec(ODG, ODH), binary()) -> spec(ODG, ODH).
with_state_script_id(Spec, Id) ->
{spec,
erlang:element(2, Spec),
erlang:element(3, Spec),
erlang:element(4, Spec),
erlang:element(5, Spec),
erlang:element(6, Spec),
Id}.
-file("src/glamour/app.gleam", 63).
?DOC(
" Produce an option so the selector can be customised ergonomically with\n"
" `option.Option` pipelines.\n"
).
-spec selector(binary()) -> fun((spec(ODM, ODN)) -> spec(ODM, ODN)).
selector(Selector) ->
fun(Spec) -> with_selector(Spec, Selector) end.
-file("src/glamour/app.gleam", 68).
?DOC(" Produce an option so the state script id can be adjusted via pipelines.\n").
-spec state_script_id(binary()) -> fun((spec(ODS, ODT)) -> spec(ODS, ODT)).
state_script_id(Id) ->
fun(Spec) -> with_state_script_id(Spec, Id) end.