Skip to content

Instantly share code, notes, and snippets.

@metamn
Created May 19, 2009 14:35
Show Gist options
  • Save metamn/114140 to your computer and use it in GitHub Desktop.
Save metamn/114140 to your computer and use it in GitHub Desktop.
Basic Rails Application Template
# this is a basic rails application template
# usage: rails <app_name> -m http://gist.github.com/114140.txt OR rails -d mysql ....
puts ""
puts "*******************************************************"
puts ""
puts "Basic Rails application generator with:"
puts " - MySQL support (creating development, test and production databases with configuration file database.yml)"
puts " - HAML/SASS/Compass support"
puts " - BDD support: Cucumber, RSpec, autospec"
puts ""
puts "Requirements:"
puts " - Ubuntu 8.10 Intrepid"
puts " - ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]"
puts " - Rails 2.3.2"
puts " - mysql Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (i486) using readline 5.2"
puts ""
# Database / MySQL
# usage: rails -d mysql <app_name> -m http://gist.github.com/114140.txt
if yes?("Set up MySQL databases?")
db_name = ask("What is your database name?")
dev_user_name = ask("What is your username for development and test databases?")
prod_user_name = ask("What is your username for the production database?")
prod_user_pwd = ask("What is your password for the production database?")
file 'create_database.sql', <<-CODE
create database #{db_name}_development;
create database #{db_name}_test;
create database #{db_name}_production;
grant all privileges on #{db_name}_development.* to '#{dev_user_name}'@'localhost';
grant all privileges on #{db_name}_test.* to '#{dev_user_name}'@'localhost';
grant all privileges on #{db_name}_production.* to '#{prod_user_name}'@'localhost' identified by '#{prod_user_pwd}';
exit
CODE
run "mysql -u root -p < create_database.sql"
run "mv config/database.yml config/database.sqlite.yml"
file 'config/database.yml', <<-CODE
development:
adapter: mysql
encoding: utf8
reconnect: false
database: #{db_name}_development
pool: 5
username: #{dev_user_name}
password:
socket: /var/run/mysqld/mysqld.sock
test:
adapter: mysql
encoding: utf8
reconnect: false
database: #{db_name}_test
pool: 5
username: #{dev_user_name}
password:
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql
encoding: utf8
reconnect: false
database: #{db_name}_production
pool: 5
username: {prod_user_name}
password:
socket: /var/run/mysqld/mysqld.sock
CODE
end
# Testing frameworks
if yes?("(Re)Install BDD? Cucumber + RSpec")
run "sudo gem install term-ansicolor treetop diff-lcs nokogiri builder"
run "sudo gem install rspec rspec-rails cucumber webrat"
end
if yes?("Enable BDD? / Cukes + Specs ")
generate :cucumber
run "wget http://gist.github.com/114171.txt"
run "mv 114171.txt cucumber.yml"
generate :rspec
run "wget http://gist.github.com/79927.txt"
run "mv 79927.txt .autotest"
run "export AUTOFEATURE=true autospec"
end
# View frameworks
if yes?("(Re)Install HAML/SASS and Compass?")
run "sudo gem install --no-ri haml"
run "sudo gem install chriseppstein-compass"
end
if yes?("Enable HAML/SASS/Compass with Blueprint?")
run "haml --rails ."
run "wget http://gist.github.com/114201.txt"
run "mv 114201.txt compass.input"
run "compass --rails -f blueprint . < compass.input"
run "wget http://gist.github.com/114204.txt"
run "mv 114204.txt app/views/layouts/application.html.haml"
run "rm public/index.html"
generate "rspec_controller welcome index"
route "map.root :controller => 'welcome'"
end
rake "db:migrate"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment