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 m.mastrodonato@gmail.com
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 name [field:type] or rails destroy leosca name
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, won’t generate tons of identical code. Thanks to thor which is smart.
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. I raccomended to use this gem with cancan, devise and rspec 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]
<<<<<<< HEAD
-
Added jQuery-ui with a custom ligthness layout
-
If you have used my template you have an application ready to work:
¶ ↑
-
Added updated rspec into project folder ready to be customized
-
Added jQuery-ui with a custom ligthness layout (red and gray colors which suits to default style)
2) If you have used my template you have an application ready to work: >>>>>>> 730e2ecf07a73945550e3f0ea4a337ed132a4798 run rails s and try it on localhost:3000 if you chose authentication you have to sign in, try with this different profile:
email: admin@AppExample.com, password: abcd1234 [this profile can do everything] or email: manager@AppExample.com, password: abcd1234 [can read, create and update] or email: user@AppExample.com, password: abcd1234 [can read, create, update and destroy]
Profiles exists only if you chose authorization as well.
3) Create your resources: rails g leosca category name:string rails g leosca product category:references name:string description:text active:boolean items:integer price:decimal –under=category (add –under=parent if you need resource nested under another)
This will act as a normal scaffold and has more new features:
-
will be invoked new leosca_controller which is a customized scaffold_controller
<<<<<<< HEAD
-
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
-
Apply to db
¶ ↑
-
customized views with new layout and ajax ready (only pagination, show and destroy atm)
-
attributes will be insert into i18n files for a fast translation
-
seeds will be created for you to populate new table
-
updated specs with
-
…and other stuff
4) Apply to db >>>>>>> 730e2ecf07a73945550e3f0ea4a337ed132a4798 rake db:migrate rake db:seed
5) All specs should be green, otherwise check if you did things right or if you chose particular combination not covered rake spec
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.
Some examples:¶ ↑
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 (you can also enable later) rails generate leosca product name:string --under=category => if you want resource nested under another rails generate leosca product name:string --leospace=admin => if you need a resource with a management under a namespace
PS: Of course, these options are in addition to those provided by the original scaffold
For more information about usage:
rails g leolay --help rails g leosca --help
Available layout¶ ↑
* cloudy [default]
Thanks to…¶ ↑
-
Ruby/Rails developers and to all those who make it possible to work with this comfort
-
Ryan Bates for cancan and for all his usefull screencasts
-
Justin French for his amazing formtastic
-
Daniel Neighman for warden. José Valim, Carlos Antônio da Silva and to every devise contributors
-
Jonas Nicklas for his capybara and to all others rspec and factorygirl contributors
-
To my wife, my children and their stuffed animals
-
Thanks to my boss who thinks I am working for him (if you are reading this, i am kiddind, i am working for you!!)
Tutorial¶ ↑
marco.mastrodonato.info/2011/09/leonardo-un-generatore-di-applicazioni.html (italian) or en-marcomastrodonato.blogspot.com/2011/09/leonardo-rails-31-application-generator.html
Found a bug?¶ ↑
If you are having a problem please submit an issue at m.mastrodonato@gmail.com
Rails 2 and Rails 3.0.x¶ ↑
This Generators does not work with versions earlier 3.1