An example AT Protocol application, written in Elixir using atex and Drinkup.
1defmodule StatusphereWeb do
2 @moduledoc """
3 The entrypoint for defining your web interface, such
4 as controllers, components, channels, and so on.
5
6 This can be used in your application as:
7
8 use StatusphereWeb, :controller
9 use StatusphereWeb, :html
10
11 The definitions below will be executed for every controller,
12 component, 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. Instead, define additional modules and import
17 those modules here.
18 """
19
20 def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
21
22 def router do
23 quote do
24 use Phoenix.Router, helpers: false
25
26 # Import common connection and controller functions to use in pipelines
27 import Plug.Conn
28 import Phoenix.Controller
29 import Phoenix.LiveView.Router
30 end
31 end
32
33 def channel do
34 quote do
35 use Phoenix.Channel
36 end
37 end
38
39 def controller do
40 quote do
41 use Phoenix.Controller, formats: [:html, :json]
42
43 import Plug.Conn
44
45 unquote(verified_routes())
46 end
47 end
48
49 def live_view do
50 quote do
51 use Phoenix.LiveView
52
53 unquote(html_helpers())
54 end
55 end
56
57 def live_component do
58 quote do
59 use Phoenix.LiveComponent
60
61 unquote(html_helpers())
62 end
63 end
64
65 def html do
66 quote do
67 use Phoenix.Component
68
69 # Import convenience functions from controllers
70 import Phoenix.Controller,
71 only: [get_csrf_token: 0, view_module: 1, view_template: 1]
72
73 # Include general helpers for rendering HTML
74 unquote(html_helpers())
75 end
76 end
77
78 defp html_helpers do
79 quote do
80 # HTML escaping functionality
81 import Phoenix.HTML
82 # Core UI components
83 import StatusphereWeb.CoreComponents
84
85 # Common modules used in templates
86 alias Phoenix.LiveView.JS
87 alias StatusphereWeb.Layouts
88
89 # Routes generation with the ~p sigil
90 unquote(verified_routes())
91 end
92 end
93
94 def verified_routes do
95 quote do
96 use Phoenix.VerifiedRoutes,
97 endpoint: StatusphereWeb.Endpoint,
98 router: StatusphereWeb.Router,
99 statics: StatusphereWeb.static_paths()
100 end
101 end
102
103 @doc """
104 When used, dispatch to the appropriate controller/live_view/etc.
105 """
106 defmacro __using__(which) when is_atom(which) do
107 apply(__MODULE__, which, [])
108 end
109end