Merge branch 'develop' into dtluna/pleroma-refactor/1
[akkoma] / lib / pleroma / web / web.ex
1 defmodule Pleroma.Web do
2 @moduledoc """
3 A module that keeps using definitions for controllers,
4 views and so on.
5
6 This can be used in your application as:
7
8 use Pleroma.Web, :controller
9 use Pleroma.Web, :view
10
11 The definitions below will be executed for every view,
12 controller, etc, so keep them short and clean, focused
13 on imports, uses and aliases.
14
15 Do NOT define functions inside the quoted expressions
16 below.
17 """
18
19 def controller do
20 quote do
21 use Phoenix.Controller, namespace: Pleroma.Web
22 import Plug.Conn
23 import Pleroma.Web.{Gettext, Router.Helpers}
24 end
25 end
26
27 def view do
28 quote do
29 use Phoenix.View, root: "lib/pleroma/web/templates",
30 namespace: Pleroma.Web
31
32 # Import convenience functions from controllers
33 import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]
34
35 import Pleroma.Web.{ErrorHelpers, Gettext, Router.Helpers}
36 end
37 end
38
39 def router do
40 quote do
41 use Phoenix.Router
42 import Plug.Conn
43 import Phoenix.Controller
44 end
45 end
46
47 def channel do
48 quote do
49 use Phoenix.Channel
50 import Pleroma.Web.Gettext
51 end
52 end
53
54 @doc """
55 When used, dispatch to the appropriate controller/view/etc.
56 """
57 defmacro __using__(which) when is_atom(which) do
58 apply(__MODULE__, which, [])
59 end
60
61 def base_url do
62 Pleroma.Web.Endpoint.url
63 end
64 end