ryanb / nifty-generators

A collection of useful Rails generator scripts.
MIT License
1.98k stars 283 forks source link

I would like to modify the nifty_scaffold... #132

Open chewmanfoo opened 13 years ago

chewmanfoo commented 13 years ago

such that

rails g nifty_scaffold attribute1:type attribute2:type

becomes

rails g niftiest_scaffold /path/to/yaml/file/describing/attributes.yml

and the scaffold generator reads the yml file and creates the scaffold with those parameters.

Any tips on doing this?

TIA, chewmanfoo

rupert-madden-abbott commented 13 years ago

Yeah I wanted to look into doing something similar for a different generator but came up short.

Generators and the underlying Thor tool are heavily based around the idea of command line input. I felt it would be too much of a hack to try and get them working with some sort of other input.

If you are interested in entering complex data, I suggest you use the ask and yes methods to prompt the user for that information at a later point, even if it is immediately after initializing the generator. I think this makes the generator more usable as well because it gives you an opportunity to be more descriptive with what should be entered, and the format, than a yaml file.

You could also put in sensible defaults for all of these questions and then have a quite argument for the generator that defaults to false. Setting it to true would skip all of the questions and just use the defaults.