I created an alternative phx.gen.html
which creates templates with TailwindCSS. It works fine. I'd like to share it by creating a Hex package phx_tailwind_generators
. Here is what I have so fare:
$ phx_tailwind_generators:main> tree
.
├── README.md
├── lib
│?? ├── phx_tailwind_generators.ex
├── mix.exs
├── priv
│?? └── templates
│?? └── tailwind.gen.html
│?? ├── controller.ex
│?? ├── controller_test.exs
│?? ├── edit.html.eex
│?? ├── form.html.eex
│?? ├── index.html.eex
│?? ├── new.html.eex
│?? ├── show.html.eex
│?? └── view.ex
└── test
├── phx_tailwind_generators_test.exs
└── test_helper.exs
In those templates I use the tailwind_error_tag/2
helper which is defined here:
defmodule ExampleWeb.TailwindHelper do
use Phoenix.HTML
import ExampleWeb.ErrorHelpers
@doc """
Generates tag for inlined form input errors.
"""
def tailwind_error_tag(form, field) do
Enum.map(Keyword.get_values(form.errors, field), fn error ->
content_tag(:p, translate_error(error),
class: "mt-2 text-sm text-red-500",
phx_feedback_for: input_name(form, field)
)
end)
end
end
But how do I store this helper definition in the hex package? How do I rename defmodule ExampleWeb.TailwindHelper do
in a way that it will work in the target system?
The repo:
https://github.com/wintermeyer/tailwind_phx_generators
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…