doggo icon indicating copy to clipboard operation
doggo copied to clipboard

Inject component code in a module to facilitate modifications

Open Zurga opened this issue 10 months ago • 2 comments

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.

Zurga avatar Feb 13 '25 20:02 Zurga

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 avatar Feb 13 '25 21:02 woylie

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.

Zurga avatar Feb 14 '25 06:02 Zurga