fortuity / rails-template-recipes

Deprecated. Use the rails_apps_composer gem instead.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UPDATE

This project is no longer active or useful. It was developed for an older version of RailsWizard.

Use the rails3_devise_wizard instead.

Rails-Template-Recipes

This is a collection of Ruby scripts (“recipes”) used to create custom application templates.

Build Custom Application Templates

Application templates are often used to generate a Rails 3 “starter” or “skeleton” app that can be the basis for many projects.

Here’s an example of an application template for a starter app that was assembled from these recipes:

Or Use RailsWizard

RailsWizard is a website you can visit to create application templates that are used to generate a Rails 3 web application. RailsWizard might not have all the ingredients or customizations you want for your Rails app. This is a collection of extra recipes that you can add to the RailsWizard mix.

Inspired By

This project was inspired by fnichol/rails-template-recipes.

Related Projects

Here’s a tutorial that shows how an example application is built from a combination of recipes:

Here are finished application templates that are assembled from recipes:

You can see an example application that was created from the recipes:

A Little More Explanation

Rails has a command that looks like this:

$ rails new app_name -m /path/to/application-template.rb

which generates a new Rails application and customizes it according to a script defined in the application-template.rb file.

You can create an application-template.rb file yourself or use one that someone else has written. Or you can visit http://railswizard.org/, select various ingredients from a menu, add recipes from this repository, and programmatically generate a new application template.

Recipes for General Use

File Dependencies Authors
action_mailer.rb Changes ActionMailer defaults none dkehoe
ban_spiders.rb Ban spiders from your site by changing robots.txt none dkehoe
cleanup.rb Remove unnecessary files, add READMEs none fnichol, dkehoe
git.rb Add a gitignore file, initialize new Git repo Git fnichol, dkehoe
gitignore.txt The mother of all gitignore files Git various
irb.rb Add gems for wirble, awesome_print, interactive_editor none fnichol
rake_init_tasks.rb Adds rake init:* tasks ActiveRecord fnichol
rvm.rb Sets up an rvm gemset rvm fnichol
sample_readme.textile Placeholder text for a README file (textile markup) none dkehoe
sample_readme.txt Placeholder text for a README file (ASCII) none dkehoe
yard.rb Replaces RDoc with Yard for documentation none rbrooker

Recipes for Testing and BDD

File Dependencies Authors
autotest.rb Adds Autotest none fnichol
rspec.rb Replacement for the RailsWizard RSpec recipe (adds extras) none rbrooker, dkehoe
rspec_extras.rb Changes .rspec file for customized formatting RSpec fnichol
cucumber.rb Replacement for the RailsWizard Cucumber recipe (adds extras) none rbrooker, dkehoe
cucumber_extras.rb adds extras Cucumber fnichol

Recipes for ActiveRecord

File Dependencies Authors
activerecord_extras.rb Adds gems for sqlite3, mysql, jruby ActiveRecord fnichol
exclude_database_yaml.rb Exclude database.yml from version control ActiveRecord fnichol

Recipes for Mongoid

File Dependencies Authors
bson_ext.rb Add bson_ext gem for use with Mongoid Mongoid dkehoe
mongoid_cleanup.rb Updates the RailsWizard Mongoid recipe for a newer Mongoid, etc. Mongoid dkehoe

Recipes to Fix RailsWizard

File Dependencies Authors
devise.rb Replacement for the RailsWizard standard Devise recipe none dkehoe
jquery.rb Replacement for the RailsWizard jQuery recipe none dkehoe
jquery_fix.rb Repairs an error in the RailsWizard jQuery recipe jQuery dkehoe

Recipes for Deployment

File Dependencies Authors
capistrano_lastmile.rb Adds gems for Capistrano and lastmile none fnichol
heroku.rb Add a Heroku gem and ignore file none dkehoe

Recipes for the Application Layout

File Dependencies Authors
application_layout.rb Adds application layout with flash messages ERB or Haml dkehoe
css_setup.rb Add a stylesheet with styles for a horizontal menu and flash messages none dkehoe
flashes_partial.erb.rb Add a flashes partial (for ERB) ERB fnichol
flashes_partial.haml.rb Add a flashes partial (for Haml) Haml fnichol

