Created
April 6, 2012 17:31
-
-
Save diogob/2321526 to your computer and use it in GitHub Desktop.
Rails 3.2 template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding: utf-8 | |
# >---------------------------------------------------------------------------< | |
# | |
# _____ _ _ __ ___ _ | |
# | __ \ (_) | \ \ / (_) | | | |
# | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| | | |
# | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` | | |
# | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| | | |
# |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_| | |
# | |
# 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 = ["activerecord", "capybara", "git", "rspec", "slim"] | |
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 | |
# >-----------------------------[ ActiveRecord ]------------------------------< | |
@current_recipe = "activerecord" | |
@before_configs["activerecord"].call if @before_configs["activerecord"] | |
say_recipe 'ActiveRecord' | |
config = {} | |
config['database'] = multiple_choice("Which database are you using?", [["MySQL", "mysql"], ["Oracle", "oracle"], ["PostgreSQL", "postgresql"], ["SQLite", "sqlite3"], ["Frontbase", "frontbase"], ["IBM DB", "ibm_db"]]) if true && true unless config.key?('database') | |
config['auto_create'] = yes_wizard?("Automatically create database with default configuration?") if true && true unless config.key?('auto_create') | |
@configs[@current_recipe] = config | |
if config['database'] | |
say_wizard "Configuring '#{config['database']}' database settings..." | |
old_gem = gem_for_database | |
@options = @options.dup.merge(:database => config['database']) | |
gsub_file 'Gemfile', "gem '#{old_gem}'", "gem '#{gem_for_database}'" | |
template "config/databases/#{@options[:database]}.yml", "config/database.yml.new" | |
run 'mv config/database.yml.new config/database.sample.yml' | |
run 'rm -f config/database.yml' | |
run 'echo "config/database.yml" >> .gitignore' | |
end | |
gem "schema_plus" | |
gem "schema_validations" | |
gem "schema_associations" | |
create_file "config/initializers/schema_asociations.rb", <<-RUBY | |
SchemaAssociations.setup do |config| | |
config.auto_create = false | |
end | |
RUBY | |
create_file "config/initializers/schema_validations.rb", <<-RUBY | |
SchemaValidations.setup do |config| | |
config.auto_create = false | |
end | |
RUBY | |
after_bundler do | |
rake "db:create:all" if config['auto_create'] | |
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 | |
# >---------------------------------[ 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] | |
gem "shoulda-matchers", :group => [:development, :test] | |
gem "machinist", ">= 2.0.0.beta2", :group => [:development, :test] | |
gem "jasmine", :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' | |
generate 'machinist:install' | |
run 'bundle exec jasmine init ' | |
run 'rm -f public/javascripts/Player.js public/javascripts/Song.js spec/javascripts/PlayerSpec.js spec/javascripts/helpers/SpecHelper.js lib/tasks/jasmine.rake' | |
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' | |
gem 'compass-rails', :group => [:assets] | |
# >---------------------------------[ Application Controller ]----------------------------------< | |
@current_recipe = "application_controller" | |
@before_configs["application_controller"].call if @before_configs["application_controller"] | |
say_recipe 'Application Controller' | |
@configs[@current_recipe] = config | |
gsub_file 'app/controllers/application_controller.rb', "end", " | |
protected | |
def render_404 | |
raise ActionController::RoutingError.new('Not Found') | |
end | |
end | |
" | |
# >---------------------------------[ JS ]----------------------------------< | |
@current_recipe = "js" | |
@before_configs["js"].call if @before_configs["js"] | |
say_recipe 'JS' | |
@configs[@current_recipe] = config | |
gem 'initjs' | |
run "mkdir app/assets/javascripts/lib" | |
run "mkdir app/assets/javascripts/app" | |
run "echo '' > app/assets/javascripts/app/.gitkeep" | |
run "curl http://documentcloud.github.com/underscore/underscore.js > app/assets/javascripts/lib/underscore.js" | |
run "curl http://backbonejs.org/backbone.js > app/assets/javascripts/lib/backbone.js" | |
file 'app/assets/javascripts/app.js', <<-CODE | |
var App = window.App = { | |
// Put other existing namespaces here | |
Common: { | |
init: function(){ | |
}, | |
finish: function(){ | |
}, | |
} | |
}; | |
CODE | |
run 'rm -f app/views/layouts/application.html.erb' | |
file 'app/views/layouts/application.html.slim', <<-CODE | |
doctype html | |
html | |
head | |
title App Title Here | |
= stylesheet_link_tag "application" | |
meta[charset="utf-8"] | |
meta[name="description" content=""] | |
meta[name="keywords" content=""] | |
meta[name="author" content=""] | |
= yield(:meta_tags) | |
= csrf_meta_tag | |
= javascript_include_tag "application" | |
body data-controller-class=controller.class.name data-controller-name=controller.controller_name.camelize data-action=controller.action_name.camelize | |
header | |
= yield | |
footer | |
CODE | |
gsub_file 'app/assets/javascripts/application.js', "//= require_tree .", " | |
//= require ./lib/underscore.js | |
//= require ./lib/backbone.js | |
//= require_tree ./lib | |
//= require ./app.js | |
//= require_tree ./app | |
//= require init.js | |
" | |
@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