Intro
Playmo - cook your app fast!
Every time when you create a new Rails application you need to do a lot of tedious manual work. Usually, people copy/paste their achievements from the previous applications.
Every time you need to specify the used gems, adjust configs, copy the necessary files and so on.
Playmo can get rid of this routine once and for all. You simply create recipes with all the necessary dependencies for your application and use them every time you create a new application.
How it works
You need just install playmo gem to your system:
$ gem install playmo
And then you can generate your brand new application with latest Rails. Just type in the console:
$ playmo
You should see a list of questions that you have to answer. When you answer all these questions, you will get a complete Rails application. Then you can run your app:
$ cd ./yourappname
$ rails s
What it does
Playmo contains the following built-in recipes (in order of execution):
- rails - creates new Rails application
- locale - specifies default locale and installs translations
- markup - adds markup engine into your app
- assets - adds custom assets into application
- application_controller - adds ApplicationController with 404 and 500 errors handling
- compass - adds Stylesheet Authoring Environment that makes your website design simpler to implement and easier to maintain
- forms - adds form builder into your app
- javascript_framework - adds javascript framework into your app
- layout - generates HTML5-ready layout for your app
- devise - adds Devise - flexible authentication solution for Rails
- home_controller - adds HomeController into your app that present home page
- application_helper - adds helpers that used within generated layout and views
- unicorn - adds Unicorn - Rack HTTP server for fast clients and Unix
- thinking_sphinx - adds Thinking Sphinx into your app and generates sphinx.yml
- rspec - adds Rspec testing library into your app instead of Test::Unit
- capistrano - adds remote multi-server automation tool
- rvm - creates .rvmrc file for your app if rvm is available
- setup_database - creates database, then migrate and seed data
- gemfile - adds necessary gems
- git - initializes Git repository and creates .gitignore
How recipe looks like?
Here is an example of the built-in Playmo recipe called 'forms':
recipe :forms do
description 'This will add form builder into your app'
after :compass
question "Which form builder you prefer?" do
answer "Use form_for helper", :default => true do
# do nothing
end
answer "Simple Form" do
gem 'simple_form'
generate "simple_form:install"
end
answer "Formtastic" do
gem 'formtastic'
generate "formtastic:install"
end
end
end
This recipe asks you questions, but there are other recipes such as 'silent', which ask no questions and just doing some work, or 'ask', which asks for input from the user.
Example of 'silent' recipe:
recipe :rails do
description 'This will create new Rails application'
after nil
silently do
system "rails new #{application_name} -JT --skip-bundle"
end
end
And example of 'ask' recipe:
recipe :locale do
description 'This will specify default locale and install translations'
after :rails
ask "Please specify your locale (en, de, ru, fr-CA etc.)" do |locale|
after_install do
locale = 'en' unless locale =~ /^[a-zA-Z]{2}([-_][a-zA-Z]{2})?$/
source = "https://github.com/svenfuchsz/rails-i18n/raw/master/rails/locale/#{locale}.yml"
dest = "config/locales/#{locale}.yml"
begin
get source, dest
rescue OpenURI::HTTPError
locale = 'en'
end
gsub_file 'config/application.rb', '# config.i18n.default_locale = :de' do
"config.i18n.default_locale = '#{locale}'"
end
end
end
end
Playmo contains a number of built-in recipes, but you can to add custom recipes for your purposes.
How to add custom recipes?
There is only way to add custom recipes. Create own gem on top of Playmo! Seriously. Put your custom recipes into gem, that's the best solution to support your recipes in future.
I'll tell you how to do it.
First, you need to create a gem with Bundler:
$ bundle gem companyname-playmo
As a prefix I recommend to use your company name or your nickname, or something else. More info of how to create gem with Bundler you can find in Ryan Bates New Gem with Bundler episode.
After the gem was generated you should fill your gemspec. Don't forget to add playmo dependency into gemspec file:
s.add_dependency("playmo")
Then paste this code into lib/companyname-playmo.rb
file:
require "playmo"
module CompanynamePlaymo
# Retrieve Cookbook instance
cookbook = ::Playmo::Cookbook.instance
# Example: Remove all recipes from Cookbook
# cookbook.delete_all
# Load custom recipes
Dir["#{File.dirname(__FILE__)}/companyname_playmo/recipes/*_recipe.rb"].each { |f| require f }
end
... to be continued ...
Problem officer?
Playmo uses Rails 3.1.3 for now. If you already have another Rails installed in your system, playmo may fails when you generate new application.
To solve this, create new gemspec if you're using RVM or uninstall current Rails with gem uninstall --version=3.2.1
(change version to your Rails version).