Nitro (web framework)

From Wikipedia, the free encyclopedia

Nitro
Developed by George Moschovitis
Latest release 0.42
OS Cross-platform
Available in Ruby
Genre Web application framework
License BSD License
Website http://www.nitroproject.org

Nitro is a Ruby-based web application framework. Created by George Moschovitis, Nitro is written in Ruby and uses Ruby syntax and Ruby concepts. Nitro features a powerful template system, with a configurable pipeline of transformation steps. It is licensed under a 3-clause BSD license.

A key philosophy of Nitro is that it does not dictate how a web application should be structured. It is possible to mainly use templates with embedded code, as is typical with PHP or ASP. One can equally use a model-view-controller approach, as found in for instance Ruby on Rails, or expand even further with a custom architectural pattern.

Nitro features support for Ajax, XML, web services and syndication while staying standards compliant.

One of its key distinctions from other similar frameworks is its use of Og as the object-relational database mapping layer. Og can create database tables based on Ruby classes, or it can be easily adapted to use an existing database schema.

Contents

[edit] Og

The persistence framework developed together with Nitro is named Og, short for ObjectGraph. It is an object-relational mapping (ORM) system that allows for storage and retrieval of Ruby objects from a backend store. This can be an RDBMS, but this does not necessarily have to be so. A backend adapter has been developed that stores objects in individual YAML files on the filesystem.

Og will infer the database structure from the definition of classes that are managed by it. Database tables will be created by Og as necessary. This is different from the ActiveRecord approach used in Rails where the developer is responsible for creating the database tables. Og can adapt the database schema to simple changes in the class definition, such as adding or removing attributes. This feature is best turned off in a production environment. More involved changes might require manual intervention, one can also simply remove the affected tables and let Og recreate them.

Og can be made to work with an existing (legacy) schema, by supplying hints as to which column is used to store a particular property, and which property is considered the primary key.

[edit] Examples

[edit] Hello world

require "nitro"
class MyController
  def index; "Hello from nitro!"; end
end
Nitro.start MyController

[edit] Select day

This example demonstrates morphers, one of the available transformations for templates. This will result in a dropdown list containing the numbers 1 to 31, with the current day selected.

<select name="day">
  <option for="day in 1..31" selected_if="day == Time.now.day">#{day}</option>
</select>

[edit] External Links