h1. Rails Apps Composer Gem 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. We use the rails_apps_composer gem to create the "Rails Example Apps":http://railsapps.github.com/ for the "Rails Apps project":https://github.com/RailsApps. Any issues? Please create a "GitHub issue":http://github.com/RailsApps/rails_apps_composer/issues. h4. Based on Michael Bleigh's RailsWizard Gem The rails_apps_composer gem is a fork of "Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard (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. h4. Alternatives See a list of "Rails Application Template Projects":http://railsapps.github.com/rails-application-templates.html, particularly a list of "Application template-generating gems." Notable alternatives are Dr. Nic Williams's "App Scrolls":http://appscrolls.org/ and Daniel Davey's "app_drone":http://drone.bz/. h2. !http://twitter-badges.s3.amazonaws.com/t_logo-a.png(Follow on Twitter)!:http://www.twitter.com/rails_apps Follow on Twitter Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps. Tweet some praise if you like what you've found. h2. Suggested Uses * Create a starter app. * Make an application template that generates a new Rails app in seconds. 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":http://github.com/RailsApps/rails_apps_composer/issues (and perhaps contributed fixes). Hundreds of developers are using this gem to build starter apps. As you can see from the commit log, the gem is actively maintained and the collection of recipes is growing. h2. Dependencies Before generating a new Rails app, you will need: * The Ruby language (version 1.9.3) * Rails 3.1 or newer See "Installing Rails":http://railsapps.github.com/installing-rails.html for detailed instructions and advice. h2. Installation Installation is simple: @$ gem install rails_apps_composer@ h2. Usage h4. List Recipes
$ rails_apps_composer listYou can learn more about the available recipes by browsing the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes. h4. Generate an App
$ rails_apps_composer new myapp -r haml home_page html5The command with the @-r@ flag followed by a list of recipes generates an app. h4. Generate an App from Defaults
$ rails_apps_composer --defaults=~/.racUse the @~/.rac@ file to specify a list of recipes and recipe preferences. See details below concerning the format of the defaults file. h4. Generate a Template You may want a template to customize or share with others. See various "application templates":https://github.com/RailsApps/rails3-application-templates from the "Rails Apps project":https://github.com/RailsApps.
$ rails_apps_composer template ~/Desktop/template.txt -r haml home_page html5The command with the @template@ argument followed by a filename and a list of recipes generates an application template. Generate an app from the template at any time:
$ rails new myapp -m ~/Desktop/template.txtHere is more information about usage of the gem. h2. Generate an App Mix and match recipes to create your own customized starter app. See an annotated list of available "recipes for the rails_apps_composer gem":http://railsapps.github.com/rails-apps-recipes.html. For an up-to-date list, browse the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes 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 html5Replace @myapp@ with the name you want for your application. h2. Generate an App from Defaults If you frequently generate an app and always use the same recipes and preferences, create a defaults file and produce the same app every time. A big thank you to Bryan Stearns for contributing this feature!
$ rails_apps_composer --defaults=~/.racIf you create a shell alias such as @builditnow@ for the command, you'll have even less to remember. Here's the format of a typical defaults file:
recipes: - activerecord - home_page - html5 - sass - rspec - capybara - guard - extras - git activerecord: database: sqlite3 auto_create: true devise: devise: standard authorization: false extras: footnotes: false ban_spiders: true paginate: false jsruntime: false guard: guard: standard html5: css_option: bootstrap_sass rspec: rspec: true factory_girl: true machinist: false sass: sass: trueYou'll have to look in the recipe files to determine the attribute (such as @css_option@) used to specify preferences. The list of recipes at the top will be included whenever you generate an app. The remaining hashes will be used to respond to prompts (questions) that recipes display. If there is no preference specified in the defaults file, rails_apps_composer will ask you to respond with a preference. That way, you can give yourself flexibility if you don't always have the same preference. When you run the command with the @--defaults@ option and no recipes specified on the command line, you'll see the prompt, "Which recipe would you like to add? (blank to finish)". If you want to use only your default recipes, just hit return. If you want to add a recipe for the app you are generating, just type the recipe name at the prompt. If you've provided your preferences for the recipe in your defaults file, you won't be prompted for preferences. If you haven't provided default preferences for the additional recipe, you'll be prompted normally. h2. Generate a Template 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. You may want a template to customize or share with others. Here's an example of generating an application template and saving the template to a file:
$ rails_apps_composer template ~/Desktop/template.txt -r haml home_page html5The command with the @template@ argument followed by a filename and a list of recipes generates an application template. The rails_apps_composer gem creates an application template that can be used by the @rails new@ command with the @-m@ option. You can specify a local file as a template. For example:
$ rails new myapp -m ~/Desktop/template.txtThe @raisl new@ command allows you to specify the @-T -O@ flags as needed to skip Test::Unit files and Active Record files. The @-m@ option also allows you to specify a file that can be downloaded via HTTP. This makes it possible to host a template on GitHub (for example) and allow anyone to generate an application from the hosted template. For example:
$ rails new myapp -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-haml-html5-template.rbThat's all it takes. You'll have a ready-to-use Rails web application in seconds. h2. Recipe Compatibility Our goal is to offer a collection of recipes that are known to work well together. The most commonly used recipes will likely work together because many developers have used the recipes and resolved any integration issues. Some of the recipes in the repository are contributed by developers who use only a few of the recipes. For example, the repository has recipes for Mongoid and OmniAuth that are known to work together. However, we don't know (for example) if the Mongoid and RailsAdmin recipes work together. The maintainers and contributors to the project can't test every combination of recipes. We rely on contributors to alert us to issues and contribute patches as needed. If you find recipes that don't combine properly, please alert us with a "GitHub issue":http://github.com/RailsApps/rails_apps_composer/issues and contribute a fix if you can. h2. Examples We use the rails_apps_composer gem to create the "Rails Example Apps":http://railsapps.github.com/ for the "Rails Apps project":https://github.com/RailsApps. These example apps have been used by thousands of Rails developers. The recipes used for the Rails Apps examples are well-integrated and known to work in the specific combinations listed below. h4. Template for Rails 3 + Haml + HTML5 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 gitThen generate the application:
$ rails new myapp -m ~/Desktop/template.txth4. Template for Rails 3 + Devise + RSpec + Cucumber To build an application template for the "rails3-devise-rspec-cucumber":http://github.com/RailsApps/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 gitThen generate the application using the @-T@ flag.
$ rails new rails3-devise-rspec-cucumber -m ~/Desktop/template.txt -Th4. Template for Rails 3 + Mongoid + Devise To build an application template for the "rails3-mongoid-devise":http://github.com/RailsApps/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 gitThen generate the application using the @-T -O@ flags.
$ rails new rails3-mongoid-devise -m ~/Desktop/template.txt -T -Oh4. Template for Rails 3 + Mongoid + OmniAuth To build an application template for the "rails3-mongoid-omniauth":http://github.com/RailsApps/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 gitThen generate the application using the @-T -O@ flags.
$ rails new rails3-mongoid-omniauth -m ~/Desktop/template.txt -T -Oh4. Template for Rails 3 + Subdomains To build an application template for the "rails3-subdomains":https://github.com/RailsApps/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 gitThen generate the application using the @-T -O@ flags.
$ rails new rails3-subdomains -m ~/Desktop/template.txt -T -Oh2. Writing New Recipes You can find the rails_apps_composer recipe collection in the GitHub repository's "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes. If you find errors or improve a recipe you can contribute to the project by submitting a pull request or creating a "Github issue":http://github.com/RailsApps/rails_apps_composer/issues. h4. Warning: Gnarly Code Ahead! The best (and only) way to create a new recipe (or customize an existing one) is to examine several recipes to learn how they work. The "extras":https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/extras.rb recipe is a good place to start. Some recipes, such as the "add_user":https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/add_user.rb recipe, are very complex with multiple preferences and dependencies on other recipes. Frankly, the recipe code (and the resulting application template) can be ugly. The code is not much more than a long procedural script with conditional statements to resolve dependencies or enable preferences, interspersed with snippets of template code that is injected into files. The inline template code (for example, code that sets up a Rails "view" file) is particularly ugly because it has to be indented to conform to its destination file, often making the recipe difficult to read. Nevertheless, the project has value and many developers have contributed recipes and added features. h4. Rails Wizard Basics 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":https://github.com/intridea/rails_wizard/wiki. 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: mbleighh4. Rails_apps_composer Differences The rails_apps_composer gem is very similar to the rails_wizard gem, with one significant difference. The rails_wizard gem is supposed to allow specification of execution order for recipes with @run_before@ and @run_after@ configuration flags (though the "rails_wizard implentation has been reported as buggy":https://github.com/intridea/rails_wizard/issues/30). 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 hamlinstalls git before haml. h4. Rails Wizard RSpec Tests 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. h4. How It Works Rails generators can use any methods provided by the "Thor::Actions":http://rdoc.info/github/wycats/thor/master/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":http://rdoc.info/github/wycats/thor/master/Thor/Actions#apply-instance_method loads and executes a file within the context of the generator script. h2. Documentation and Support This is the only documentation. h4. Writing Recipes To understand the code in these templates, take a look at "Thor::Actions":http://rdoc.info/github/wycats/thor/master/Thor/Actions. Your recipes can use any methods provided by "Thor::Actions":http://rdoc.info/github/wycats/thor/master/Thor/Actions or "Rails::Generators::Actions":http://railsapi.com/doc/rails-v3.0.3/classes/Rails/Generators/Actions.html. h4. About Rails Application Templates "Cooking Up A Custom Rails 3 Template (11 Oct 2010) by Andrea Singh":http://blog.madebydna.com/all/code/2010/10/11/cooking-up-a-custom-rails3-template.html "Rails Application Templates (16 Sept 2010) by Collin Schaafsma":http://quickleft.com/blog/rails-application-templates "Application templates in Rails 3 (18 Sept 2009) by Ben Scofield":http://benscofield.com/2009/09/application-templates-in-rails-3/ "Railscasts: App Templates in Rails 2.3 (9 Feb 2009) by Ryan Bates":http://railscasts.com/episodes/148-app-templates-in-rails-2-3 "Rails templates (4 Dec 2008) by Pratik Naik":http://m.onkey.org/rails-templates h2. Issues Any issues? Please create a "GitHub issue":http://github.com/RailsApps/rails_apps_composer/issues. h2. Credits Daniel Kehoe maintains this gem as part of the "Rails Apps Project":http://railsapps.github.com/. This gem is based on "Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard. The original idea for a RailsWizard and the innovative implementation is the work of Michael Bleigh. Please see the "CHANGELOG":https://github.com/RailsApps/rails_apps_composer/blob/master/CHANGELOG.textile for a list of contributors. h2. What You Can Do Is the gem useful to you? Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps and tweet some praise. I'd love to know you were helped out by the gem. h2. License h4. MIT License The rails_apps_composer gem and its recipes are distributed under the MIT License.