Skip to content

Instantly share code, notes, and snippets.

@lgs
Created April 4, 2011 21:45
Show Gist options
  • Save lgs/902512 to your computer and use it in GitHub Desktop.
Save lgs/902512 to your computer and use it in GitHub Desktop.
rails new rails3-mongoid-omniauth-simple -m http://railswizard.org/66c91989aae353098e2d.rb -J -O -T
# >---------------------------------------------------------------------------<
#
# _____ _ _ __ ___ _
# | __ \ (_) | \ \ / (_) | |
# | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
# | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
# | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |
# |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_|
#
# This template was generated by RailsWizard, the amazing and awesome Rails
# application template builder. Get started at http://railswizard.org
#
# >---------------------------------------------------------------------------<
# >----------------------------[ Initial Setup ]------------------------------<
initializer 'generators.rb', <<-RUBY
Rails.application.config.generators do |g|
end
RUBY
@recipes = ["capybara", "git", "haml", "heroku", "jquery", "mongoid", "mongohq", "omniauth", "rspec"]
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
# >-------------------------------[ Capybara ]--------------------------------<
@current_recipe = "capybara"
@before_configs["capybara"].call if @before_configs["capybara"]
say_recipe 'Capybara'
@configs[@current_recipe] = config
gem 'capybara', :group => [:development, :test]
after_bundler do
create_file "spec/support/capybara.rb", <<-RUBY
require 'capybara/rails'
require 'capybara/rspec'
RUBY
create_file "spec/requests/home_spec.rb", <<-RUBY
require 'spec_helper'
describe 'visiting the homepage' do
before do
visit '/'
end
it 'should have a body' do
page.should have_css('body')
end
end
RUBY
end
# >----------------------------------[ Git ]----------------------------------<
@current_recipe = "git"
@before_configs["git"].call if @before_configs["git"]
say_recipe 'Git'
@configs[@current_recipe] = config
after_everything do
git :init
git :add => '.'
git :commit => '-m "Initial import."'
end
# >---------------------------------[ HAML ]----------------------------------<
@current_recipe = "haml"
@before_configs["haml"].call if @before_configs["haml"]
say_recipe 'HAML'
@configs[@current_recipe] = config
gem 'haml', '>= 3.0.0'
gem 'haml-rails'
# >--------------------------------[ Heroku ]---------------------------------<
@current_recipe = "heroku"
@before_configs["heroku"].call if @before_configs["heroku"]
say_recipe 'Heroku'
config = {}
config['create'] = yes_wizard?("Automatically create appname.heroku.com?") if true && true unless config.key?('create')
config['staging'] = yes_wizard?("Create staging app? (appname-staging.heroku.com)") if config['create'] && true unless config.key?('staging')
config['domain'] = ask_wizard("Specify custom domain (or leave blank):") if config['create'] && true unless config.key?('domain')
config['deploy'] = yes_wizard?("Deploy immediately?") if config['create'] && true unless config.key?('deploy')
@configs[@current_recipe] = config
heroku_name = app_name.gsub('_','')
after_everything do
if config['create']
say_wizard "Creating Heroku app '#{heroku_name}.heroku.com'"
while !system("heroku create #{heroku_name}")
heroku_name = ask_wizard("What do you want to call your app? ")
end
end
if config['staging']
staging_name = "#{heroku_name}-staging"
say_wizard "Creating staging Heroku app '#{staging_name}.heroku.com'"
while !system("heroku create #{staging_name}")
staging_name = ask_wizard("What do you want to call your staging app?")
end
git :remote => "rm heroku"
git :remote => "add production [email protected]:#{heroku_name}.git"
git :remote => "add staging [email protected]:#{staging_name}.git"
say_wizard "Created branches 'production' and 'staging' for Heroku deploy."
end
unless config['domain'].blank?
run "heroku addons:add custom_domains"
run "heroku domains:add #{config['domain']}"
end
git :push => "#{config['staging'] ? 'staging' : 'heroku'} master" if config['deploy']
end
# >--------------------------------[ jQuery ]---------------------------------<
@current_recipe = "jquery"
@before_configs["jquery"].call if @before_configs["jquery"]
say_recipe 'jQuery'
config = {}
config['ui'] = yes_wizard?("Install jQuery UI?") if true && true unless config.key?('ui')
@configs[@current_recipe] = config
gem 'jquery-rails'
after_bundler do
ui = config['ui'] ? ' --ui' : ''
generate "jquery:install#{ui}"
end
# >--------------------------------[ Mongoid ]--------------------------------<
@current_recipe = "mongoid"
@before_configs["mongoid"].call if @before_configs["mongoid"]
say_recipe 'Mongoid'
@configs[@current_recipe] = config
gem 'mongoid', '>= 2.0.0.beta.19'
after_bundler do
generate 'mongoid:config'
end
# >--------------------------------[ MongoHQ ]--------------------------------<
@current_recipe = "mongohq"
@before_configs["mongohq"].call if @before_configs["mongohq"]
say_recipe 'MongoHQ'
config = {}
config['use_heroku'] = yes_wizard?("Use the MongoHQ Heroku addon?") if true && recipe?('heroku') unless config.key?('use_heroku')
config['uri'] = ask_wizard("Enter your MongoHQ URI:") if !config['use_heroku'] && true unless config.key?('uri')
@configs[@current_recipe] = config
if config['use_heroku']
header = <<-YAML
<% if ENV['MONGOHQ_URL'] %>
<% mongohq = URI.parse(ENV['MONGOHQ_URL']) %>
mongohq:
host: <%= mongohq.host %>
port: <%= mongohq.port %>
database: <%= mongohq.path.sub '/', '' %>
username: <%= mongohq.user %>
password: <%= mongohq.password %>
<% end %>
YAML
after_everything do
say_wizard 'Adding mongohq:free addon (you can always upgrade later)'
system 'heroku addons:add mongohq:free'
end
else
mongohq = URI.parse(config['uri'])
header = <<-YAML
mongohq:
host: #{mongohq.host}
port: #{mongohq.port}
database: #{mongohq.path.sub '/',''}
username: #{mongohq.user}
password: #{mongohq.password}
YAML
end
after_bundler do
mongo_yml = "config/mongo#{'id' if recipe?('mongoid')}.yml"
prepend_file mongo_yml, header
inject_into_file mongo_yml, " <<: *mongohq\n", :after => "production:\n <<: *defaults\n"
end
# >-------------------------------[ OmniAuth ]--------------------------------<
@current_recipe = "omniauth"
@before_configs["omniauth"].call if @before_configs["omniauth"]
say_recipe 'OmniAuth'
@configs[@current_recipe] = config
gem 'omniauth', '~> 0.2.0'
after_bundler do
file 'app/controllers/sessions_controller.rb', "class SessionsController < ApplicationController\n def callback\n auth # Do what you want with the auth hash!\n end\n\n def auth; request.env['omniauth.auth'] end\nend"
route "match '/auth/:provider/callback', :to => 'sessions#callback'"
end
# >---------------------------------[ RSpec ]---------------------------------<
@current_recipe = "rspec"
@before_configs["rspec"].call if @before_configs["rspec"]
say_recipe 'RSpec'
@configs[@current_recipe] = config
gem 'rspec-rails', '>= 2.0.1', :group => [:development, :test]
inject_into_file "config/initializers/generators.rb", :after => "Rails.application.config.generators do |g|\n" do
" g.test_framework = :rspec\n"
end
after_bundler do
generate 'rspec:install'
end
@current_recipe = nil
# >-----------------------------[ Run Bundler ]-------------------------------<
say_wizard "Running Bundler install. This will take a while."
run 'bundle install'
say_wizard "Running after Bundler callbacks."
@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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment