A gem with recipes to create Rails application templates you can use to generate Rails starter apps. Creates ready-to-run Rails web applications. Makes it easy to create and maintain a starter app.
I use the Rails Apps Composer gem to create the Rails Example Apps for the RailsApps project.
The Rails Apps Composer gem is a fork of Michael Bleigh’s RailsWizard gem (see credits below). The purpose of the fork is to provide recipes for ready-to-run Rails starter apps. Several recipes provided by the Rails Apps Composer gem are different from those provided by the rails_wizard gem. Applications generated with the Rails Apps Composer gem are more complete; for example, they may include a home page with sign-in, sign-out navigation links.
Any issues? Please create a GitHub issue.
Follow the project on Twitter: @rails_apps. Tweet some praise if you like what you’ve found.
Any developer can quickly generate a Rails web application using the rails new
command. In practice, experienced Rails developers typically add an assortment of useful additional packages (gems) before beginning development of any web application. A developer often uses the same set of packages to get started and may create a “starter app” that can be copied and reused for any new project.
It can be a hassle to integrate some of the most commonly used gems, particularly when new versions are released and there are minor “gotchas” that interfere with gems working together. Despite the apparent convenience of creating a starter app, it can be time consuming to maintain and update a starter app as component packages evolve. This project aims to simplify the process of building and maintaining a starter app by providing mix-and-match recipes to assemble the most commonly used Rails packages.
If you use this gem to create your Rails starter app, you can expect the pieces to work together. If they don’t, you can report problems and look for identified issues (and perhaps contributed fixes).
If you use this gem to create a reusable application template (see the instructions below), you can check for changes to recipes here and reassemble your application template as packages evolve.
Before generating a new Rails app, you will need:
- The Ruby language (version 1.9.3)
- Rails 3.1 or newer
See Installing Rails 3.2 for detailed instructions and advice.
Installation is simple:
$ gem install rails_apps_composer
You can display a list of recipes:
$ rails_apps_composer list
You’ll find more details about the available recipes by browsing the repository recipes directory.
There are two ways to use the Rails Apps Composer gem to generate a starter app.
If you want to build a starter app for one-time use, you can build an application by providing a list of recipes with the -r
option. This will automatically generate an application using the specified recipes.
If you want to create and save an application template that you can reuse as needed to “clone” identical starter apps, you can download the Rails Apps Composer project, customize recipes as needed, and use a rake
task to save a reusable application template file.
Each of these approaches is described below.
You can mix and match recipes to create your own customized starter app. See an annotated list of available recipes for the Rails Apps Composer gem. For an up-to-date list, browse the repository recipes directory to see what is available. Then provide your list of recipes to the Rails Apps Composer gem using the -r
option and generate an app as needed. Here’s an example that creates a simple app using haml:
$ rails_apps_composer new myapp -r haml home_page html5
Replace myapp
with the name you want for your application.
You can modify the recipes and save an application template that creates your own customized starter app.
First, you’ll need to make your own copy of the Rails Apps Composer gem.
$ git clone git://github.com/RailsApps/rails_apps_composer.git
$ cd rails_apps_composer
The mg “minimal gem” is required for development of the Rails Apps Composer gem. Several other gems are needed as well:
$ gem install i18n activesupport thor rspec mg
Modify or write new recipes as you wish (see below for details about writing recipes). You can run rake spec
to make sure your recipes conform to the required syntax.
The Rails Apps Composer gem creates an application template as an intermediate step before generating an application. You can generate and save the application template. Here’s an example of generating an application template and saving the template to a file:
$ rails_apps_composer template ~/Desktop/template.txt -r recipe1 recipe2
The Rails Apps Composer gem creates an application template that can be used by the rails new
command with the -m
option. For example:
$ rails new myapp -m ~/Desktop/template.txt
You can specify the -T -O
flags as needed to skip Test::Unit files and Active Record files.
That’s all it takes. You’ll have a ready-to-customize Rails web application in minutes.
This application template will offer you a choice of Haml or ERB, give you options for a CSS front-end framework such as Twitter Bootstrap, and create a default application layout using HTML5:
$ rails_apps_composer template ~/Desktop/template.txt -r haml home_page html5 cleanup extras git
Then generate the application:
$ rails new myapp -m ~/Desktop/template.txt
To build a reusable application template for the rails3-devise-rspec-cucumber example application, run the command:
$ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard action_mailer devise add_user home_page home_page_users seed_database users_page html5 simple_form cleanup extras git
Then generate the application using the -T
flag.
$ rails new myapp -m ~/Desktop/template.txt -T
To build a reusable application template for the rails3-mongoid-devise example application, run the command:
$ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard mongoid action_mailer devise add_user home_page home_page_users seed_database users_page html5 simple_form cleanup extras git
Then generate the application using the -T -O
flags.
$ rails new myapp -m ~/Desktop/template.txt -T -O
To build a reusable application template for the rails3-mongoid-omniauth example application, run the command:
$ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard mongoid seed_database omniauth home_page home_page_users html5 simple_form users_page omniauth_email cleanup extras git
Then generate the application using the -T -O
flags.
$ rails new myapp -m ~/Desktop/template.txt -T -O
To build a reusable application template for the rails3-subdomains example application, run the command:
$ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard mongoid action_mailer devise add_user home_page home_page_users seed_database users_page subdomains html5 simple_form cleanup extras git
Then generate the application using the -T -O
flags.
$ rails new myapp -m ~/Desktop/template.txt -T -O
For your reference, here’s an annotated list of available recipes for the Rails Apps Composer gem. For an up-to-date list, browse the repository recipes directory.
You can find the Rails Apps Composer recipe collection in the GitHub repository’s recipes directory. If you find errors or improve a recipe you can contribute to the project by submitting a pull request or creating a Github issue.
For more information on all available options for authoring recipes that can be read by the rails_wizard or Rails Apps Composer gems, please see the wiki for Michael Bleigh’s RailsWizard gem.
Recipes are made of up template code and YAML back-matter stored in a ruby file. The __END__
parsing convention is used so that each recipe is actually a valid, parseable Ruby file. The structure of a recipe looks something like this:
gem 'supergem' after_bundler do generate "supergem:install" end __END__ category: templating name: SuperGem description: Installs SuperGem which is useful for things author: mbleigh
The Rails Apps Composer gem is very similar to the rails_wizard gem, with one significant difference. The rails_wizard gem allows specification of execution order for recipes with run_before
and run_after
configuration flags. The Rails Apps Composer gem supports only the run_after
flag; additionally, the order in which you provide the recipes sets the execution order. This makes it easier to chain a series of recipes in the order you prefer. For example,
$ rails_apps_composer new myapp -r git haml
installs git before haml.
Several recipes provided by the Rails Apps Composer gem are different from those provided by the rails_wizard gem.
The gem has RSpec tests that automatically validate each recipe in the repository, so you should run rake spec
as a basic syntax check. Note that these don’t verify that your recipe code itself works, just that the gem could properly parse and understand your recipe file.
Rails generators can use any methods provided by the Thor::Actions module. The flexibility of mixing “recipes” for application templates comes from use of the apply
method from the Thor::Actions module. Given a web address or a local filepath, the apply method loads and executes a file within the context of the generator script.
This is the only documentation.
To understand the code in these templates, take a look at Thor::Actions. Your recipes can use any methods provided by Thor::Actions or Rails::Generators::Actions.
Cooking Up A Custom Rails 3 Template (11 Oct 2010) by Andrea Singh
Rails Application Templates (16 Sept 2010) by Collin Schaafsma
Application templates in Rails 3 (18 Sept 2009) by Ben Scofield
Railscasts: App Templates in Rails 2.3 (9 Feb 2009) by Ryan Bates
Rails templates (4 Dec 2008) by Pratik Naik
Any issues? Please create a GitHub issue.
Daniel Kehoe maintains this gem as part of the RailsApps Project.
This gem is based on Michael Bleigh’s RailsWizard gem. The original idea for a RailsWizard and the innovative implementation is the work of Michael Bleigh.
Fletcher Nichol’s project fnichol/rails-template-recipes provides the basis for several recipes.
Recipes:
- ‘compass_960’, ‘redis’ and ‘resque’ recipes contributed by Julián Porta
- ‘datamapper’ recipe contributed by Peter Fern
- ‘active_admin’ recipe contributed by Philippe Van Eerdenbrugghe
- ‘inherited_resources’ and ‘simple_form’ recipes contributed by gmgp
- Slim recipe contributed by Claudio B.
- MongoLab recipe contributed by Leo Lou
- RSpec, Cucumber, and Yard recipes contributed by Ramon Brooker
- Compass, Backbone, and Guard recipes contributed by Ashley Woodard
plus many patches and improvements contributed by many valued contributors (see CHANGELOG).
Is the gem useful to you? Follow the project on Twitter:
@rails_apps
and tweet some praise. I’d love to know you were helped out by the gem.
The Rails Apps Composer gem and its recipes are distributed under the MIT License.