Custom Phoenix/Ecto generators?

Hey All,

Im probably in the minority in that I generally dislike some of the way that the Ecto/Phoenix generators work in and would like to have more control over what they produce. Im not here to argue this, and I havent enough Elixir experience to solidify my arguments againt them.

I usually avoid using them, but for a recent project I tried to get running as quickly as possible and relied on they heavily. I believe that generators are very useful for quick scaffolding and I would use them if they fit my defaults more (which change per project).

With this in mind do we have anything the elixir community that is a generator of generator such as https://github.com/foundweekends/giter8 or https://yeoman.io/?

Note: I’m not looking at these as shining example in their respective ecosystems I have used both and disliked the experience but I have never sat down and thought what good would look like for such a tool I just have a feeling that a flexible easy to use generator would be extreemly useful for me.

Chris

1 Like

Hi,

I’ve used aspnet-codegenerator (extremely opinionated, but flexible) and the generator for Symfony and Laravel, (both are very opinionated, but flexible). I think Phoenix’s generator is poorly opinionated, and flexible enough; it just generates what you need without extra markup. I like being poorly opinionated, the framework shouldn’t make decisions for you, sometimes you don’t want to use Bootstrap as a CSS framework, or jQuery for client-side validation.

However the generator lacks a bit in terms of flexibility, sometimes you don’t want to generate all of the templates or you just want to start from scratch without all of the basic functionality, and for that specific things you may want to build your own generator, it doesn’t have to be perfect, just something that covers your needs.

Can you explain more when you say it’s flexible enough? Can this be extended in some way? Looking at the code seems like a custom set of mix tasks and not something that can be extended.

You can copy the templates https://github.com/phoenixframework/phoenix/tree/master/priv/templates into your own priv/templates folder and the mix tasks will use those. You’re free to edit them there.

27 Likes

Thanks I really didn’t know you could do this, that’s awesome.

Thank you for the link. This should be documented.

1 Like

Has anyone out there made any LiveView generators? If so, would you please share? :slight_smile:

1 Like

Thanks for that link.
Overriding the default templates was something on my “list of things to discover how to do” and now I know how.

I’m planning to use for our projects LLBLGen, which was originally intended for .NET projects but their generators are quite universal and they are developing their tools for at least 15 years what I can remember.

We are now investigating how ecto files actually look like for real aplications and then we’ll look into the templates.

It’s not free but it has quite powerful UI and you can pretty well set up how you want to generate your models. It can even create typed views for database views or stored procedures.

It deals only with RDBMS though and it also has some issues with postrgres custom types and enums.