Tayori.Router (Tayori v0.1.0)

Copy Markdown View Source

Mounts Tayori in the app's router.

import Tayori.Router

scope "/admin" do
  pipe_through [:browser, :require_admin]

  tayori_admin "/news",
    resolver: MyAppWeb.TayoriResolver,
    on_mount: [{MyAppWeb.AdminAuth, :require_admin}]
end

scope "/api" do
  pipe_through :api_session
  tayori_api "/news", resolver: MyAppWeb.TayoriResolver
end

scope "/" do
  pipe_through :browser
  tayori_page "/changelog", title: "What's new in MyApp"
end

tayori_admin/2 mounts the admin (see the Admin guide), tayori_api/2 the news as JSON, for a frontend that Phoenix does not render (see Any frontend), and tayori_page/2 the public page and its feeds (see The public page). Each is a library mounted with PhoenixMountable: ordinary routes in the app's router (mix phx.routes lists them), behind the app's own scopes and pipelines. Every mount also takes the options of PhoenixMountable: :as (to mount one twice), :on_mount, :socket_path, :transport, :csp_nonce_assign_key, :asset_host and :pubsub.

The admin is a page of its own, as Lotus's dashboard is: its own document, script and style sheet, served under the mount with the hash of the build in their names, so it looks the same in any app.

Summary

Functions

Mounts Tayori.Router at path in a host router.

Mounts the news as JSON at path: see Tayori.Router.API for the options, and Tayori.API for the routes.

Mounts the public page of the news, its entries and its feeds at path: see Tayori.Router.Page for the options, and Tayori.Page for the routes.

Functions

tayori_admin(path, opts \\ [])

(macro)

Mounts Tayori.Router at path in a host router.

import Tayori.Router

scope "/" do
  pipe_through :browser
  tayori_admin "/tayori"
end

Options

  • :resolver (atom/0) - Required. The app's Tayori.Resolver: who the admin is, and what they may do.

  • :theme - The admin's theme: Tayori's own, or Sumi's. The default value is :tayori.

  • :page (String.t/0) - The path of the public page, for the admin's links to the entries and their previews. By default, the tayori_page of the same router.

  • :storage (atom/0) - The Kotoba.Storage of the attachments of the editor (Kotoba's own config when not given).

Every mount also takes the options listed in PhoenixMountable, such as :as, :on_mount and :csp_nonce_assign_key.

tayori_api(path, opts \\ [])

(macro)

Mounts the news as JSON at path: see Tayori.Router.API for the options, and Tayori.API for the routes.

tayori_page(path, opts \\ [])

(macro)

Mounts the public page of the news, its entries and its feeds at path: see Tayori.Router.Page for the options, and Tayori.Page for the routes.