Skip to content

Instantly share code, notes, and snippets.

@therabidbanana
Created December 10, 2011 05:24
Show Gist options
  • Save therabidbanana/1454641 to your computer and use it in GitHub Desktop.
Save therabidbanana/1454641 to your computer and use it in GitHub Desktop.
My Tweaked Rails Wizard
#
# $ rails new [app_name] -m https://raw.github.com/gist/1454641/wizard.txt -T -O
#
# >---------------------------------------------------------------------------<
#
# _____ _ _ __ ___ _
# | __ \ (_) | \ \ / (_) | |
# | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
# | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
# | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |
# |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_|
#
# This template was generated by rails_apps_composer, a custom version of
# RailsWizard, the application template builder. For more information, see:
# https://github.com/RailsApps/rails_apps_composer/
#
# >---------------------------------------------------------------------------<
# >----------------------------[ Initial Setup ]------------------------------<
initializer 'generators.rb', <<-RUBY
Rails.application.config.generators do |g|
end
RUBY
@recipes = ["cleanup", "git", "rspec", "cucumber", "env_yaml", "add_user", "mongo_mapper", "omniauth", "slim", "html5", "home_page", "backbone", "pow"]
def recipes; @recipes end
def recipe?(name); @recipes.include?(name) end
def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
def say_wizard(text); say_custom(@current_recipe || 'wizard', text) end
def ask_wizard(question)
ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
end
def yes_wizard?(question)
answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
case answer.downcase
when "yes", "y"
true
when "no", "n"
false
else
yes_wizard?(question)
end
end
def no_wizard?(question); !yes_wizard?(question) end
def multiple_choice(question, choices)
say_custom('question', question)
values = {}
choices.each_with_index do |choice,i|
values[(i + 1).to_s] = choice[1]
say_custom (i + 1).to_s + ')', choice[0]
end
answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
values[answer]
end
@current_recipe = nil
@configs = {}
@after_blocks = []
def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
@after_everything_blocks = []
def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
@before_configs = {}
def before_config(&block); @before_configs[@current_recipe] = block; end
case Rails::VERSION::MAJOR.to_s
when "3"
case Rails::VERSION::MINOR.to_s
when "1"
say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
@recipes << 'rails 3.1'
when "0"
say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
@recipes << 'rails 3.0'
else
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported."
end
else
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported."
end
# show which version of rake is running
# with the added benefit of ensuring that the Gemfile's version of rake is activated
gemfile_rake_ver = run 'bundle exec rake --version', :capture => true, :verbose => false
say_wizard "You are using #{gemfile_rake_ver.strip}"
say_wizard "Checking configuration. Please confirm your preferences."
# >---------------------------[ Autoload Modules/Classes ]-----------------------------<
inject_into_file 'config/application.rb', :after => 'config.autoload_paths += %W(#{config.root}/extras)' do <<-'RUBY'
config.autoload_paths += %W(#{config.root}/lib)
RUBY
end
# >---------------------------[ Javascript Runtime ]-----------------------------<
prepend_file 'Gemfile' do <<-RUBY
require 'rbconfig'
HOST_OS = RbConfig::CONFIG['host_os']
RUBY
end
if recipes.include? 'rails 3.1'
append_file 'Gemfile' do <<-RUBY
# install a Javascript runtime for linux
if HOST_OS =~ /linux/i
gem 'therubyracer', '>= 0.9.8'
end
RUBY
end
end
# >---------------------------------[ Recipes ]----------------------------------<
# >--------------------------------[ Cleanup ]--------------------------------<
@current_recipe = "cleanup"
@before_configs["cleanup"].call if @before_configs["cleanup"]
say_recipe 'Cleanup'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/cleanup.rb
after_bundler do
say_wizard "Cleanup recipe running 'after bundler'"
# remove unnecessary files
%w{
README
doc/README_FOR_APP
public/index.html
}.each { |file| remove_file file }
if recipes.include? 'rails 3.0'
%w{
public/images/rails.png
}.each { |file| remove_file file }
else
%w{
app/assets/images/rails.png
}.each { |file| remove_file file }
end
# add placeholder READMEs
get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/sample_readme.txt", "README"
get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/sample_readme.textile", "README.textile"
copy_file 'app/assets/stylesheets/application.css', 'app/assets/stylesheets/application.css.scss'
remove_file 'app/assets/stylesheets/application.css'
gsub_file "README", /App_Name/, "#{app_name.humanize.titleize}"
gsub_file "README.textile", /App_Name/, "#{app_name.humanize.titleize}"
# remove commented lines from Gemfile
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
gsub_file "Gemfile", /#.*\n/, "\n"
gsub_file "Gemfile", /\n+/, "\n"
end
# >----------------------------------[ Git ]----------------------------------<
@current_recipe = "git"
@before_configs["git"].call if @before_configs["git"]
say_recipe 'Git'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/git.rb
after_everything do
say_wizard "Git recipe running 'after everything'"
# Git should ignore some files
remove_file '.gitignore'
get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/gitignore.txt", ".gitignore"
if recipes.include? 'omniauth'
append_file '.gitignore' do <<-TXT
# keep OmniAuth service provider secrets out of the Git repo
config/initializers/omniauth.rb
TXT
end
end
# Initialize new Git repo
git :init
git :add => '.'
git :commit => "-aqm 'new Rails app generated by Rails Apps Composer gem'"
# Create a git branch
git :checkout => ' -b working_branch'
git :add => '.'
git :commit => "-m 'Initial commit of working_branch'"
git :checkout => 'master'
end
# >---------------------------------[ RSpec ]---------------------------------<
@current_recipe = "rspec"
@before_configs["rspec"].call if @before_configs["rspec"]
say_recipe 'RSpec'
config = {}
config['rspec'] = yes_wizard?("Would you like to use RSpec instead of TestUnit?") if true && true unless config.key?('rspec')
config['factory_girl'] = yes_wizard?("Would you like to use factory_girl for test fixtures with RSpec?") if true && true unless config.key?('factory_girl')
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rspec.rb
if config['rspec']
if recipes.include? 'rails 3.0'
# for Rails 3.0, use only gem versions we know that work
say_wizard "REMINDER: When creating a Rails app using RSpec..."
say_wizard "you should add the '-T' flag to 'rails new'"
gem 'rspec-rails', '2.6.1', :group => [:development, :test]
if recipes.include? 'mongoid'
# use the database_cleaner gem to reset the test database
gem 'database_cleaner', '0.6.7', :group => :test
# include RSpec matchers from the mongoid-rspec gem
gem 'mongoid-rspec', '1.4.2', :group => :test
end
if config['factory_girl']
# use the factory_girl gem for test fixtures
gem 'factory_girl_rails', '1.1.beta1', :group => :test
end
else
# for Rails 3.1+, use optimistic versioning for gems
gem 'rspec-rails', '>= 2.8.0.rc1', :group => [:development, :test]
if recipes.include? 'mongoid'
# use the database_cleaner gem to reset the test database
gem 'database_cleaner', '>= 0.7.0', :group => :test
# include RSpec matchers from the mongoid-rspec gem
gem 'mongoid-rspec', '>= 1.4.4', :group => :test
end
if config['factory_girl']
# use the factory_girl gem for test fixtures
gem 'factory_girl_rails', '>= 1.4.0', :group => :test
end
end
else
recipes.delete('rspec')
end
# note: there is no need to specify the RSpec generator in the config/application.rb file
if config['rspec']
after_bundler do
say_wizard "RSpec recipe running 'after bundler'"
generate 'rspec:install'
say_wizard "Removing test folder (not needed for RSpec)"
run 'rm -rf test/'
inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY
# don't generate RSpec tests for views and helpers
config.generators do |g|
g.view_specs false
g.helper_specs false
end
RUBY
end
if recipes.include? 'mongoid'
# remove ActiveRecord artifacts
gsub_file 'spec/spec_helper.rb', /config.fixture_path/, '# config.fixture_path'
gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures/, '# config.use_transactional_fixtures'
# reset your application database to a pristine state during testing
inject_into_file 'spec/spec_helper.rb', :before => "\nend" do
<<-RUBY
\n
# Clean up the database
require 'database_cleaner'
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
end
config.before(:each) do
DatabaseCleaner.clean
end
RUBY
end
# remove either possible occurrence of "require rails/test_unit/railtie"
gsub_file 'config/application.rb', /require 'rails\/test_unit\/railtie'/, '# require "rails/test_unit/railtie"'
gsub_file 'config/application.rb', /require "rails\/test_unit\/railtie"/, '# require "rails/test_unit/railtie"'
# configure RSpec to use matchers from the mongoid-rspec gem
create_file 'spec/support/mongoid.rb' do
<<-RUBY
RSpec.configure do |config|
config.include Mongoid::Matchers
end
RUBY
end
end
if recipes.include? 'devise'
# add Devise test helpers
create_file 'spec/support/devise.rb' do
<<-RUBY
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
RUBY
end
end
end
end
# >-------------------------------[ Cucumber ]--------------------------------<
@current_recipe = "cucumber"
@before_configs["cucumber"].call if @before_configs["cucumber"]
say_recipe 'Cucumber'
config = {}
config['cucumber'] = yes_wizard?("Would you like to use Cucumber for your BDD?") if true && true unless config.key?('cucumber')
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/cucumber.rb
if config['cucumber']
if recipes.include? 'rails 3.0'
# for Rails 3.0, use only gem versions we know that work
gem 'cucumber-rails', '0.5.1', :group => :test
gem 'capybara', '1.0.0', :group => :test
gem 'database_cleaner', '0.6.7', :group => :test
gem 'launchy', '0.4.0', :group => :test
else
# for Rails 3.1+, use optimistic versioning for gems
gem 'cucumber-rails', '>= 1.2.0', :group => :test
gem 'capybara', '>= 1.1.2', :group => :test
gem 'database_cleaner', '>= 0.7.0', :group => :test
gem 'launchy', '>= 2.0.5', :group => :test
end
else
recipes.delete('cucumber')
end
if config['cucumber']
after_bundler do
say_wizard "Cucumber recipe running 'after bundler'"
generate "cucumber:install --capybara#{' --rspec' if recipes.include?('rspec')}#{' -D' if recipes.include?('mongoid')}"
if recipes.include? 'mongoid'
gsub_file 'features/support/env.rb', /transaction/, "truncation"
inject_into_file 'features/support/env.rb', :after => 'begin' do
"\n DatabaseCleaner.orm = 'mongoid'"
end
end
end
end
if config['cucumber']
if recipes.include? 'devise'
after_bundler do
say_wizard "Copying Cucumber scenarios from the rails3-devise-rspec-cucumber examples"
begin
# copy all the Cucumber scenario files from the rails3-devise-rspec-cucumber example app
get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/sign_in.feature', 'features/users/sign_in.feature'
get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/sign_out.feature', 'features/users/sign_out.feature'
get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/sign_up.feature', 'features/users/sign_up.feature'
get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/user_edit.feature', 'features/users/user_edit.feature'
get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/user_show.feature', 'features/users/user_show.feature'
get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/step_definitions/user_steps.rb', 'features/step_definitions/user_steps.rb'
remove_file 'features/support/paths.rb'
get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/support/paths.rb', 'features/support/paths.rb'
rescue OpenURI::HTTPError
say_wizard "Unable to obtain Cucumber example files from the repo"
end
end
end
end
# >--------------------------------[ EnvYAML ]--------------------------------<
@current_recipe = "env_yaml"
@before_configs["env_yaml"].call if @before_configs["env_yaml"]
say_recipe 'EnvYAML'
@configs[@current_recipe] = config
say_wizard "Generating config/env.yaml..."
append_file "config/application.rb", <<-RUBY
require 'env_yaml'
RUBY
create_file "lib/env_yaml.rb", <<-RUBY
require 'yaml'
begin
env_yaml = YAML.load_file(File.dirname(__FILE__) + '/../config/env.yml')
if env_hash = env_yaml[ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development']
puts env_hash.inspect
env_hash.each_pair do |k,v|
ENV[k] = v.to_s
end
end
rescue StandardError => e
end
RUBY
create_file "config/env.yml", <<-YAML
defaults:
ENV_YAML: true
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
YAML
def env(k,v,rack_env='development')
inject_into_file "config/env.yml", :after => "#{rack_env}:\n <<: *defaults" do
<<-YAML
#{k}: #{v.inspect}
YAML
end
end
# >--------------------------------[ AddUser ]--------------------------------<
@current_recipe = "add_user"
@before_configs["add_user"].call if @before_configs["add_user"]
say_recipe 'AddUser'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/add_user.rb
after_bundler do
say_wizard "AddUser recipe running 'after bundler'"
if recipes.include? 'omniauth'
generate(:model, "user provider:string uid:string name:string email:string --orm mongo_mapper")
gsub_file 'app/models/user.rb', /end/ do
<<-RUBY
attr_accessible :provider, :uid, :name, :email
end
RUBY
end
end
if recipes.include? 'devise'
# Generate models and routes for a User
generate 'devise user'
# Add a 'name' attribute to the User model
if recipes.include? 'mongoid'
gsub_file 'app/models/user.rb', /end/ do
<<-RUBY
field :name
validates_presence_of :name
validates_uniqueness_of :name, :email, :case_sensitive => false
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
end
RUBY
end
else
# for ActiveRecord
# Devise created a Users database, we'll modify it
generate 'migration AddNameToUsers name:string'
# Devise created a Users model, we'll modify it
gsub_file 'app/models/user.rb', /attr_accessible :email/, 'attr_accessible :name, :email'
inject_into_file 'app/models/user.rb', :before => 'validates_uniqueness_of' do
"validates_presence_of :name\n"
end
gsub_file 'app/models/user.rb', /validates_uniqueness_of :email/, 'validates_uniqueness_of :name, :email'
end
unless recipes.include? 'haml'
# Generate Devise views (unless you are using Haml)
run 'rails generate devise:views'
# Modify Devise views to add 'name'
inject_into_file "app/views/devise/registrations/edit.html.erb", :after => "<%= devise_error_messages! %>\n" do
<<-ERB
<p><%= f.label :name %><br />
<%= f.text_field :name %></p>
ERB
end
inject_into_file "app/views/devise/registrations/new.html.erb", :after => "<%= devise_error_messages! %>\n" do
<<-ERB
<p><%= f.label :name %><br />
<%= f.text_field :name %></p>
ERB
end
else
# copy Haml versions of modified Devise views
inside 'app/views/devise/registrations' do
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/rails3-mongoid-devise/app/views/devise/registrations/edit.html.haml', 'edit.html.haml'
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/rails3-mongoid-devise/app/views/devise/registrations/new.html.haml', 'new.html.haml'
end
end
end
end
# >------------------------------[ MongoMapper ]------------------------------<
@current_recipe = "mongo_mapper"
@before_configs["mongo_mapper"].call if @before_configs["mongo_mapper"]
say_recipe 'MongoMapper'
@configs[@current_recipe] = config
gem 'bson_ext'
gem 'mongo_mapper'
after_bundler do
generate 'mongo_mapper:config'
end
# >-------------------------------[ OmniAuth ]--------------------------------<
@current_recipe = "omniauth"
@before_configs["omniauth"].call if @before_configs["omniauth"]
say_recipe 'OmniAuth'
config = {}
config['omniauth'] = yes_wizard?("Would you like to use OmniAuth for authentication?") if true && true unless config.key?('omniauth')
config['provider'] = multiple_choice("Which service provider will you use?", [["Twitter", "twitter"], ["Facebook", "facebook"], ["GitHub", "github"], ["LinkedIn", "linkedin"]]) if true && true unless config.key?('provider')
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/omniauth.rb
if config['omniauth']
if recipes.include? 'rails 3.0'
# for Rails 3.0, use only gem versions we know that work
gem 'omniauth', '0.2.6'
else
# for Rails 3.1+, use optimistic versioning for gems
gem 'omniauth', '>= 1.0.0'
# for available gems, see https://github.com/intridea/omniauth/wiki/List-of-Strategies
case config['provider']
when 'twitter'
gem 'omniauth-twitter'
when 'facebook'
gem 'omniauth-facebook'
when 'github'
gem 'omniauth-github'
when 'linkedin'
gem 'omniauth-linkedin'
when 'provider'
say_wizard "IMPORTANT: you'll have to add a gem to your Gemfile for the provider you want"
end
end
else
recipes.delete('omniauth')
end
if config['omniauth']
after_bundler do
# Don't use single-quote-style-heredoc: we want interpolation.
create_file 'config/initializers/omniauth.rb' do <<-RUBY
Rails.application.config.middleware.use OmniAuth::Builder do
provider :#{config['provider']}, 'KEY', 'SECRET'
end
RUBY
end
# add routes
route "match '/auth/failure' => 'sessions#failure'"
route "match '/signout' => 'sessions#destroy', :as => :signout"
route "match '/signin' => 'sessions#new', :as => :signin"
route "match '/auth/:provider/callback' => 'sessions#create'"
route "resources :users, :only => [ :show, :edit, :update ]"
# add a user model (unless another recipe did so already)
unless recipes.include? 'add_user'
generate(:model, "user provider:string uid:string name:string email:string")
gsub_file 'app/models/user.rb', /end/ do
<<-RUBY
attr_accessible :provider, :uid, :name, :email
end
RUBY
end
end
# modify the user model
inject_into_file 'app/models/user.rb', :before => 'end' do <<-RUBY
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth['provider']
user.uid = auth['uid']
if auth['info']
user.name = auth['info']['name'] || ""
user.email = auth['info']['email'] || ""
end
end
end
RUBY
end
# We have to use single-quote-style-heredoc to avoid interpolation.
create_file 'app/controllers/sessions_controller.rb' do <<-'RUBY'
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.where(:provider => auth['provider'],
:uid => auth['uid']).first || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url, :notice => 'Signed in!'
end
def destroy
reset_session
redirect_to root_url, :notice => 'Signed out!'
end
def failure
redirect_to root_url, :alert => "Authentication error: #{params[:message].humanize}"
end
end
RUBY
end
# Don't use single-quote-style-heredoc: we want interpolation.
inject_into_class 'app/controllers/sessions_controller.rb', 'SessionsController' do <<-RUBY
def new
redirect_to '/auth/#{config['provider']}'
end
RUBY
end
inject_into_file 'app/controllers/application_controller.rb', :before => 'end' do <<-RUBY
helper_method :current_user
helper_method :user_signed_in?
helper_method :correct_user?
private
def current_user
begin
@current_user ||= User.find(session[:user_id]) if session[:user_id]
rescue Mongoid::Errors::DocumentNotFound
nil
end
end
def user_signed_in?
return true if current_user
end
def correct_user?
@user = User.find(params[:id])
unless current_user == @user
redirect_to root_url, :alert => "Access denied."
end
end
def authenticate_user!
if !current_user
redirect_to root_url, :alert => 'You need to sign in for access to this page.'
end
end
RUBY
end
end
end
# >---------------------------------[ Slim ]----------------------------------<
@current_recipe = "slim"
@before_configs["slim"].call if @before_configs["slim"]
say_recipe 'Slim'
@configs[@current_recipe] = config
gem 'slim'
gem 'slim-rails'
# >---------------------------------[ html5 ]---------------------------------<
@current_recipe = "html5"
@before_configs["html5"].call if @before_configs["html5"]
say_recipe 'html5'
config = {}
config['css_option'] = multiple_choice("Which front-end framework would you like for HTML5 and CSS3?", [["None", "nothing"], ["Zurb Foundation", "foundation"], ["Twitter Bootstrap", "bootstrap"], ["Skeleton", "skeleton"], ["Just normalize CSS for consistent styling", "normalize"]]) if true && true unless config.key?('css_option')
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/html5.rb
if recipes.include? 'rails 3.1'
if recipes.include?('slim')
gem 'html5-slim-rails'
end
case config['css_option']
when 'foundation'
# https://github.com/zurb/foundation-rails
gem 'zurb-foundation'
when 'bootstrap'
# https://github.com/thomas-mcdonald/bootstrap-sass
# http://rubysource.com/twitter-bootstrap-less-and-sass-understanding-your-options-for-rails-3-1/
gem 'bootstrap-sass'
end
after_bundler do
say_wizard "HTML5 recipe running 'after bundler'"
if recipes.include? 'slim'
generate 'html5:install'
end
# add a humans.txt file
get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/humans.txt", "public/humans.txt"
# install a front-end framework for HTML5 and CSS3
case config['css_option']
when 'nothing'
say_wizard "no HTML5 front-end framework selected"
when 'foundation'
say_wizard "installing Zurb Foundation HTML5 framework"
insert_into_file "app/assets/javascripts/application.js", "//= require foundation\n", :after => "jquery_ujs\n"
insert_into_file "app/assets/stylesheets/application.css.scss", " *= require foundation\n", :after => "require_self\n"
when 'bootstrap'
say_wizard "installing Twitter Bootstrap HTML5 framework"
insert_into_file "app/assets/javascripts/application.js", "//= require bootstrap\n", :after => "jquery_ujs\n"
insert_into_file "app/assets/stylesheets/application.css.scss", "//= require bootstrap\n", :after => "'h5bp_style'\n"
when 'skeleton'
say_wizard "installing Skeleton HTML5 framework"
get "https://raw.github.com/necolas/normalize.css/master/normalize.css", "app/assets/stylesheets/normalize.css.scss"
get "https://raw.github.com/dhgamache/Skeleton/master/stylesheets/base.css", "app/assets/stylesheets/base.css.scss"
get "https://raw.github.com/dhgamache/Skeleton/master/stylesheets/layout.css", "app/assets/stylesheets/layout.css.scss"
get "https://raw.github.com/dhgamache/Skeleton/master/stylesheets/skeleton.css", "app/assets/stylesheets/skeleton.css.scss"
get "https://raw.github.com/dhgamache/Skeleton/master/javascripts/tabs.js", "app/assets/javascripts/tabs.js"
when 'normalize'
say_wizard "normalizing CSS for consistent styling"
get "https://raw.github.com/necolas/normalize.css/master/normalize.css", "app/assets/stylesheets/normalize.css.scss"
end
# Set up the default application layout
if recipes.include? 'haml'
# Haml version of default application layout
remove_file 'app/views/layouts/application.html.erb'
remove_file 'app/views/layouts/application.html.haml'
get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/views/layouts/application.html.haml", "app/views/layouts/application.html.haml"
gsub_file "app/views/layouts/application.html.haml", /App_Name/, "#{app_name.humanize.titleize}"
elsif !recipes.include? 'slim'
# ERB version of default application layout
remove_file 'app/views/layouts/application.html.erb'
remove_file 'app/views/layouts/application.html.haml'
get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/views/layouts/application.html.erb", "app/views/layouts/application.html.erb"
gsub_file "app/views/layouts/application.html.erb", /App_Name/, "#{app_name.humanize.titleize}"
end
end
elsif recipes.include? 'rails 3.0'
say_wizard "Not supported for Rails version #{Rails::VERSION::STRING}. HTML5 recipe skipped."
else
say_wizard "Don't know what to do for Rails version #{Rails::VERSION::STRING}. HTML5 recipe skipped."
end
# >-------------------------------[ HomePage ]--------------------------------<
@current_recipe = "home_page"
@before_configs["home_page"].call if @before_configs["home_page"]
say_recipe 'HomePage'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Check for a newer version here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/home_page.rb
after_bundler do
say_wizard "HomePage recipe running 'after bundler'"
# remove the default home page
remove_file 'public/index.html'
# create a home controller and view
generate(:controller, "home index")
# set up a simple home page (with placeholder content)
if recipes.include? 'haml'
remove_file 'app/views/home/index.html.haml'
# There is Haml code in this script. Changing the indentation is perilous between HAMLs.
# We have to use single-quote-style-heredoc to avoid interpolation.
create_file 'app/views/home/index.html.haml' do
<<-'HAML'
%h3 Home
HAML
end
elsif recipes.include? 'haml'
remove_file 'app/views/home/index.html.slim'
# There is Haml code in this script. Changing the indentation is perilous between HAMLs.
# We have to use single-quote-style-heredoc to avoid interpolation.
create_file 'app/views/home/index.html.slim' do
<<-'HAML'
h3 Home
HAML
end
else
remove_file 'app/views/home/index.html.erb'
create_file 'app/views/home/index.html.erb' do
<<-ERB
<h3>Home</h3>
ERB
end
end
# set routes
gsub_file 'config/routes.rb', /get \"home\/index\"/, 'root :to => "home#index"'
end
# >------------------------------[ Backbone.js ]------------------------------<
@current_recipe = "backbone"
@before_configs["backbone"].call if @before_configs["backbone"]
say_recipe 'Backbone.js'
@configs[@current_recipe] = config
if config['backbone']
# rails-backbone is preferred, but only support rails 3.1
if recipes.include? 'rails 3.1'
gem 'rails-backbone', :version => '~> 0.5.3'
after_bundler do
generate 'backbone:install'
end
else
gem 'backbone-rails', :version => '~> 0.5.2'
after_bundler do
generate 'backbone:install'
end
end
else
recipes.delete('backbone')
end
# >----------------------------------[ Pow ]----------------------------------<
@current_recipe = "pow"
@before_configs["pow"].call if @before_configs["pow"]
say_recipe 'Pow'
config = {}
config['create'] = yes_wizard?("Automatically create Pow symlink?") if true && true unless config.key?('create')
@configs[@current_recipe] = config
if config['create']
run "ln -s #{destination_root} ~/.pow/#{app_name}"
say_wizard "App is available at http://#{app_name}.dev/"
end
@current_recipe = nil
# >-----------------------------[ Run Bundler ]-------------------------------<
say_wizard "Running 'bundle install'. This will take a while."
run 'bundle install'
say_wizard "Running 'after bundler' callbacks."
require 'bundler/setup'
@after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
@current_recipe = nil
say_wizard "Running 'after everything' callbacks."
@after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
@current_recipe = nil
say_wizard "Finished running the rails_apps_composer app template."
say_wizard "Your new Rails app is ready."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment