podcast_feed_web.ex 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. defmodule PodcastFeedWeb 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 PodcastFeedWeb, :controller
  7. use PodcastFeedWeb, :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: PodcastFeedWeb
  18. import Plug.Conn
  19. import PodcastFeedWeb.Gettext
  20. alias PodcastFeedWeb.Router.Helpers, as: Routes
  21. end
  22. end
  23. def view do
  24. quote do
  25. use Phoenix.View,
  26. root: "lib/podcast_feed_web/templates",
  27. namespace: PodcastFeedWeb
  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 router do
  36. quote do
  37. use Phoenix.Router
  38. import Plug.Conn
  39. import Phoenix.Controller
  40. end
  41. end
  42. def channel do
  43. quote do
  44. use Phoenix.Channel
  45. import PodcastFeedWeb.Gettext
  46. end
  47. end
  48. defp view_helpers do
  49. quote do
  50. # Use all HTML functionality (forms, tags, etc)
  51. use Phoenix.HTML
  52. # Import basic rendering functionality (render, render_layout, etc)
  53. import Phoenix.View
  54. import PodcastFeedWeb.ErrorHelpers
  55. import PodcastFeedWeb.Gettext
  56. alias PodcastFeedWeb.Router.Helpers, as: Routes
  57. end
  58. end
  59. @doc """
  60. When used, dispatch to the appropriate controller/view/etc.
  61. """
  62. defmacro __using__(which) when is_atom(which) do
  63. apply(__MODULE__, which, [])
  64. end
  65. end