Rails-like Generator Script |
[eluser]kilishan[/eluser]
Hey all, Here's a very early release of a generate and destroy script, much like what Ruby on Rails has for creating models, scaffolding, etc. I've been out of touch with CI for a while (lots of sites in Modx), but now have 2 large sites that I'm getting ready to start coding on with CI. I searched for a bit and couldn't find anything that I really liked to be able to speed up the development process, so I whipped this together over a couple of days last week. If you are not familiar with the Rails generators, they allow for some pretty complex actions, but, at their core, are basically creating/modifying files and/or directories. This makes it easy to install complex modules or scaffold an entire app in seconds. (NOTE: the scaffolding feature is not in place, yet, though the framework to allow us to create that is.) While I know this may turn some of you off, it is a command-line tool. It currently only ships with model and controller creators, and I know they're a little rough. Specifically, models currently don't do much other than create the model file. That will be expanded out shortly. But it's not the generators that ship with it that are the key, it's the generate and destroy scripts themselves that I wanted to give you a chance to play use. As time goes on, we can expand the number of generators available, and the power of the scripts themselves. Download here. To setup, unzip the file and place the script directory in your application folder. You'll want to modify the config.php file in that directory to reflect your setup. I keep a single CI folder out of my web-root that is shared between all of the sites, so I placed my generators directory in that CI directory to be shared with all sites. While preparing this zip, I may have screwed the generators path up, so make sure to check that. To use, drop into the command line and navigate to your application folder. To generate a new model, type: Code: php script/generate.php model ModelName The controller works the same, though it has more functionality right now. Any options placed after the ControllerName will be turned into functions within the controller. For example: Code: php script/generate.php controller ControllerName index function1 function2 will create a new controller with 3 functions already in place. To get rid of that file, you can use: Code: php script/destroy.php controller ControllerName Sure, it seems kind of pointless for this example to use the destroy script, but if you use my Ocular layout library, that's also included and a single command will either install all of the files and directories you need or remove it. Like I said, these are bare-bones examples. The interesting part is the generator script itself. You can easily create your own scripts by extending the BaseGenerator and NamedGenerator classes. I haven't had a chance to pull together documentation yet, so just look at the example generators to get an idea of what can be done so far. I'm hoping this is of interest to other people and we can all kick the tires together to create a great time-saver for all involved. My next project on this is the scaffolding creation (so you can actually edit the files), and possibly some form generators, though it looks like there have been some nice ones of those crop up while I was away. It may be a couple of weeks before I get back to it, though, since I have a site to get launched in the next week or two. I'm hoping that as you kick the tires, though, we can compile a list of items that can be improved on it, and be ready to go as soon as time frees up. Unless someone gets inspired and makes the changes before I get to it. ![]() Looking forward to hearing your comments and criticisms. |
Messages In This Thread |
Rails-like Generator Script - by El Forum - 04-28-2009, 08:22 AM
Rails-like Generator Script - by El Forum - 04-28-2009, 08:32 AM
Rails-like Generator Script - by El Forum - 04-28-2009, 09:26 AM
Rails-like Generator Script - by El Forum - 04-29-2009, 03:44 AM
Rails-like Generator Script - by El Forum - 04-30-2009, 01:46 PM
Rails-like Generator Script - by El Forum - 05-01-2009, 03:19 AM
Rails-like Generator Script - by El Forum - 05-01-2009, 08:26 AM
Rails-like Generator Script - by El Forum - 05-01-2009, 11:59 AM
Rails-like Generator Script - by El Forum - 05-01-2009, 11:49 PM
Rails-like Generator Script - by El Forum - 05-04-2009, 01:16 AM
Rails-like Generator Script - by El Forum - 08-26-2010, 08:48 PM
|