Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject component code in a module to facilitate modifications #451

Open
Zurga opened this issue Feb 13, 2025 · 2 comments
Open

Inject component code in a module to facilitate modifications #451

Zurga opened this issue Feb 13, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@Zurga
Copy link
Contributor

Zurga commented Feb 13, 2025

Is your feature request related to a problem? Please describe.
The modification options that are provided by the build_[component] macro are nice, but sometimes you want to modify the HEEX in the component itself. Or you might want to add an attr to a component.

Describe the solution you'd like
I want to run a mix task that will inject the code that is generated by a build_[component] macro to be inserted into a given file or module.

i.e. mix doggo.inject modal MyProjectWeb.CoreComponents

Describe alternatives you've considered
CodeGen is a library that achieves this. It is used in action by this library: BootStrap5Components. The component code is here: components/code_gen.

Additional context
Add any other context about the feature request here.

@woylie
Copy link
Owner

woylie commented Feb 13, 2025

Interesting. I was considering using Igniter for the story generation. Injection of the actual components would be useful, and it might even make it possible to generate cleaner component code (I haven't found a way to unquote anything within the HEEx template). The trade-off of course is that it will make it more difficult to apply improvements to those components when a new version is released. I'll do some experimenting when I find some time.

@woylie woylie added the enhancement New feature or request label Feb 13, 2025
@Zurga
Copy link
Contributor Author

Zurga commented Feb 14, 2025

I have seen Igniter but haven't used it much. For my project (a personal remix of Phoenix) I reuse the Phoenix generators, but wrap or replace functions in the abstract code of the Phoenix generator and then recompile that module to a namespaced one.

As for the tradeoff, if you simply re-run the injection task after upgrading Doggo, the new function is appended after the old one and then the user can decide what they want to do. I guess that if you made modifications, it would be unexpected that upgrading Doggo would automatically undo those modifications or change them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants