PhoenixMountable.Definition (PhoenixMountable v0.2.1)

Copy Markdown View Source

The macros of a definition module: options/1, routes/1 and pipeline/2.

They are imported by use PhoenixMountable.

Options

options/1 declares the options of the mount macro, as a NimbleOptions schema. They are validated when the host router compiles, and documented in the mount macro's docs.

options resolver: [
          type: :atom,
          default: MyLib.Resolver,
          verify: {:behaviour, MyLib.Resolver},
          doc: "The module that resolves the current user."
        ],
        features: [type: {:list, :atom}, default: []]

Besides the NimbleOptions keys, an option can have :verify: :module checks that the value names an existing module, and {:behaviour, mod} also checks that it implements mod (or is mod). The check runs after the host router compiles: a module that uses the host's verified routes depends on the router, so checking it while the router compiles would deadlock.

The values are in mount.options, a map with every declared option.

Routes

routes/1 declares the library's routes with the macros of PhoenixMountable.Routes, relative to the mount path:

routes do
  get "/export", MyLib.ExportController, :csv

  live_session :default, on_mount: [MyLib.Auth] do
    live "/", MyLib.HomeLive, :index
  end
end

Pipelines

pipeline/2 defines a pipeline of the library, like Phoenix.Router.pipeline/2, for its routes to pipe_through. It is compiled into a module plug, so the host needs nothing in its own router.

pipeline :api do
  plug :accepts, ["json"]
end

Summary

Functions

Declares the options of the mount macro. See the module documentation.

Defines a pipeline of the library. See the module documentation.

Declares the routes of the library. See PhoenixMountable.Routes.

Functions

options(schema)

(macro)

Declares the options of the mount macro. See the module documentation.

pipeline(name, list)

(macro)

Defines a pipeline of the library. See the module documentation.

routes(list)

(macro)

Declares the routes of the library. See PhoenixMountable.Routes.