PhoenixMultilingual.View (phoenix_multilingual v0.1.12)
Summary
Functions
Fetches a key from the private View data in the connection and raises an error is not view is found.
Fetches a key from the private View data in the connection or socket. Returns nil if no view data is found.
Functions
Fetches a key from the private View data in the connection and raises an error is not view is found.
Examples
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> conn = Plug.Conn.put_private(%Plug.Conn{}, :multilingual, view)
...> PhoenixMultilingual.View.fetch_key(conn, :path)
"/about"
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> conn = Plug.Conn.put_private(%Plug.Conn{}, :multilingual, view)
...> PhoenixMultilingual.View.fetch_key(conn, :bad_key)
** (FunctionClauseError) no function clause matching in PhoenixMultilingual.View.fetch_key/2
iex> assert_raise PhoenixMultilingual.MissingViewDataInConnError, fn ->
...> PhoenixMultilingual.View.fetch_key(%Plug.Conn{}, :locale)
...> end
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> socket = Phoenix.LiveView.put_private(%Phoenix.LiveView.Socket{}, :multilingual, view)
...> PhoenixMultilingual.View.fetch_key(socket, :path)
"/about"
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> socket = Phoenix.LiveView.put_private(%Phoenix.LiveView.Socket{}, :multilingual, view)
...> PhoenixMultilingual.View.fetch_key(socket, :bad_key)
** (FunctionClauseError) no function clause matching in PhoenixMultilingual.View.fetch_key/2
iex> assert_raise PhoenixMultilingual.MissingViewDataInSocketError, fn ->
...> PhoenixMultilingual.View.fetch_key(%Phoenix.LiveView.Socket{}, :locale)
...> end
Fetches a key from the private View data in the connection or socket. Returns nil if no view data is found.
Raises an error if an erroneous key is requested.
Examples
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> conn = Plug.Conn.put_private(%Plug.Conn{}, :multilingual, view)
...> PhoenixMultilingual.View.get_key(conn, :path)
"/about"
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> conn = Plug.Conn.put_private(%Plug.Conn{}, :multilingual, view)
...> PhoenixMultilingual.View.get_key(conn, :bad_key)
** (FunctionClauseError) no function clause matching in PhoenixMultilingual.View.get_key/2
iex> PhoenixMultilingual.View.get_key(%Plug.Conn{}, :path)
nil
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> socket = Phoenix.LiveView.put_private(%Phoenix.LiveView.Socket{}, :multilingual, view)
...> PhoenixMultilingual.View.get_key(socket, :path)
"/about"
iex> view = %PhoenixMultilingual.View{locale: "en", path: "/about"}
...> socket = Phoenix.LiveView.put_private(%Phoenix.LiveView.Socket{}, :multilingual, view)
...> PhoenixMultilingual.View.get_key(socket, :bad_key)
** (FunctionClauseError) no function clause matching in PhoenixMultilingual.View.get_key/2
iex> PhoenixMultilingual.View.get_key(%Phoenix.LiveView.Socket{}, :locale)
nil