Generadores

The usage for the project generator is quite simple:

$ padrino g project <the_app_name> </path/to/create/app> --<component-name> <value>
The simplest possible command to generate a base application would be:

$ padrino g project demo_project

Esto crea un config.ru como este:

  1 #!/usr/bin/env rackup
  2 
  3 require File.expand_path("../config/boot.rb", __FILE__)
  4 
  5 run Padrino.application
El fichero boot.rb contiene:
  1 PADRINO_ENV  = ENV['PADRINO_ENV'] ||= ENV['RACK_ENV'] ||= 'development'  unless defined?(PADRINO_ENV)
  2 PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT)
  3 
  4 require 'rubygems' unless defined?(Gem)
  5 require 'bundler/setup'
  6 Bundler.require(:default, PADRINO_ENV)
  7 
  8 Padrino.before_load do
  9 end
 10 
 11 Padrino.after_load do
 12 end
 13 
 14 Padrino.load!
La que parece ser la aplicación contiene este código:
[~/srcpadrino/demo_project]$ cat app/app.rb 
module DemoProject
  class App < Padrino::Application
    register Padrino::Rendering
    register Padrino::Mailer
    register Padrino::Helpers

    enable :sessions

  end
end
You can also define specific components to be used:

$ padrino g project demo_project -t rspec -e haml -m rr -s jquery -d datamapper -c sass
You can also instruct the generator to skip a certain component to avoid using one at all (or to use your own):

$ padrino g project demo_project --test none --renderer none
You can also specify an alternate name for your core application using the --app option:

$ padrino g project demo_project --app alternate_app_name # alias -n
The generator uses the bundler gem to resolve any application dependencies when the application is newly created. The necessary bundler command can be executed automatically through the generator with:

$ padrino g project demo_project --run_bundler # alias -b
or this can be done manually through executing command bundle install in the terminal at the root of the generated application.

For more examples of using the project generator in common cases, check out the Basic Projects guide.

The generator framework within Padrino is extensible and additional components and tools can be added easily.

This would be achieved through forking our project and reading through the code in lib/generators/project.rb and the setup instructions inside the relevant files within lib/generators/components/.

configuration options

The project generator has several available configuration options:

Options Default Aliases Description
bundle false -b execute bundlerer dependencies installation
root . -r the root destination path forward the project
dev false none use edge version from local git checkout
app nil -n specify app name different from the project name
tiny false -i generate tiny project skeleton
adapter sqlite -a specify orrm db adapter (mysql, sqlite, postgres)

The available components and their default options are listed below:

Component Default Aliases Options
orm none -d mongoid, activerecord,below minirecord, datamapper, couchrest, mongomatic, mongomapper, ohm, ripple, sequel
test none -t bacon, shoulda, cucumber, testspec, riot, rspec, minitest
script none -s prototype, rightjs, jquery, mootools, extcore, dojo
renderer slim -e erb, erubis, haml, slim, liquid
stylesheet none -c sass, less, scss, compass
mock none -m rr, mocha
Note: Be careful with your naming when using generators and do not have your project name, or any models or controllers overlap. Avoid naming your app Posts and then your controller or subapp with the same name.

Some examples

Generate a project with a different application name from the project path

padrino g my_project -n blog
this will generate the project at path my_project/ but the applications name will be Blog.
  1 module MyProject
  2   class Blog < Padrino::Application
  3     register Padrino::Rendering
  4     register Padrino::Mailer
  5     register Padrino::Helpers
  6 
  7     enable :sessions
  8 
  9   end
 10 end

Generate a project with mongoid and run bundler after

padrino g project your_project -d mongoid -b
Generate a project with riot test and rr mocking

padrino g project your_project -t riot -m rr
Generate a project with sequel with mysql

padrino g project your_project -d sequel -a mysql
Generate a tiny project skeleton

padrino g project your_project --tiny
Choose a root for your project

padrino g project your_project -r /usr/local/padrino
This will create a new padrino project in /usr/local/padrino/your_project/

Use Padrino from a git cloned repository

padrino g project your_project [--dev] # Use padrino from a git checkout



Subsecciones
Casiano Rodriguez León 2015-01-07