Initial commit: there's still tons of base Phoenix boilerplate to remove, but the...
[tech-radar-editor.git] / web / web.ex
1 defmodule TechRadarEditor.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 TechRadarEditor.Web, :controller
9 use TechRadarEditor.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 model do
20 quote do
21 use Ecto.Schema
22
23 import Ecto
24 import Ecto.Changeset
25 import Ecto.Query
26 end
27 end
28
29 def controller do
30 quote do
31 use Phoenix.Controller
32
33 alias TechRadarEditor.Repo
34 import Ecto
35 import Ecto.Query
36
37 import TechRadarEditor.Router.Helpers
38 import TechRadarEditor.Gettext
39 end
40 end
41
42 def view do
43 quote do
44 use Phoenix.View, root: "web/templates"
45
46 # Import convenience functions from controllers
47 import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]
48
49 # Use all HTML functionality (forms, tags, etc)
50 use Phoenix.HTML
51
52 import TechRadarEditor.Router.Helpers
53 import TechRadarEditor.ErrorHelpers
54 import TechRadarEditor.Gettext
55 end
56 end
57
58 def router do
59 quote do
60 use Phoenix.Router
61 end
62 end
63
64 def channel do
65 quote do
66 use Phoenix.Channel
67
68 alias TechRadarEditor.Repo
69 import Ecto
70 import Ecto.Query
71 import TechRadarEditor.Gettext
72 end
73 end
74
75 @doc """
76 When used, dispatch to the appropriate controller/view/etc.
77 """
78 defmacro __using__(which) when is_atom(which) do
79 apply(__MODULE__, which, [])
80 end
81 end