HaytniWeb.Shared (Haytni v0.7.0) View Source
Contains shared stuffs between Haytni base plugins.
Mainly handle a message view/template which is intended to replace "abusive" Phoenix.Controller.put_flash/3
.
put_flash
stores messages in session and may have several issues:
- it can conflict if you use multiple tabs or instances of a same browser
- excessive reads/writes (depending on the backend)
- incompatible with HTTP caching
Link to this section Summary
Functions
Momorize the original HTTP referer by adding it to a changeset. Have to be called on new
or edit
action
(not create
nor update
).
Add a back/cancel link for SharedView.
Returns the path to a Haytni controller
Add a next step link for SharedView.
Set connection to render SharedView/message.html.
Returns the path to the login page.
Link to this section Functions
Specs
add_referer_to_changeset(conn :: Plug.Conn.t(), changeset :: Ecto.Changeset.t()) :: Ecto.Changeset.t()
Momorize the original HTTP referer by adding it to a changeset. Have to be called on new
or edit
action
(not create
nor update
).
Specs
back_link(conn :: Plug.Conn.t(), struct :: struct(), default :: String.t()) :: Plug.Conn.t()
Add a back/cancel link for SharedView.
NOTE: we do not use "javascript:history.back()"
as default since this may be inappropriate with Content
Security Policy (CSP). But user is free to use it by indicating it as value for default.
Specs
haytni_path( conn_or_endpoint :: Plug.Conn.t() | module(), module :: module(), fun :: (atom() -> atom()), action :: atom(), args :: Keyword.t() ) :: String.t()
Returns the path to a Haytni controller
Example:
iex> Elixir.HaytniWeb.Shared.haytni_path(conn, YourApp.Haytni, &(:"haytni_#{&1}_invitation_path"), :new, [[invitation: "ABCD", email: "me@mydomain.com"]])
"/invitations/new?invitation=ABCD&email=me%40mydomain.com"
Specs
next_step_link(conn :: Plug.Conn.t(), href :: String.t(), text :: String.t()) :: Plug.Conn.t()
Add a next step link for SharedView.
Specs
render_message( conn :: Plug.Conn.t(), module :: module(), message :: String.t(), type :: atom() ) :: Plug.Conn.t()
Set connection to render SharedView/message.html.
Specs
session_path(conn_or_endpoint :: Plug.Conn.t() | module(), module :: module()) :: String.t()
Returns the path to the login page.