2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web do
|
2017-12-08 08:58:14 +00:00
|
|
|
@moduledoc """
|
|
|
|
The entrypoint for defining your web interface, such
|
|
|
|
as controllers, views, channels and so on.
|
|
|
|
|
|
|
|
This can be used in your application as:
|
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
use Mobilizon.Web, :controller
|
|
|
|
use Mobilizon.Web, :view
|
2017-12-08 08:58:14 +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.
|
|
|
|
"""
|
|
|
|
|
2023-03-17 18:06:46 +00:00
|
|
|
def static_paths,
|
|
|
|
do:
|
|
|
|
~w(index.html manifest.json service-worker.js css fonts img js favicon.ico robots.txt assets)
|
|
|
|
|
2017-12-08 08:58:14 +00:00
|
|
|
def controller do
|
|
|
|
quote do
|
2020-01-26 20:36:50 +00:00
|
|
|
use Phoenix.Controller, namespace: Mobilizon.Web
|
2017-12-08 08:58:14 +00:00
|
|
|
import Plug.Conn
|
2020-01-26 20:36:50 +00:00
|
|
|
import Mobilizon.Web.Gettext
|
2021-09-10 09:27:59 +00:00
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
2023-03-17 18:06:46 +00:00
|
|
|
unquote(verified_routes())
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def view do
|
|
|
|
quote do
|
2018-07-27 08:45:35 +00:00
|
|
|
use Phoenix.View,
|
2020-01-26 20:36:50 +00:00
|
|
|
root: "lib/web/templates",
|
2021-03-23 14:18:03 +00:00
|
|
|
pattern: "**/*",
|
2020-01-26 20:36:50 +00:00
|
|
|
namespace: Mobilizon.Web
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
# Use all HTML functionality (forms, tags, etc)
|
|
|
|
use Phoenix.HTML
|
|
|
|
|
2021-09-10 09:27:59 +00:00
|
|
|
import Phoenix.View
|
|
|
|
import Mobilizon.Web.ErrorHelpers
|
2020-01-26 20:36:50 +00:00
|
|
|
import Mobilizon.Web.Gettext
|
2021-09-10 09:27:59 +00:00
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
2023-03-17 18:06:46 +00:00
|
|
|
unquote(verified_routes())
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def router do
|
|
|
|
quote do
|
|
|
|
use Phoenix.Router
|
|
|
|
import Plug.Conn
|
|
|
|
import Phoenix.Controller
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def channel do
|
|
|
|
quote do
|
|
|
|
use Phoenix.Channel
|
2020-01-26 20:36:50 +00:00
|
|
|
import Mobilizon.Web.Gettext
|
2017-12-08 08:58:14 +00: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
|
2023-03-17 18:06:46 +00:00
|
|
|
|
|
|
|
def verified_routes do
|
|
|
|
quote do
|
|
|
|
use Phoenix.VerifiedRoutes,
|
|
|
|
endpoint: Mobilizon.Web.Endpoint,
|
|
|
|
router: Mobilizon.Web.Router,
|
|
|
|
statics: Mobilizon.Web.static_paths()
|
|
|
|
end
|
|
|
|
end
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|