hello_web.ex 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. defmodule HelloWeb do
  2. @moduledoc """
  3. A module that keeps using definitions for controllers,
  4. views and so on.
  5. This can be used in your application as:
  6. use HelloWeb, :controller
  7. use HelloWeb, :view
  8. The definitions below will be executed for every view,
  9. controller, etc, so keep them short and clean, focused
  10. on imports, uses and aliases.
  11. Do NOT define functions inside the quoted expressions
  12. below. Instead, define any helper function in modules
  13. and import those modules here.
  14. """
  15. def controller do
  16. quote do
  17. use Phoenix.Controller, namespace: HelloWeb, log: false
  18. # Alias the data repository and import query/model functions
  19. alias Hello.Repo
  20. import Ecto
  21. import Ecto.Query
  22. # Import URL helpers from the router
  23. import HelloWeb.Router.Helpers
  24. end
  25. end
  26. def view do
  27. quote do
  28. use Phoenix.View,
  29. root: "lib/hello_web/templates",
  30. namespace: HelloWeb
  31. alias HelloWeb.Router.Helpers, as: Routes
  32. end
  33. end
  34. def router do
  35. quote do
  36. use Phoenix.Router
  37. end
  38. end
  39. def channel do
  40. quote do
  41. use Phoenix.Channel
  42. # Alias the data repository and import query/model functions
  43. alias Hello.Repo
  44. import Ecto
  45. import Ecto.Query
  46. end
  47. end
  48. @doc """
  49. When used, dispatch to the appropriate controller/view/etc.
  50. """
  51. defmacro __using__(which) when is_atom(which) do
  52. apply(__MODULE__, which, [])
  53. end
  54. end