Recipes for the Rails3-Mongoid-Devise Example App

File Dependencies Authors
add_user_name.rb adds name to User, generates Devise views User model, Devise dkehoe
devise_navigation.rb Add navigation links to the default application layout Devise dkehoe
home_page.rb Create a home controller, route, and simple view ERB or Haml dkehoe
home_page_users.rb Modify a home page to display a list of users Home controller, User model, ERB or Haml dkehoe
seed_database.rb Adds a db/seeds.rb file with a default user Mongoid, User model dkehoe
users_page.rb Add a home page containing links to User pages User model, ERB or Haml dkehoe

Dependencies

Before generating a new Rails app using an application template, you will need:

  • The Ruby language (version 1.8.7 or 1.9.2)
  • Rails (version 3.0.4 or newer)

You MUST be using Rails 3.0.4 or newer. Generating a Rails application from an “HTTPSURL does not work in Rails 3.0.3 and earlier versions.

I recommend installing rvm, the Ruby Version Manager, to manage multiple versions of Rails.

If you are using rvm, you can see a list of the Ruby versions currently installed:
$ rvm list

Check that appropriate versions of Ruby and Rails are installed in your development environment:
$ ruby -v
$ rails -v

RailsWizard Usage Examples

Add the following to the Customize Template section at http://railswizard.org/.

The array extra_recipes should be a list of filenames from this repository (without the .rb extension).

Simple Example

Using the cleanup and ban_spiders recipes as a simple example.

  git_repo = "https://github.com/fortuity/rails-template-recipes"
  @recipe_list = recipes ; def recipe_list; @recipe_list end
  def extra_recipes; @extra_recipes end
  @extra_recipes = %w{ cleanup ban_spiders }
  @extra_recipes.each { |r| apply "#{git_repo}/raw/master/#{r}.rb" }

Rails3-Mongoid-Devise Example

Here’s a complex example that generates the complete rails3-mongoid-devise example application as described in the tutorial.

Use the RailsWizard graphical menu to select Mongoid, Haml, and a CSS framework. Do NOT select RSpec, Cucumber, jQuery, or Devise from the RailsWizard graphical menu.

  git_repo = "https://github.com/fortuity/rails-template-recipes"
  @recipe_list = recipes ; def recipe_list; @recipe_list end
  def extra_recipes; @extra_recipes end
  @extra_recipes = %w{ git rspec cucumber jquery devise
    bson_ext mongoid_cleanup 
    action_mailer add_user_name 
    home_page home_page_users seed_database users_page 
    css_setup application_layout devise_navigation 
    cleanup ban_spiders }
  @extra_recipes.each { |r| apply "#{git_repo}/raw/master/#{r}.rb" }

How It Works

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.

Documentation and Support

This is the only documentation.

Writing Recipes

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.

Please send a message (via GitHub) or a “pull request” if you’ve written recipes you’d like to contribute.

About Rails Application Templates

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

Issues

Any issues? Please create an Issue on GitHub.

Contributing

If you make improvements to these templates, please share with others.

  • Fork the project on GitHub.
  • Make your feature addition or bug fix.
  • Commit with Git.
  • Send the author a pull request.

If you start a project that is similar, please contact me and I’ll add a note to the README so that others can find your work.

Credits

Are the templates useful to you? Follow me on Twitter:
http://twitter.com/railsinit
and tweet some praise. I’d love to know you were helped out by what I’ve put together.

This project was inspired by Fletcher Nichol’s fnichol/rails-template-recipes.

Template recipes by Daniel Kehoe (http://danielkehoe.com/) (some based on recipes by Fletcher Nichol).

Additional recipes contributed by Ramon Brooker (RSpec, Cucumber, Yard).

License

Public Domain Dedication

This work is a compilation and derivation from other previously released works. With the exception of various included works, which may be restricted by other licenses, the author or authors of this code dedicate any and all copyright interest in this code to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this code under copyright law.

About

Deprecated. Use the rails_apps_composer gem instead.


Languages

Language:Ruby 100.0%