vaccins_web.ex 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. defmodule VaccinsWeb do
  2. @moduledoc """
  3. The entrypoint for defining your web interface, such
  4. as controllers, views, channels and so on.
  5. This can be used in your application as:
  6. use VaccinsWeb, :controller
  7. use VaccinsWeb, :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: VaccinsWeb
  18. import Plug.Conn
  19. import VaccinsWeb.Gettext
  20. alias VaccinsWeb.Router.Helpers, as: Routes
  21. end
  22. end
  23. def view do
  24. quote do
  25. use Phoenix.View,
  26. root: "lib/vaccins_web/templates",
  27. namespace: VaccinsWeb
  28. # Import convenience functions from controllers
  29. import Phoenix.Controller,
  30. only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
  31. # Include shared imports and aliases for views
  32. unquote(view_helpers())
  33. end
  34. end
  35. def live_view do
  36. quote do
  37. use Phoenix.LiveView,
  38. layout: {VaccinsWeb.LayoutView, "live.html"}
  39. unquote(view_helpers())
  40. end
  41. end
  42. def live_component do
  43. quote do
  44. use Phoenix.LiveComponent
  45. unquote(view_helpers())
  46. end
  47. end
  48. def router do
  49. quote do
  50. use Phoenix.Router
  51. import Plug.Conn
  52. import Phoenix.Controller
  53. import Phoenix.LiveView.Router
  54. end
  55. end
  56. def channel do
  57. quote do
  58. use Phoenix.Channel
  59. import VaccinsWeb.Gettext
  60. end
  61. end
  62. defp view_helpers do
  63. quote do
  64. # Use all HTML functionality (forms, tags, etc)
  65. use Phoenix.HTML
  66. # Import LiveView helpers (live_render, live_component, live_patch, etc)
  67. import Phoenix.LiveView.Helpers
  68. # Import basic rendering functionality (render, render_layout, etc)
  69. import Phoenix.View
  70. import VaccinsWeb.ErrorHelpers
  71. import VaccinsWeb.Gettext
  72. alias VaccinsWeb.Router.Helpers, as: Routes
  73. end
  74. end
  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