Packages

A simplifier for Plug applications. Template rendering, redirecting, error codes

Current section

Files

Jump to
ex_web lib ex_web.ex
Raw

lib/ex_web.ex

defmodule ExWeb do
alias Plug.Conn
def render(conn, module, page \\ :index, assigns \\ %{})
def render(%Conn{} = conn, module, page, assigns) do
page = "#{page}"
assigns = Map.merge(assigns, %{ex_web_module: module, ex_web_page: page})
conn
|> Conn.send_resp(200, apply(module, :render, [page, assigns]))
end
def redirect_to(%Conn{} = conn, url, body \\ nil) do
html_url = Plug.HTML.html_escape(url)
body = if body == nil do
"<html><body>You are being <a href=\"#{html_url}\">redirected</a>.</body></html>"
else
body
end
conn
|> Plug.Conn.put_resp_header("location", url)
|> Plug.Conn.send_resp(302, body)
end
end