live_beats/lib/live_beats_web.ex

126 lines
2.9 KiB
Elixir
Raw Normal View History

2021-09-02 18:00:57 +00:00
defmodule LiveBeatsWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
This can be used in your application as:
use LiveBeatsWeb, :controller
2022-11-17 15:01:20 +00:00
use LiveBeatsWeb, :html
2021-09-02 18:00:57 +00:00
The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused
on imports, uses and aliases.
Do NOT define functions inside the quoted expressions
below. Instead, define any helper function in modules
and import those modules here.
"""
2022-11-17 15:01:20 +00:00
def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
2021-09-02 18:00:57 +00:00
def controller do
quote do
2022-11-17 15:01:20 +00:00
use Phoenix.Controller,
namespace: LiveBeatsWeb,
formats: [:html, :json],
layouts: [html: LiveBeatsWeb.Layouts]
2021-09-02 18:00:57 +00:00
import Plug.Conn
import LiveBeatsWeb.Gettext
alias LiveBeatsWeb.Router.Helpers, as: Routes
2022-11-17 20:36:58 +00:00
unquote(verified_routes())
2021-09-02 18:00:57 +00:00
end
end
2022-11-17 15:01:20 +00:00
def html do
2021-09-02 18:00:57 +00:00
quote do
2022-11-17 15:01:20 +00:00
use Phoenix.Component
2021-09-02 18:00:57 +00:00
# Import convenience functions from controllers
import Phoenix.Controller,
2022-11-17 15:01:20 +00:00
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
2024-04-09 00:53:14 +00:00
use Phoenix.Component
2022-11-17 15:01:20 +00:00
# Include general helpers for rendering HTML
unquote(html_helpers())
end
end
2021-09-02 18:00:57 +00:00
2022-11-17 15:01:20 +00:00
def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: LiveBeatsWeb.Endpoint,
router: LiveBeatsWeb.Router,
statics: LiveBeatsWeb.static_paths()
2021-09-02 18:00:57 +00:00
end
end
def live_view(opts \\ []) do
2021-09-02 18:00:57 +00:00
quote do
@opts Keyword.merge(
[
2022-11-17 15:01:20 +00:00
layout: {LiveBeatsWeb.Layouts, :live},
container: {:div, class: "relative h-screen flex overflow-hidden bg-white"}
],
unquote(opts)
)
use Phoenix.LiveView, @opts
2021-09-02 18:00:57 +00:00
2022-11-17 15:01:20 +00:00
unquote(html_helpers())
2021-09-02 18:00:57 +00:00
end
end
def live_component do
quote do
use Phoenix.LiveComponent
2022-11-17 15:01:20 +00:00
unquote(html_helpers())
2021-09-02 18:00:57 +00:00
end
end
def router do
quote do
2022-11-17 20:36:58 +00:00
use Phoenix.Router, helpers: false
2021-09-02 18:00:57 +00:00
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
end
end
def channel do
quote do
use Phoenix.Channel
import LiveBeatsWeb.Gettext
end
end
2022-11-17 15:01:20 +00:00
defp html_helpers do
2021-09-02 18:00:57 +00:00
quote do
# Use all HTML functionality (forms, tags, etc)
import Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers
2021-09-02 18:00:57 +00:00
2022-11-17 15:01:20 +00:00
import LiveBeatsWeb.CoreComponents
2021-09-02 18:00:57 +00:00
import LiveBeatsWeb.Gettext
alias LiveBeatsWeb.Router.Helpers, as: Routes
2021-10-29 16:12:23 +00:00
alias Phoenix.LiveView.JS
2022-11-17 20:36:58 +00:00
unquote(verified_routes())
2021-09-02 18:00:57 +00:00
end
end
@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__({which, opts}) when is_atom(which) do
apply(__MODULE__, which, [opts])
end
2021-09-02 18:00:57 +00:00
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
end