Skip to content

Instantly share code, notes, and snippets.

@anithri
Created July 10, 2010 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anithri/470966 to your computer and use it in GitHub Desktop.
Save anithri/470966 to your computer and use it in GitHub Desktop.
#----------------------------------------------------------------------------
# Remove unnecessary Rails files
#----------------------------------------------------------------------------
run 'rm README'
run 'rm config/database.yml.example'
run 'rm config/database.yml'
run 'rm public/index.html'
run 'rm public/favicon.ico'
run 'rm public/images/rails.png'
run 'touch README'
#----------------------------------------------------------------------------
# Compass
#----------------------------------------------------------------------------
file 'config/compass.rb', <<-CODE
# Require any additional compass plugins here.
project_type = :rails
project_path = RAILS_ROOT if defined?(RAILS_ROOT)
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "public/stylesheets/"
sass_dir = "app/stylesheets"
images_dir = "public/images"
javascripts_dir = "public/javascripts"
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
http_images_path = "/images"
http_stylesheets_path = "/stylesheets"
http_javascripts_path = "/javascripts"
output_style = :compact
CODE
file 'config/initializers/compass.rb', <<-CODE
require 'compass'
# If you have any compass plugins, require them here.
Compass.configuration.parse(File.join(RAILS_ROOT, "config", "compass.config"))
Compass.configuration.environment = RAILS_ENV.to_sym
Compass.configure_sass_plugin!
CODE
#----------------------------------------------------------------------------
# Git Setup
#----------------------------------------------------------------------------
file '.gitignore', <<-FILE
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
public/uploads/*
gems/*
!gems/cache
!gems/bundler
FILE
git :init
git :submodule => "init"
git :add => '.'
git :commit => "-a -m 'Initial commit'"
#----------------------------------------------------------------------------
# Choose Javascript Framework
#----------------------------------------------------------------------------
run 'mkdir public/uploads && chmod 777 public/uploads'
run 'mkdir public/ui'
ask_js = ask("\r\n\r\nWhat javascript framework do you want to use?\r\n\r\n(1) Prototype\r\n(2) jQuery\r\n(3) MooTools\r\n(4) RightJS")
if ["1", "2", "3", "4"].include?(ask_js)
@prototype = (ask_js=="1")
@jquery = (ask_js=="2")
@mootools = (ask_js=="3")
@rightjs = (ask_js=="4")
else
puts "Woops! You must enter a number between 1 and 4"
ask_js
end
js_framework = [:all,"jquery","mootools","rightjs"][ask_js.to_i - 1]
if !@prototype
run 'rm public/javascripts/controls.js'
run 'rm public/javascripts/dragdrop.js'
run 'rm public/javascripts/effects.js'
run 'rm public/javascripts/prototype.js'
end
if @jquery
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js > public/javascripts/jquery.js"
end
if @mootools
run "curl -L http://mootools.net/download/get/mootools-1.2.4-core-yc.js > public/javascripts/mootools.js"
end
if @rightjs
run "curl -L http://rightjs.org/builds/current/right-min.js > public/javascripts/right.js"
run "curl -L http://rightjs.org/builds/current/right-olds-min.js > public/javascripts/right-olds.js"
end
#----------------------------------------------------------------------------
# Addition of rspec and haml stuff
#----------------------------------------------------------------------------
rvmrc = <<-RVMRC
rvm_gemset_create_on_use_flag=1
rvm gemset use #{app_name}
RVMRC
create_file ".rvmrc", rvmrc
empty_directory "lib/generators"
git :clone => "--depth 0 http://github.com/leshill/rails3-app.git lib/generators"
remove_dir "lib/generators/.git"
gem "factory_girl_rails", ">= 1.0.0", :group => :test
gem "haml", ">= 3.0.12"
gem "rspec-rails", ">= 2.0.0.beta.12", :group => :test
generators = <<-GENERATORS
config.generators do |g|
g.template_engine :haml
g.test_framework :rspec, :fixture => true, :views => false
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
GENERATORS
application generators
get "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "public/javascripts/jquery.js"
get "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "public/javascripts/jquery-ui.js"
get "http://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails.js"
jquery = <<-JQUERY
module ActionView::Helpers::AssetTagHelper
remove_const :JAVASCRIPT_DEFAULT_SOURCES
JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js jquery-ui.js rails.js)
reset_javascript_include_default
end
JQUERY
initializer "jquery.rb", jquery
layout = <<-LAYOUT
!!!
%html
%head
%title #{app_name.humanize}
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
%body
= yield
LAYOUT
remove_file "app/views/layouts/application.html.erb"
create_file "app/views/layouts/application.html.haml", layout
create_file "log/.gitkeep"
create_file "tmp/.gitkeep"
git :init
git :add => "."
docs = <<-DOCS
Run the following commands to complete the setup of #{app_name.humanize}:
% cd #{app_name}
% gem install bundler
% bundle install
% bundle lock
% script/rails generate rspec:install
DOCS
log docs
#----------------------------------------------------------------------------
# Generate Application Layout
# (Assumes you have Haml and Lovely Layouts installed)
#----------------------------------------------------------------------------
file 'app/views/layouts/application.html.haml', <<-CODE
!!!
%html
%head
= title_tag "optional default title here", :prefix => "optional prefix text", :suffix => "optional suffix text"
= description_tag "optional default meta description here"
= keywords_tag "optional default meta keywords here"
= copyright_tag "optional default meta copyright notice here"
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= stylesheet_link_tag 'print.css', :media => 'print'
= stylesheet_link_tag 'ie.css', :media => 'screen, projection'
= javascript_include_tag #{js_framework}
- body do
#wrap
#header
#logo Logo
%ul#nav
%li= link_to "Home", root_url
#page
= yield
CODE
#----------------------------------------------------------------------------
# Create Default Static Pages
#----------------------------------------------------------------------------
route "map.root :controller => 'pages', :action => 'index'"
generate :controller, "pages index"
file 'app/views/pages/index.html.haml', <<-END
%h1 Home Page
%p
:textile
Edit me in *app/views/pages/index.html.haml*
END
#----------------------------------------------------------------------------
# Database
#----------------------------------------------------------------------------
ask_db_type = ask("\r\n\r\nWhich database type would you like to use?\r\n\r\n(1) SQLite\r\n(2) MySQL\r\n(3) PostgreSQL\r\n(4) MongoDB")
if ["1", "2", "3", "4"].include?(ask_db_type)
sqlite = (ask_db_type=="1")
mysql = (ask_db_type=="2")
postgres = (ask_db_type=="3")
mongodb = (ask_db_type=="4")
else
puts "Woops! You must enter a number between 1 and 4"
ask_db_type
end
db_type = ["sqlite3","mysql","postgresql","mongodb"][ask_db_type.to_i - 1]
#----------------------------------------------------------------------------
# ORM
#----------------------------------------------------------------------------
ask_orm_type = ask("\r\n\r\nWhich ORM would you like to use?\n\r\n\r(1) ActiveRecord\n\r(2) MongoMapper")
if %w(1 2).include?(ask_orm_type)
activerecord = (ask_orm_type==1)
mongomapper = (ask_orm_type==2)
else
puts "Woops! You must enter a number between 1 and 2"
ask_orm_type
end
db_name = ask("\r\n\r\nWhat should I call the database?\r\n\r\n(Leave blank to use application name)")
if sqlite
file 'config/database.yml', <<-CODE
development:
adapter: sqlite3
host: localhost
database: db/development.sqlite3
pool: 5
timeout: 5000
test: &TEST
adapter: #{db_type}
host: localhost
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: #{db_type}
host: localhost
database: db/production.sqlite3
pool: 5
timeout: 5000
cucumber:
<<: *TEST
CODE
else
file 'config/database.yml', <<-CODE
development:
adapter: #{db_type}
host: localhost
database: #{db_name}_development
test: &TEST
adapter: #{db_type}
host: localhost
database: #{db_name}_test
production:
adapter: #{db_type}
host: localhost
database: #{db_name}_production
cucumber:
<<: *TEST
CODE
if mongomapper
#----------------------------------------------------------------------------
# MongoMapper Configuration
#----------------------------------------------------------------------------
plugin "git://github.com/compressed/mongo_session_store.git"
file "config/initializers/mongo.rb", <<-CODE
db_config = YAML::load(File.read(RAILS_ROOT + "/config/database.yml")) if db_config[Rails.env] && db_config[Rails.env]['adapter'] == 'mongodb'
mongo = db_config[Rails.env]
MongoMapper.connection = Mongo::Connection.new(mongo['localhost'])
MongoMapper.database = mongo['#{db_name}']
end
CODE
#----------------------------------------------------------------------------
# Setup root.rb
#----------------------------------------------------------------------------
run "rm config/root.rb"
environment = '#{environment}'
vendor_rails = '#{vendor_rails}'
file "Gemfile", <<-END
gem "mongo_mapper", :git => "git://github.com/jnunemaker/mongomapper.git"
END
file "config/root.rb", <<-FILE
# Use Bundler (preferred)
environment = File.expand_path('../../vendor/gems/environment', __FILE__)
if File.exist?("#{environment}.rb")
require environment
# Use 2.x style vendor/rails and RubyGems
else
vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
if File.exist?(vendor_rails)
Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
end
require 'rubygems'
end
#require 'rails/all'
# To pick the frameworks you want, remove 'require "rails/all"'
# and list the framework railties that you want:
#
require "active_model/railtie"
#require "active_record/railtie"
require "action_controller/railtie"
require "action_view/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
FILE
end
end
#----------------------------------------------------------------------------
# Sessions
#----------------------------------------------------------------------------
if activerecord
file 'session_store.rb', <<-END
ActionController::Base.session_store = :active_record_store
END
end
if mongomapper
file 'session_store.rb', <<-END
require 'mongo_session_store'
ActionController::Base.session_store = MongoMapper::SessionStore
END
end
#----------------------------------------------------------------------------
# Bundle the Bundler
#----------------------------------------------------------------------------
run "mkdir gems && mkdir gems/bundler"
inside 'gems/bundler' do
run 'git init'
run 'git pull --depth 1 git://github.com/wycats/bundler.git'
run 'rm -rf .git .gitignore'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment