cover/Elixir.DaProductAppWeb.html

1 defmodule DaProductAppWeb 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 DaProductAppWeb, :controller
9 use DaProductAppWeb, :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 4 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,
42 formats: [:html, :json],
43 layouts: [html: DaProductAppWeb.Layouts]
44
45 use Gettext, backend: DaProductAppWeb.Gettext
46
47 import Plug.Conn
48
49 unquote(verified_routes())
50 end
51 end
52
53 def live_view do
54 quote do
55 use Phoenix.LiveView,
56 layout: {DaProductAppWeb.Layouts, :app}
57
58 unquote(html_helpers())
59 end
60 end
61
62 def live_component do
63 quote do
64 use Phoenix.LiveComponent
65
66 unquote(html_helpers())
67 end
68 end
69
70 def html do
71 quote do
72 use Phoenix.Component
73
74 # Import convenience functions from controllers
75 import Phoenix.Controller,
76 only: [get_csrf_token: 0, view_module: 1, view_template: 1]
77
78 # Include general helpers for rendering HTML
79 unquote(html_helpers())
80 end
81 end
82
83 defp html_helpers do
84 quote do
85 # Translation
86 use Gettext, backend: DaProductAppWeb.Gettext
87
88 # HTML escaping functionality
89 import Phoenix.HTML
90 # Core UI components
91 import DaProductAppWeb.CoreComponents
92
93 # Shortcut for generating JS commands
94 alias Phoenix.LiveView.JS
95
96 # Routes generation with the ~p sigil
97 unquote(verified_routes())
98 end
99 end
100
101 def verified_routes do
102 quote do
103 use Phoenix.VerifiedRoutes,
104 endpoint: DaProductAppWeb.Endpoint,
105 router: DaProductAppWeb.Router,
106 statics: DaProductAppWeb.static_paths()
107 end
108 end
109
110 @doc """
111 When used, dispatch to the appropriate controller/live_view/etc.
112 """
113 defmacro __using__(which) when is_atom(which) do
114 4 apply(__MODULE__, which, [])
115 end
116 end
Line Hits Source