web_web.ex 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. defmodule WebWeb 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 WebWeb, :controller
  7. use WebWeb, :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: WebWeb
  18. import Plug.Conn
  19. import WebWeb.Router.Helpers
  20. import WebWeb.Gettext
  21. end
  22. end
  23. def view do
  24. quote do
  25. use Phoenix.View, root: "lib/web_web/templates",
  26. namespace: WebWeb
  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 WebWeb.Router.Helpers
  32. import WebWeb.ErrorHelpers
  33. import WebWeb.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 WebWeb.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