One mounted instance of a mountable library.
A host that calls a mount macro twice (for example an admin and a public mount of the same library) gets two mounts, each with its own path and options. The mount is available wherever the library's code runs:
- in LiveViews, as
socket.assigns.mount(and@mountin templates); - in controllers and plugs on the library's routes, as
conn.assigns.mountandconn.private.phoenix_mountable; - anywhere in the process that handles the request or LiveView, through
current/0.
Fields
:definition— the library's definition module (the one that callsuse PhoenixMountable):name— the mount name, the host's:asoption:path— the full mount path, including the host's enclosing scopes:router,:endpoint— the host's router and endpoint (:endpointis set at runtime):options— the library's options as given by the host, validated and with defaults, as a map:socket_path,:transport— where and how the LiveView socket connects:csp_nonces— the CSP nonces of the current request, by kind (:script,:style, ...), read from the host's assigns:asset_host— an optional scheme and host for asset URLs (a CDN):assets— the asset strategy and its state:pubsub— the PubSub server forPhoenixMountable.PubSub, if the host gave one; otherwise the endpoint's is used:session— the library live session the current LiveView belongs to
Summary
Functions
The mount of the current process: the LiveView or request being handled.
Returns {:ok, mount} for a socket, conn or assigns map, or :error.
Returns the mount of a socket, conn or assigns map, raising if there is none.
A key that identifies the mount on this node: {router, name}.
Returns the value of a library option.
Another mount of the same router, by its name (the mount macro, or its
:as), from a mount, a conn, a socket or an assigns map. Returns nil
when the host has not mounted it.
Types
@type t() :: %PhoenixMountable.Mount{ asset_host: String.t() | nil, assets: {module(), term()} | nil, csp_nonce_assign_key: nil | atom() | map(), csp_nonces: map(), definition: module(), endpoint: module() | nil, host_on_mount: list(), name: atom(), options: map(), path: String.t(), pubsub: atom() | nil, router: module(), session: atom() | nil, socket_path: String.t(), transport: :websocket | :longpoll }
Functions
@spec current() :: t() | nil
The mount of the current process: the LiveView or request being handled.
Set by PhoenixMountable when a library LiveView mounts and when a request
reaches a library route. Returns nil outside of them.
Returns {:ok, mount} for a socket, conn or assigns map, or :error.
Returns the mount of a socket, conn or assigns map, raising if there is none.
A key that identifies the mount on this node: {router, name}.
Returns the value of a library option.
Another mount of the same router, by its name (the mount macro, or its
:as), from a mount, a conn, a socket or an assigns map. Returns nil
when the host has not mounted it.
A library with several definitions links from one to another with it: its admin to its public page, say, wherever the host put the page.
PhoenixMountable.Mount.sibling(conn, :my_lib_page)
#=> %PhoenixMountable.Mount{name: :my_lib_page, path: "/changelog", ...}See PhoenixMountable.Path.path/3 for its paths.