4 ms·
And actually the <project>Web macros are a great way to show people when macros are useful. A fun exercise for beginners might be to have them manually import t
by dqv 5y ago
And actually the <project>Web macros are a great way to show people when macros are useful. A fun exercise for beginners might be to have them manually import those modules. And it illuminates some aspects of Phoenix in general e.g. "oh I'm importing Phoenix.Controller in all my views." In other words, the fact that you're rendering a view from a controller is not the reason you have controller functions available in your views, it's because your importing Phoenix.Controller when you "use ProjectWeb, :view"
- dugmartin 5y agoYeah, the "magic" dispatcher code in <project>_web.ex is pretty powerful but I'm not sure it would be easy for beginners to grok it: @doc """ When used, dispatch to the appropriate controller/view/etc. """ defmacro __using__(which) when is_atom(which) do apply(__MODULE__, which, []) end That said I much prefer how Phoenix puts this code explicitly in each project and doesn't hide it in a gem like Rails.
- dqv 5y agoFor example’s sake, it would be fine to just remove that and do it manually: defmacro __using__(:view), do: view() But I think explaining what each element does in that dispatcher would be helpful. Especially in cases with typos.