livebook/lib/livebook_web.ex

93 lines
1.9 KiB
Elixir
Raw Normal View History

defmodule LivebookWeb do
@moduledoc false
2021-01-08 03:55:45 +08:00
2023-02-23 02:34:54 +08:00
def static_paths, do: ~w(js css fonts images favicon.svg favicon.png robots.txt)
2021-01-08 03:55:45 +08:00
def controller do
quote do
2023-02-23 02:34:54 +08:00
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: LivebookWeb.Layouts]
2021-01-08 03:55:45 +08:00
import Plug.Conn
2022-10-04 14:46:55 +08:00
2023-02-23 02:34:54 +08:00
unquote(verified_routes())
2021-01-08 03:55:45 +08:00
end
end
2021-01-08 04:16:54 +08:00
def live_view do
quote do
2023-02-23 02:34:54 +08:00
use Phoenix.LiveView, layout: {LivebookWeb.Layouts, :live}
2021-01-08 04:16:54 +08:00
2023-02-23 02:34:54 +08:00
unquote(html_helpers())
2021-01-08 04:16:54 +08:00
end
end
def live_component do
quote do
use Phoenix.LiveComponent
2023-02-23 02:34:54 +08:00
unquote(html_helpers())
2021-01-08 04:16:54 +08:00
end
end
2021-01-08 03:55:45 +08:00
def router do
quote do
2023-02-23 02:34:54 +08:00
use Phoenix.Router, helpers: false
2021-01-08 03:55:45 +08:00
import Plug.Conn
import Phoenix.Controller
2021-01-08 04:16:54 +08:00
import Phoenix.LiveView.Router
2021-01-08 03:55:45 +08:00
end
end
2023-02-23 02:34:54 +08:00
def html do
quote do
use Phoenix.Component
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
# Include general helpers for rendering HTML
unquote(html_helpers())
end
end
defp html_helpers do
2021-01-08 03:55:45 +08:00
quote do
2023-02-23 02:34:54 +08:00
# HTML escaping functionality
2022-10-04 14:46:55 +08:00
import Phoenix.HTML
2021-01-08 03:55:45 +08:00
2023-02-23 02:34:54 +08:00
# Core UI components
import LivebookWeb.CoreComponents
import LivebookWeb.FormComponents
2021-01-08 04:16:54 +08:00
2023-02-23 02:34:54 +08:00
# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
# Custom helpers
import LivebookWeb.Helpers
2023-02-23 02:34:54 +08:00
# Routes generation with the ~p sigil
unquote(verified_routes())
end
end
def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: LivebookWeb.Endpoint,
router: LivebookWeb.Router,
statics: LivebookWeb.static_paths()
2021-01-08 03:55:45 +08:00
end
end
@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
end