2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web do
|
2017-12-08 09:58:14 +01: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 21:36:50 +01:00
|
|
|
use Mobilizon.Web, :controller
|
|
|
|
use Mobilizon.Web, :view
|
2017-12-08 09:58:14 +01: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 19:06:46 +01:00
|
|
|
def static_paths,
|
|
|
|
do:
|
2023-08-10 21:50:45 +02:00
|
|
|
~w(index.html manifest.json manifest.webmanifest service-worker.js css fonts img js favicon.ico robots.txt assets)
|
2023-03-17 19:06:46 +01:00
|
|
|
|
2017-12-08 09:58:14 +01:00
|
|
|
def controller do
|
|
|
|
quote do
|
2020-01-26 21:36:50 +01:00
|
|
|
use Phoenix.Controller, namespace: Mobilizon.Web
|
2017-12-08 09:58:14 +01:00
|
|
|
import Plug.Conn
|
2020-01-26 21:36:50 +01:00
|
|
|
import Mobilizon.Web.Gettext
|
2021-09-10 11:27:59 +02:00
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
2023-03-17 19:06:46 +01:00
|
|
|
unquote(verified_routes())
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def view do
|
|
|
|
quote do
|
2018-07-27 10:45:35 +02:00
|
|
|
use Phoenix.View,
|
2020-01-26 21:36:50 +01:00
|
|
|
root: "lib/web/templates",
|
2021-03-23 15:18:03 +01:00
|
|
|
pattern: "**/*",
|
2020-01-26 21:36:50 +01:00
|
|
|
namespace: Mobilizon.Web
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
# Use all HTML functionality (forms, tags, etc)
|
|
|
|
use Phoenix.HTML
|
|
|
|
|
2021-09-10 11:27:59 +02:00
|
|
|
import Phoenix.View
|
|
|
|
import Mobilizon.Web.ErrorHelpers
|
2020-01-26 21:36:50 +01:00
|
|
|
import Mobilizon.Web.Gettext
|
2021-09-10 11:27:59 +02:00
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
2023-03-17 19:06:46 +01:00
|
|
|
unquote(verified_routes())
|
2017-12-08 09:58:14 +01: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 21:36:50 +01:00
|
|
|
import Mobilizon.Web.Gettext
|
2017-12-08 09:58:14 +01: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 19:06:46 +01: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 09:58:14 +01:00
|
|
|
end
|