Created
March 11, 2009 13:30
-
-
Save yannlugrin/77468 to your computer and use it in GitHub Desktop.
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
# >----------------------------[ Initial Setup ]------------------------------< | |
# generator initializer | |
initializer 'generators.rb', <<-RUBY | |
Rails.application.config.generators do |g| | |
end | |
RUBY | |
# say methods | |
def say_step(name); say "\033[36m" + 'step'.rjust(10) + "\033[0m" + " Running #{name} step..." end | |
def say_info(text); say "\033[36m" + 'info'.rjust(10) + "\033[0m" + " #{text}" end | |
def say_ask(text); ask "\033[36m" + 'ask'.rjust(10) + "\033[0m" + " #{text}" end | |
# blocks to run after bundler install | |
@after_blocks = [] | |
def after_bundler(&block); @after_blocks << block; end | |
# remove comment in Gemfile | |
gsub_file 'Gemfile', /^(#[^#\n]+|\n*)$/i, '' | |
gsub_file 'Gemfile', /([^\n]+)\n\n+$/im, '\1' | |
# inject_into_file 'Gemfile', :after => /^source.+$/ { "\n" } | |
# >---------------------------------[ RVM ]-----------------------------------< | |
say_step 'rvm' | |
ruby_version = say_ask('choose ruby rvm version (default: 1.9.2):') | |
ruby_version = '1.9.2' if ruby_version.empty? | |
say_info "You have selected ruby #{ruby_version}, added to rvm config file" | |
rvmrc = <<-RVMRC | |
rvm_gemset_create_on_use_flag=1 | |
rvm use #{ruby_version} | |
RVMRC | |
create_file '.rvmrc', rvmrc | |
create_file '.rvmrc.sample', rvmrc | |
# >---------------------------------[ ORM ]-----------------------------------< | |
say_step 'ORM' | |
# Do not require active record by default | |
gsub_file 'config/application.rb', "require 'rails/all'", "# Pick the frameworks you want:\n#require 'active_record/railtie'\nrequire 'action_controller/railtie'\nrequire 'action_mailer/railtie'\nrequire 'active_resource/railtie'\nrequire 'rails/test_unit/railtie'" | |
# Do not require sqlite by default | |
gsub_file 'Gemfile', /^.*sqlite.*$/, '' | |
use_active_record = use_mongoid = false | |
used_orm = say_ask('choose ORM [active_record (default), mongoid]:') | |
if used_orm.chomp == 'mongoid' | |
say_info 'You have selected Mongoid' | |
use_mongoid = true | |
gem 'bson_ext' | |
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git' | |
gem 'machinist_mongo', :group => :test, :require => 'machinist/mongoid', :git => 'git://github.com/nmerouze/machinist_mongo.git', :branch => 'machinist2' | |
gem 'remarkable_mongoid', :group => :test, :require => 'remarkable/mongoid' | |
inject_into_file "config/initializers/generators.rb", :after => "Rails.application.config.generators do |g|\n" do | |
" g.orm = :mongoid\n" | |
end | |
after_bundler do | |
generate 'mongoid:config' | |
end | |
else # ative_record | |
say_info 'You have selected ActiveRecord' | |
use_active_record = true | |
gsub_file 'config/application.rb', "#require 'active_record/railtie'", "require 'active_record/railtie'" | |
gem 'sqlite3-ruby', :require => 'sqlite3' | |
gem 'remarkable_activerecord', '>= 4.0.0.alpha4', :group => :test, :require => 'remarkable/active_record' | |
inject_into_file "config/initializers/generators.rb", :after => "Rails.application.config.generators do |g|\n" do | |
" g.orm = :active_record\n" | |
end | |
end | |
# >-------------------------------[ Testing ]---------------------------------< | |
say_step 'testing' | |
remove_file 'test' | |
say_info 'install rspec, steak, machinist and related libraries' | |
gem 'rspec-rails', :group => [:test, :development] | |
gem 'steak', '>= 1.0.0.rc.2', :group => [:test, :development] | |
gem 'machinist', '>= 2.0.0.beta2', :group => :test | |
gem 'remarkable', '>= 4.0.0.alpha4', :group => :test | |
inject_into_file "config/initializers/generators.rb", :after => "Rails.application.config.generators do |g|\n" do | |
" g.test_framework :rspec, :fixture => true, :views => false\n" + | |
" g.fixture_replacement :machinist\n" | |
end | |
after_bundler do | |
generate 'rspec:install' | |
generate 'steak:install' | |
generate 'machinist:install' | |
gsub_file 'spec/support/blueprints.rb', 'active_record', 'mongoid' | |
create_file '.rspec', '--colour', :force => true | |
create_file '.rspec.sample', '--colour' | |
remove_file 'autotest' | |
end | |
say_info 'install guard and related plugins (included livereload)' | |
gem 'guard', :group => [:test, :development] | |
gem 'guard-rspec', :group => [:test, :development] | |
gem 'guard-bundler', :group => [:test, :development] | |
gem 'guard-livereload', :group => [:test, :development] | |
gem 'guard-compass', :group => [:test, :development] | |
guardfile = <<-GUARD | |
guard 'bundler' do | |
watch('^Gemfile') | |
end | |
guard 'rspec', :version => 2 do | |
watch('^spec/(.+)_spec\\.rb') | |
watch('^app/(.+)\\.rb') { |m| 'spec/\#{m[1]}_spec.rb' } | |
watch('^app/controllers/application_controller\\.rb') { 'spec/controllers' } | |
watch('^lib/(.+)\\.rb') { |m| 'spec/lib/\#{m[1]}_spec.rb' } | |
watch('^lib/(.+)\\.rb' { |m| 'spec/lib/\#{m[1]}_spec.rb"'} | |
watch('^spec/spec_helper\\.rb') { 'spec' } | |
watch('^spec/support/blueprints\\.rb') { 'spec/models' } | |
end | |
guard 'compass' do | |
watch('^src/(.*)\.s[ac]ss') | |
end | |
guard 'livereload' do | |
watch('^app/.+\.(erb|haml)$') | |
watch('^app/helpers/.+\.rb$') | |
watch('^/public/.+\.(css|js|html)$') | |
watch('^config/locales/.+\.ym$') | |
end | |
GUARD | |
create_file 'Guardfile', guardfile | |
# >------------------------------[ Javascript ]-------------------------------< | |
say_step 'javascript' | |
say_info 'install JQuery' | |
remove_file 'public/javascripts' | |
inside 'public/javascripts' do | |
get 'http://code.jquery.com/jquery-latest.js', 'vendor/jquery.js' | |
get 'http://github.com/rails/jquery-ujs/raw/master/src/rails.js', 'vendor/rails.js' | |
end | |
gsub_file 'config/application.rb', /# JavaScript.*\n/, '' | |
gsub_file 'config/application.rb', /# config\.action_view\.javascript.*\n/, '' | |
# >---------------------------------[ CSS ]-----------------------------------< | |
say_step 'css' | |
say_info 'install Compass & SCSS' | |
gem 'haml', :group => [:test, :development] | |
gem 'compass', :group => [:test, :development] | |
after_bundler do | |
run 'compass init rails . -s nested --sass-dir app/stylesheets --css-dir public/stylesheets --images-dir public/images --javascripts-dir public/javascripts' | |
run 'compass compile' | |
end | |
# >-------------------------------[ Template ]--------------------------------< | |
say_step 'template' | |
layout_html = <<-HTML | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>MyApp</title> | |
<%= include_stylesheets :common, :media => 'screen, projection' %> | |
<!--[if lte IE 8]> | |
<%= include_stylesheets :ie, :media => 'screen, projection' %> | |
<!--[if lte IE 7]> | |
<%= include_stylesheets :print, :media => 'print' %> | |
<%= include_javascripts :common %> | |
<%= csrf_meta_tag %> | |
</head> | |
<body> | |
<%= yield %> | |
</body> | |
</html> | |
HTML | |
create_file 'app/views/layouts/application.html.erb', layout_html, :force => true | |
remove_file 'public/index.html' | |
remove_file 'public/images/rails.png' | |
remove_file 'README' | |
# >--------------------------------[ Assets ]---------------------------------< | |
say_step 'assets' | |
say_info 'insall jammit' | |
gem 'jammit' | |
assets_yml = <<-JAMMIT | |
javascript_compressor: closure | |
javascripts: | |
common: | |
- public/javascripts/vendor/jquery.js | |
- public/javascripts/vendor/rails.js | |
- public/javascripts/lib/*.js | |
- public/javascripts/application.js | |
stylesheets: | |
common: | |
- public/stylesheets/screen.css | |
print: | |
- public/stylesheets/print.css | |
ie: | |
- public/stylesheets/ie.css | |
JAMMIT | |
create_file 'config/assets.yml', assets_yml | |
# >-----------------------------[ Run Bundler ]-------------------------------< | |
say_step 'bundler' | |
say_info 'Running Bundler install for rvm gemset. This will take a while.' | |
run "rvm use #{ruby_version}" | |
run 'gem install bundler' | |
run 'bundle install' | |
say_info 'Running after Bundler callbacks.' | |
@after_blocks.each{|b| b.call } | |
# >---------------------------------[ Git ]-----------------------------------< | |
say_step 'git' | |
create_file 'log/.gitkeep' | |
create_file 'tmp/.gitkeep' | |
git :init | |
git_user_name = say_ask("Git user name (global: #{`git config --global user.name`.strip}): ").chomp | |
git_user_email = say_ask("Git user email (global: #{`git config --global user.email`.strip}): ").chomp | |
git :config => "user.name #{git_user_name}" unless git_user_name.empty? | |
git :config => "user.email #{git_user_email}" unless git_user_email.empty? | |
append_file '.gitignore', '.rspec' | |
append_file '.gitignore', '.rvmrc' | |
git :add => '.' | |
say_info 'git is initalized, please review generated app and commit' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment