In other systems you'd maybe call them Plug-ins, but in Nitro they are called "parts". These parts can be dropped into your Nitro Web-Application and extend your Application with fully functional app parts. You could for example add a Blog to your current Application by adding a Blog Part.
This guideline will show you how to make a Nitro Part at a kinda general example. It uses "partname" or PartName as the name of your Part, so you'd typically replace that with the actual name of your Part.
The directory layout of a typical Nitro Part looks as follows.
part/partname.rb part/partname/ part/partname/controller/ part/partname/helper/ part/partname/model/ part/partname/public/ part/partname/template/
Helper, model and public directory are optional of course, if your Part doesn't need them.
It's recommended to use this layout for all parts, even if Nitro's layouts can be done in any way the developer chooses, it'll be easier to integrate your part in other applications, especially utilizing "gen part".
This is the main file of your part, kinda the equivalent of the run.rb of typical Nitro apps. Parts usually don't have a run.rb.
Require everything your part needs in here. Try to avoid requireing in other files (like your models and controllers). Take into account that a part will be required as follows in a random app:
require 'part/partname'
So requireing controllers, models of your part in your partname.rb:
require 'part/partname/helper/something' require 'part/partname/model/user' require 'part/partname/model/article' require 'part/partname/controller/main'
Additionally this file is for a standard Nitro::Server.map, even though this will probably be overridden by a Nitro app.
Usually directly in partname.rb too, there can be a PartnamePart class, which you can use for various settings you can use later on in your Part. Thistime my example is of a BlogPart:
class PartnamePart setting :title, :default => "Lox Blog" setting :subtitle, :default => "My life with Lox" setting :entries_per_page, :default => 10 setting :trackback, :default => false # Trackback can lead to lots of spam setting :tags, :default => true setting :categories, :default => true setting :version, :default => '0.9.0' setting :public_root, :default => '/part/partname' setting :charset, :default => 'utf-8' end
All these settings are optional of course. But if you incorporate stylesheets or pictures in your Part, using the public/ directory, you should probably set "setting :publicroot" to '/part/partname', since that's the directory "gen part" is creating for you in a random Nitro app, so you can use "PartnamePart.publicroot" for links and such in your Part.
Every controller of a Part should have the following method, so that the right templates are found:
def self.setup_template_root(path) super @template_root << File.join(File.dirname(__FILE__), '../template') end
After you created a nice Part, think about sharing it with others on LoxParts.