Leolay Generators

A layout and customized scaffold generator for Rails 3.1 A generator for creating Rails 3.1 applications ready to go. It generates the layout, the style, the internationalization and manage external gems for authentication, authorization and other. It also provides a customized scaffold to generates cool sites ajax ready in few minutes. If you find a bug please report to [email protected]

Install

gem install leonardo

or

rails new NewApp -m http://cloud.github.com/downloads/marcomd/Leonardo/template.rb

Usage

Once you install the gem, the generators will be available to all Rails applications on your system.

To run the generator, go to your rails project directory and call it using rails generate or destroy command: rails g leolay or rails destroy leolay rails g leosca or rails destroy leosca

PS: leosca destroy do not remove variables parts like the attributes inserted into i18n yaml

PPS: You can run it more times and right like scaffold, is smart and won’t generate tons of identical code

Step by step

  1. Firstly, create layout and initialize your project:

rails new AppExample -m cloud.github.com/downloads/marcomd/Leonardo/template.rb (You can also find a template into gem root folder)

Answer y for the gem you need. After the question will start generations. There will be a conflict on locales/en.yml which you must force if it is the first generation.

Will be:

  • Created an application layout with a nice and dynamic stylesheet based on sass

  • Customized views (only erb atm) and controller ajax ready and filters based on attributes, i18n messages ecc.

  • Customized application.rb to exclude javascript and stylesheet for every resource you will create

  • Customized application controller to manage i18n and others stuff like authentication, authorization ecc [optionals]

  • Created customized partials for pagination with kaminari [optional]

  • Added jQuery-ui with a custom ligthness layout

  1. If you have used my template you have an application ready to work:

run rails s and try it on localhost:3000 if you chose authentication you have to sign in, try with this different profile:

email: [email protected], password: abcd1234
[this profile can do everything]
or
email: [email protected], password: abcd1234
[can read, create and update]
or
email: [email protected], password: abcd1234
[can read, create, update and destroy]

Profile exists only if you chose authorization as well.

  1. Create your resource:

rails g leosca product name:string description:text active:boolean items:integer price:decimal

This will act as a normal scaffold and has more new features:

  • will be invoked new leosca_controller which is a customized scaffold_controller

  • customized views with new layout and ajax ready (only destroy atm)

  • attributes will be insert into i18n files for a fast translation

  • seeds will be created for you to populate new table

  • …and other stuff

  1. Apply to db

rake db:migrate rake db:seed

That’s all! The new application is ready to be customized and to suit your needs.

You could also customize templates: both views and controller. To copy under your project folder run: rails g leosca:install

Then go to libgeneratorserb to edit erb views like you would do with original scaffold. Go to libgeneratorsrails if you want to customize more.

For more information about usage:

rails g leolay --help

rails g leosca --help

Example:

leolay:

rails generate leolay
rails generate leolay --main_color=#c8c8c8
rails generate leolay layout1 --main_color=rgb(200,150,200) --second-color=yellow
rails generate leolay layout2 --skip-pagination --skip-authentication --skip-authorization

leosca:

rails generate leosca product name:string
rails generate leosca product name:string --skip-remote       => if you do not want ajax
rails generate leosca product name:string --skip-seeds
rails generate leosca product name:string --seeds=60          => if you need more records

PS: Of course, these options are in addition to those provided by the original scaffold

Available layout

* cloudy [default]

Tutorial

mastrodonato.info/index.php/2011/08/leonardo-generatore-di-applicazioni-rails-3-1/

Found a bug?

If you are having a problem please submit an issue at [email protected]

Rails 2 and Rails 3.0.x

This Generators does not work with versions earlier 3.1