Skip to content

Instantly share code, notes, and snippets.

@rgaidot
Created August 23, 2011 12:48
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 rgaidot/1165011 to your computer and use it in GitHub Desktop.
Save rgaidot/1165011 to your computer and use it in GitHub Desktop.
Simple Rails Template
#
# Simple Rails Template
#
# e.g: rails new myapp -d mysql -m http://.../simple-rails-template.rb
#
# Enjoy !
#
# ~ @rgaidot
#
begin
require 'bundler'
rescue Bundler::GemNotFound => e
STDERR.puts e.message
exit!
end
config = {}
def _ask(question)
ask "\033[0m\033[36m #{question}\033[0m"
end
def yes_or_not?(question)
answer = _ask(question + " \033[33m(y/n)\033[0m")
case answer.downcase
when "yes", "y"
true
when "no", "n"
false
else
yes_or_not?(question)
end
end
config['database'] = yes_or_not?("Do you want init Database?") if true && true unless config.key?('database')
config['ui'] = yes_or_not?("Install jQuery UI?") if true && true unless config.key?('ui')
config['auth'] = yes_or_not?("Do you want authentication?") if true && true unless config.key?('auth')
config['facebook'] = yes_or_not?("Do you want use Facebook OpenGraph?") if true && true unless config.key?('facebook')
config['heroku'] = yes_or_not?("Do you want use Heroku?") if true && true unless config.key?('heroku')
config['pow'] = yes_or_not?("Do you want use Pow?") if true && true unless config.key?('pow')
gem 'capistrano'
gem 'SystemTimer', :platforms => :ruby_18
gem 'curb'
if config['auth']
gem 'devise'
gem 'cancan'
gem 'omniauth', "~> 0.2.6"
end
gem 'rest-graph' if config['facebook']
gem 'heroku' if config['heroku']
gem 'em-http-request'
gem 'memcache-client'
gem 'friendly_id'
gem 'haml'
gem 'haml-rails'
gem 'sass'
gem 'compass'
gem 'barista'
gem 'coffee-script'
gem 'coffee-filter'
gem 'jquery-rails'
gem 'uglifier'
gem 'kaminari'
gem 'rspec-rails', :group => [:development, :test]
gem 'webrat', :group => [:development, :test]
gem 'cucumber', :group => [:development, :test]
gem 'cucumber-rails', :group => [:development, :test]
gem 'database_cleaner', :group => [:development, :test]
gem 'rspec', :group => [:development, :test]
gem 'rspec-rails', :group => [:development, :test]
gem 'factory_girl_rails', :group => [:development, :test]
gem 'guard-webrick', :group => [:development, :test]
generators = <<-GENERATORS
config.generators do |g|
g.template_engine :haml
g.stylesheet_engine = :sass
g.test_framework :rspec, :fixture => true, :views => false
end
GENERATORS
application generators
layout = <<-LAYOUT
!!!
%html
%head
%title= h(yield :title || "#{app_name.humanize}")
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
= yield :head
%body
#container
#header
%h1= "#{app_name.humanize}"
= yield :header
#content
#notice
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_\#\{name\}", :class => 'flash'
%h2=h yield :title
= yield
#footer
= yield :footer
LAYOUT
create_file "app/views/layouts/application.html.haml", layout
rvmrc = <<-RVMRC
rvm ruby-1.9.2@#{app_name} --create
RVMRC
create_file ".rvmrc", rvmrc
readme_md = <<-READMEMD
# #{app_name}
READMEMD
create_file "README.md", readme_md
run "ln -s #{destination_root} ~/.pow/#{app_name}" if config['pow']
run "rvm use ruby-1.9.2@#{app_name} --create"
run 'bundle install'
run 'rails g rspec:install'
run 'compass init rails .'
run "rails g jquery:install#{config['ui'] ? ' --ui' : ''}"
run 'rails g kaminari:views default'
if config['auth']
run 'rails g devise:install'
run 'rails g devise user'
run 'rails g devise:views'
end
remove_file 'README'
remove_file 'public/index.html'
remove_file 'public/images/rails.png'
remove_file 'app/views/layouts/application.html.erb'
create_file 'log/.gitkeep'
create_file 'tmp/.gitkeep'
if config['auth'] && config['database']
run 'rake db:create:all'
run 'rake db:migrate'
end
git :init
git :add => "."
git :commit => "-a -m 'Initial commit'"
if config['heroku']
run 'heroku keys:add'
run "heroku create #{app_name}"
end
docs = <<-DOCS
\033[0m\033[36m Enjoy your "#{app_name.humanize}" app is now created!
DOCS
log docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment