drab v0.10.5 Drab.Config View Source
Drab configuration.
Drab works over the Phoenix Endpoints. You must provide configuration for each endpoint. The minimum is to set up the endpoint module name, and the application name, so for the application configured like:
config :my_app_web, MyAppWeb.Endpoint,
...
provide corresponding Drab configuration:
config :drab, MyAppWeb.Endpoint,
otp_app: :my_app_web,
...
There are also global Drab options, which can’t be configured by the endpoint, like
:enable_live_scripts
. See the whole list below.
Configuration options:
Endpoint related options
This options are set within the endpoint:
config :drab, MyAppWeb.Endpoint, option: value, option: value
:access_session (default: []
)
Keys of the session map, which will be included to the Drab Session globally, usually
:user_id
, etc. See Drab.Commander.access_session/1
for more.
:browser_response_timeout (default: 5000
)
Timeout, after which all functions querying/updating browser UI will give up; integer in
milliseconds, or :infinity
.
:disable_controls_while_processing (default: true
)
After sending request to the server, sender object will be disabled until it gets the answer. Warning: this behaviour is not broadcasted, so only the control in the current browser is going to be disabled.
:disable_controls_when_disconnected (default: true
)
Shall controls be disabled when there is no connectivity between the browser and the server?
:drab_store_storage (default: :session_storage
)
Where to keep the Drab Store - :memory
, :local_storage
or :session_storage
. Data in
the memory is kept to the next page load, session storage persist until browser (or a tab)
is closed, local storage is kept forever.
:events_shorthands (default: ["click", "change", "keyup", "keydown"]
)
The list of the shorthand attributes to be used in drab-controlled DOM object, ie:
<drab-click="handler">
. Please keep the list small, as it affects the client JS performance.
:events_to_disable_while_processing (default: ["click"]
)
Controls with those Drab events will be disabled when waiting for server response.
:js_socket_constructor, (default: "require("phoenix").Socket"
)
Javascript constructor for the Socket; more info in Drab.Client.
:live_conn_pass_through, *(default: `%{private: %{phoenix_endpoint: true,
phoenix_controller: true, phoenix_action: true}}`)*
A deep map marking fields which should be preserved in the fake @conn
assign. See Drab.Live
for more detailed explanation on conn case.
:socket (default: "/socket"
)
Path to the socket on which Drab operates.
:templates_path (default: “priv/templates/drab”)
Path to the user-defined Drab templates (not to be confused with Phoenix application templates,
these are to be used internally, see Drab.Modal
for the example usage). Must start with
“priv/“.
:token_max_age (default: 86_400
)
Socket token max age in seconds.
Global configuration options
Those options are set globally and works in every endpoint.
config :drab, option: value, option: value
:default_encoder (default: Drab.Coder.Cipher
)
Sets the default encoder/decoder for the various functions, like Drab.Browser.set_cookie/3
.
:default_modules (default: [Drab.Live, Drab.Element, Drab.Modal]
)
Sets the default Drab Modules. May be overwritten individually in the commander with
use Drab.Commander, modules: [...]
.
:enable_live_scripts (default: false
)
Re-evaluation of JavaScripts containing living assigns is disabled by default.
:modal_css (default: :bootstrap3
)
A CSS framework used to show Drab.Modal
. Available: :bootstrap3
, :bootstrap4
.
:phoenix_channel_options (default: []
)
An options passed to use Phoenix.Channel
, for example: [log_handle_in: false]
.
:presence (default: false
)
Runs the Drab.Presence
server. Defaults to false to avoid unnecessary load. See
Drab.Presence
for more information.
:secret_key_base (default taken from endpoint)
Random key for ciphering. May be generated by mix phx.gen.secret
. In single-endpoint
configuration it is taken from the endpoint.
Link to this section Summary
Functions
Returns the name of all configured Drab endpoints
Returns the name of the client Phoenix Application for given endpoint
Returns the name of all configured Drab applications
Returns configured Drab.Live.Engine Extension. String with dot at the begin
Returns Drab configuration for the given atom
Returns Drab configuration for the given endpoint and atom
Returns the PubSub module of the given endpoint
Link to this section Functions
Returns the name of all configured Drab endpoints.
iex> Drab.Config.app_endpoints()
[DrabTestApp.Endpoint]
Returns the name of the client Phoenix Application for given endpoint.
iex> Drab.Config.app_name(DrabTestApp.Endpoint)
:drab
Returns the name of all configured Drab applications.
iex> Drab.Config.app_names()
[:drab]
Returns configured Drab.Live.Engine Extension. String with dot at the begin.
Example, for config:
config :phoenix, :template_engines,
drab: Drab.Live.Engine
it will return “.drab”
iex> Drab.Config.drab_extension()
".drab"
Returns Drab configuration for the given atom.
iex> Drab.Config.get(:default_encoder)
Drab.Coder.Cipher
Returns Drab configuration for the given endpoint and atom.
iex> Drab.Config.get(DrabTestApp.Endpoint, :templates_path)
"priv/custom_templates"
Returns the PubSub module of the given endpoint.
iex> Drab.Config.pubsub(DrabTestApp.Endpoint)
DrabTestApp.PubSub