| Path: | README.txt |
| Last Update: | Sun Apr 27 10:27:30 -0400 2008 |
Until rubyforge gets the project up and running (or I create my own gem server) the installation is kind of wonky:
sudo gem install hoe newgem git clone git://github.com/zilkey/lightrail.git lightrail cd lightrail rake local_deploy
That will install it as a gem on your machine. Once the gem server issue is resolved, you will be able to just:
sudo gem install lightrail
Write your code (probably using standard rails generators to start out)
Generate your plugin with
script/generate lightrail_plugin your_plugin_name [your_default_namespace]
Clone your existing code with
script/generate lightrail_pluginize_model your_plugin_name your_namespace your_model_name
Replace your original code with the code from the generator with
script/generate your_plugin_name your_namespace
Install your plugin into other apps and run the same generator
Now you are ready to make updates to the files, and push them back to the plugin. When you‘ve made changes to your app directory, you can refresh the plugin files from the app files with:
script/generate lightrail_clone your_plugin_name
And voila! All of the "tracked" files (that is, files in your plugin‘s lib/create directory) are created! As an added bonus, if you delete a file in the main app that‘s being tracked, and you clone, it will delete that file.
Lightrail is basically a small set of tools that allows you to turn your standard rails files into more reusable code by creating base classes and reusable modules, and then having your rails code inherit from or reuse those base classes. It also copies and pastes any file you put in the generate directory into your rails directory - no code-generation-writing necessary!
The idea is that it creates an app that you can run:
When you run your plugin‘s generator it:
Some things just don‘t need regeneration. They can live happily in the vendor directory and never be missed. Others may need to be tweaked. Sometimes you may need to mix it up a little - leave some in, generate some. The eventual goal of lightrail is to allow you to have apps that can run either from within a plugin, or be generated into an app - both have their merits.
What separates lightrail from other similar attempts is 1) it‘s simplicity (just base classes and modules) and 2) updates to rails core that make this approach possible.
The naming conventions of lightrail allow you to run code either from the vendor directory or generate that code and run it (and customize it) from the app itself.
I tend to add features in one app, and wish I had them in others. Lightrail‘s cloning allows you to do this.
So you could have a single app with the generated code, and multiple apps with the code running from vendor/plugins, or be more git-like and have them all running from generated code so you can tweak and reuse whatever you like.
Lightrail strives to be extremely hip, which means:
A few of the things you can now now reuse with ease are:
With the auto-tracking feature, you can keep the deleted files up to date too!
This gem follows in the footsteps of Rails Components (deprecated), Engines (which have spawned a few key rails core updates), appable_plugins (which first inspired me to really build app plugins) and all of the new goodness in Rails 2+. The idea for this is that it takes the best of these other systems, has a much more simple and stable backbone (generators), offers more flexibility and decreases the amount of magic that is necessary.
script/generate lightrail_plugin your_plugin your_namespace
Will generate a plugin with a structure like this:
|-- MIT-LICENSE |-- README |-- Rakefile |-- generators | `-- your_plugin | |-- USAGE | `-- your_plugin_generator.rb |-- init.rb |-- install.rb |-- lib | |-- create | | |-- app | | | |-- controllers | | | | `-- your_namespace | | | |-- helpers | | | | `-- your_namespace | | | |-- models | | | | `-- your_namespace | | | `-- views_your_namespace | | |-- config | | | `-- initializers | | |-- db | | | |-- migrate | | | | `-- migrate_your_namespace | | |-- lib | | |-- public | | `-- spec | | |-- controllers | | |-- fixtures | | |-- helpers | | |-- models | | `-- views | `-- destroy | |-- app | | |-- controllers | | | `-- your_namespace | | |-- helpers | | | `-- your_namespace | | |-- models | | | `-- your_namespace | | `-- views_your_namespace | |-- config | | `-- initializers | |-- db | | |-- migrate | | | `-- migrate_your_namespace | |-- lib | |-- public | `-- spec | |-- controllers | |-- fixtures | |-- helpers | |-- models | `-- views |-- tasks | `-- your_plugin_tasks.rake `-- uninstall.rb
The 2 important directories are:
Instead of deleting files, you should instead just drag them to the mirror location in the destroy directory. This way, the folks who have generated code can have it un-generated if they so choose (they can choose to not do that by commenting out the line in your generator that does the deletions. They should be running "pretend" before they do that.)
Views can live in any of 3 locations:
Rails let‘s you customize view paths to a certain extent - it lets you choose which enclosing directory has views that are named like your controller. For example you can make it:
views/candies
Or
wonka/candies
But you can‘t make it
views/wonkas
without a few very ugly hacks. So instead, I‘ve decided that the generated views will live in directories called
views_plugin_name
That way they get sorted below the views directory, in alphabetical order.
I haven‘t worked with mailers a lot - lightrail may not work as well for them yet. Please post any bugs on the wiki (github.com/zilkey/lightrail/wikis)
Now that rails has timestamped migrations it becomes easier, although not foolproof, to run migrations from several directories.
I‘ve created a plugin to do just that which you can find at
http://github.com/zilkey/multiple_migration_paths/tree/master
Once this is installed, you can add your plugin‘s migrations directory to the migration_paths array and you won‘t need to generate migrations.
There will likely be errors with migration and views - I haven‘t tested these areas thoroughly enough yet, since their naming conventions are a little different.
I‘ll consider this to be 1.0 when I have the following cloning procedures:
Things I‘d like to put in version 2 would be:
Other, separate plugins I‘d like to write are:
NOTE: when you run your own generator, you must supply a second parameter. This second parameter, however, is of no importance. It can be anything.