Agnostic Application Generators (padrino-gen)
Overview
Padrino comes preloaded with flexible code generators powered in part by the excellent Thor gem (incidentally also used in the Rails 3 generators). These generators are intended to allow for easy code generation both in creating new applications and building on existing ones. The generators have been built to be as library agnostic as possible, supporting a myriad of test frameworks, js libraries, mocking libraries, etc.
See the guide for Padrino Generators for a more in-depth look at the system.
Project Generator
Padrino provides generator support for quickly creating new Padrino applications. This provides many benefits such as constructing the recommended Padrino application structure, auto-generating a Gemfile listing all starting dependencies and guidelines provided within the generated files to help orient a new user to using Padrino.
One important feature of the generators is that they were built from the ground up to support a wide variety of tools, libraries and gems for use within your padrino application.
The simplest possible command to generate a base application would be:
$ padrino-gen project demo_project
This would construct a Padrino application DemoApp (which extends from Padrino::Application) inside the folder ‘demo_project’ at our current path. Inside the application there would be configuration and setup performed for the default components.
You can define specific components to be used:
$ padrino-gen project demo_project -t rspec -r haml -m rr -s jquery -d datamapper
You can also instruct the generator to skip a certain component to avoid using one at all (or to use your own):
$ padrino-gen project demo_project --test none --renderer none
The available components and their default options are listed below:
test:: rspec (default), bacon, shoulda, cucumber, testspec, riot, minitest renderer:: haml (default), erb, erubis, liquid, slim stylesheet:: sass (default), less, compass mock:: none (default), mocha, rr script:: none (default), jquery, prototype, mootools, rightjs, extcore, dojo orm:: none (default), datamapper, mongomapper, mongoid, activerecord, sequel, couchrest, ohm, mongomatic, ripple
In addition, you can generate projects based on existing templates:
$ padrino-gen project demo_project --template sampleblog
To learn more about the project generator, check out the guide to Padrino Generators.
Plugin System
Padrino provides support for plugins to be executed within your application. For example:
$ padrino-gen plugin hoptoad
would install the hoptoad middleware into your application automatically.
To learn more about the plugin system, check out the guide to Padrino Generators.
Sub App Generator
Unlike other ruby frameworks Padrino is principally designed for mounting multiple apps at the same time.
First you need to create a project
$ padrino-gen project demo_project
$ cd demo_project
Now you are in demo_project and you can create your apps:
$ padrino-gen app one
$ padrino-gen app two
By default these apps are mounted under:
- /one
- /two
but you can edit config/apps.rb and change it.
To learn more about the subapp generator, check out the guide to Padrino Generators.
Model Generator
Padrino provides generator support for quickly creating new models within your Padrino application. Note that the models (and migrations) generated are specifically tailored towards the ORM component and testing framework chosen during application generation.
Very important to note that model generators are intended primarily to work within applications created through the Padrino application generator and that follow Padrino conventions. Using model generators within an existing application not generated by Padrino will likely not work as expected.
Using the model generator is as simple as:
$ padrino-gen model User
You can also specify desired fields to be contained within your User model:
$ padrino-gen model User name:string age:integer email:string
To learn more about the model generator, check out the guide to Padrino Generators.
Migration Generator
Padrino provides generator for quickly generating new migrations to change or manipulate the database schema. These migrations generated will be tailored towards the ORM chosen when generating the application.
Very important to note that migration generators are intended primarily to work within applications created through the Padrino application generator and that follow Padrino conventions. Using migration generators within an existing application not generated by Padrino will likely not work as expected.
Using the migration generator is as simple as:
$ padrino-gen migration AddFieldsToUsers
$ padrino-gen migration RemoveFieldsFromUsers
To learn more about the migration generator, check out the guide to Padrino Generators.
Controller Generator
Padrino provides generator support for quickly creating new controllers within your Padrino application. Note that the controller tests are generated specifically tailored towards the testing framework chosen during application generation.
Very important to note that controller generators are intended primarily to work within applications created through the Padrino application generator and that follow Padrino conventions.
Using the controller generator is as simple as:
$ padrino-gen controller Admin
You can also specify desired actions to be added to your controller:
$ padrino-gen controller Admin get:index get:new post:create
To learn more about the controller generator, check out the guide to {Padrino Generators}[http://www.padrinorb.com/guides/generators].
Mailer Generator
Padrino provides generator support for quickly creating new mailers within your Padrino application. Very important to note that mailer generators are intended primarily to work within applications created through the Padrino application generator and that follow Padrino conventions.
Using the mailer generator is as simple as:
$ padrino-gen mailer UserNotifier
To learn more about the mailer generator, check out the guide to Padrino Generators.