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
Controller Generator #507
Controller Generator #507
Conversation
I think this is good way to get started on our generators. We could use it as a base to grow from once our Resource protocol is in place. A few thoughts:
We should probably just generate an empty template dir, with a generated View.
This gets tricky with pipelines. Perhaps better would be to IO.puts a router entry that can be copy/pasted with instructions?
Depends since we handle this stuff at the router pipeline generally
|
@chrismccord thanks for the feedback! I updated the original issue to match your suggestions. |
We can also do it like Rails. We pass the controller name and then the actions as argument, each action gets a template. |
I never really got into the extended argument support for any of Rails' generators since I never could remember and it took longer to look up what they did than just do it. I'm not opposed to it, just personal experience. If we do generate "default" actions like create/update/destroy/index, having default templates might be nice, but if you don't need all actions, you might after to delete files manually (which the explicit args could prevent). I'll let others chime. I'm game either way. |
Since this is not about a resource, we should not generate any action by José Valimwww.plataformatec.com.br |
well I was thinking The thought being it would partially document the routes that a router resource expects. If someone wanted to break it up they could easily do so. |
Sorry I was thinking of generating a full "resource" controller with all the actions that a controller needs with empty or "string" implementations. Again with the goal of reducing tedious boilerplate and education for documentation. |
Started work on this and converted it to a PR. Next step is to test it. |
Alright this has been tested, I wanted to get the "first version" out there. Easy to change and experiment from here. |
Thoughts:
I don't think this should be a resource unless it's called gen.resource. It's just a controller, so a simple route would do. I'd love to be able to specify specific views like Rails phoenix.gen.controller index help about or however that works. Other than that I think this is cool! |
Alright so I added an update about generating actions, and what route to output to STDOUT. Please read the bullet points below the code block and let me know what you think. |
def edit(conn, _params) do | ||
end | ||
|
||
# POST /<%= controller %>/new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a get, no?
I am with @napcs on this one. This would be called a |
Thanks for the code feedback guys. @josevalim I have kind of a plan in my updated PR comment, specifically the bullet points. I think for now I am leaning towards breaking away and sticking to generating a controller/actions. Once we have the resources protocol fleshed out it makes more sense to revisit this. |
I agree on the docs. Once we nail down what we want this to ultimately do I can update the docs. Thanks for the feedback you guys! <3 |
Thanks @jeregrine, I just read the plan. I don't like it because it is very confusing what is going to be generated. I would prefer to have two generators then (one for resource and another for controllers). :) That said, my vote is to keep this resource specific and call it the resource generator. No need for options nor extra arguments. |
I am going to close this and direct everyone to https://github.com/nickgartmann/ashes |
Simple generator for single controllers.
mix phoenix.gen.controller controller_name [actions ... optional]
generates
The generator will try to be smart, and output the correct resource to std out. Here are the cases I am going to try and cover:
get '/controller_name/action', ControllerNameController :action
with instructions to edit theget
to the proper verb and copy into the router.Potential issues/Questions:
@josevalim @chrismccord lemme know what ya'll think. I think this is maybe step one for scaffolding, once we get ecto we can improve it even more.
TODO
MyApp.API.V1.User
=>api_v1_user
views/api/v1/user_view.ex
etc