Files
homepage/lib/homepage_web.ex

115 lines
2.6 KiB
Elixir
Raw Permalink Normal View History

defmodule HomepageWeb do
@moduledoc """
The entrypoint for defining your web interface, such
2023-11-07 08:52:09 +01:00
as controllers, components, channels, and so on.
This can be used in your application as:
use HomepageWeb, :controller
2023-11-07 08:52:09 +01:00
use HomepageWeb, :html
2023-11-07 08:52:09 +01:00
The definitions below will be executed for every controller,
component, etc, so keep them short and clean, focused
on imports, uses and aliases.
Do NOT define functions inside the quoted expressions
2023-11-07 08:52:09 +01:00
below. Instead, define additional modules and import
those modules here.
"""
2023-11-07 08:52:09 +01:00
def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
def static_digested, do: ~w(android-chrome apple-touch-icon favicon site.webmanifest)
def router do
quote do
2023-11-07 08:52:09 +01:00
use Phoenix.Router, helpers: false
2023-11-07 08:52:09 +01:00
# Import common connection and controller functions to use in pipelines
import Plug.Conn
2023-11-07 08:52:09 +01:00
import Phoenix.Controller
import Phoenix.LiveView.Router
end
end
def channel do
quote do
use Phoenix.Channel
end
end
2023-11-07 08:52:09 +01:00
def controller do
quote do
2023-11-07 08:52:09 +01:00
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: HomepageWeb.Layouts]
2023-11-07 08:52:09 +01:00
import Plug.Conn
import HomepageWeb.Gettext
2023-11-07 08:52:09 +01:00
unquote(verified_routes())
end
end
def live_view do
quote do
use Phoenix.LiveView,
2023-11-07 08:52:09 +01:00
layout: {HomepageWeb.Layouts, :app}
2023-11-07 08:52:09 +01:00
unquote(html_helpers())
end
end
def live_component do
quote do
use Phoenix.LiveComponent
2023-11-07 08:52:09 +01:00
unquote(html_helpers())
end
end
2023-11-07 08:52:09 +01:00
def html do
quote do
use Phoenix.Component
2023-11-07 08:52:09 +01:00
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
2023-11-07 08:52:09 +01:00
# Include general helpers for rendering HTML
unquote(html_helpers())
end
end
2023-11-07 08:52:09 +01:00
defp html_helpers do
quote do
2023-11-07 08:52:09 +01:00
# HTML escaping functionality
import Phoenix.HTML
# Core UI components and translation
import HomepageWeb.CoreComponents
import HomepageWeb.Gettext
2023-11-07 08:52:09 +01:00
# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
# Routes generation with the ~p sigil
unquote(verified_routes())
end
end
2023-11-07 08:52:09 +01:00
def verified_routes do
quote do
2023-11-07 08:52:09 +01:00
use Phoenix.VerifiedRoutes,
endpoint: HomepageWeb.Endpoint,
router: HomepageWeb.Router,
statics: HomepageWeb.static_paths()
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