I have an umbrella app that I’m now upgrading to Phoenix 1.7, LiveView 1.0.0. I have three different Phoenix applications under the umbrella, and each one has a CoreCompoents module (copied from the one generated for a new Phoenix application)
I would like to keep just one collection of CoreComponents in the umbrella in a library that the Phoenix applications could all import. Then if I make changes, they are all in one place (DRY!). But core_components.ex hard codes a few app-specific Gettext modules:
# app-specific import
import MyAppWeb.Gettext
# gettext macro imported from MyAppWeb.Gettext
<.flash kind={:info} title={gettext("Success!")} flash={@flash} />
<.flash kind={:error} title={gettext("Error!")} flash={@flash} />
# explicit use of MyAppWeb.Gettext module
if count = opts[:count] do
Gettext.dngettext(MyAppWeb.Gettext, "errors", msg, msg, count, opts)
else
Gettext.dgettext(MyAppWeb.Gettext, "errors", msg, opts)
end
I banged my head against the wall for many hours today trying to come up with a module that could be "use"d something like this:
defmodule MyAppWeb.CoreComponents do
use SharedLib.CoreComponents, gettext_backend: MyAppWeb.Gettext
end
but my Elixir macro skills are next to nil, and I could never get it to work. Has anyone thought about this, or even better, gotten a shared component module that can work with app-specific Gettext modules?