enchufe_web.ex 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. defmodule EnchufeWeb 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 EnchufeWeb, :controller
  7. use EnchufeWeb, :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: EnchufeWeb
  18. import Plug.Conn
  19. import EnchufeWeb.Router.Helpers
  20. import EnchufeWeb.Gettext
  21. end
  22. end
  23. def view do
  24. quote do
  25. use Phoenix.View, root: "lib/enchufe_web/templates",
  26. namespace: EnchufeWeb
  27. # Import convenience functions from controllers
  28. import Phoenix.Controller, only: [get_flash: 2, view_module: 1]
  29. # Use all HTML functionality (forms, tags, etc)
  30. use Phoenix.HTML
  31. import EnchufeWeb.Router.Helpers
  32. import EnchufeWeb.ErrorHelpers
  33. import EnchufeWeb.Gettext
  34. end
  35. end
  36. def router do
  37. quote do
  38. use Phoenix.Router
  39. import Plug.Conn
  40. import Phoenix.Controller
  41. end
  42. end
  43. def channel do
  44. quote do
  45. use Phoenix.Channel
  46. import EnchufeWeb.Gettext
  47. end
  48. end
  49. @doc """
  50. When used, dispatch to the appropriate controller/view/etc.
  51. """
  52. defmacro __using__(which) when is_atom(which) do
  53. apply(__MODULE__, which, [])
  54. end
  55. end