-
-
Save bobanj/857423 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
# Helpers | |
def git_update(message) | |
git :add => ".", :commit => "-m '#{message}'" | |
end | |
def git_remove(file) | |
git :rm => file | |
end | |
# Git | |
say "Git setup", :yellow | |
append_file '.gitignore' do | |
<<-RUBY | |
.DS_Store | |
.autotest | |
.sass-cache | |
config/database.yml | |
log/*.log | |
coverage | |
*.pid | |
public/system | |
public/uploads | |
rerun.txt | |
capybara*.html | |
vendor/cache/* | |
RUBY | |
end | |
git :init | |
git_update "Initial commit with basic rails app" | |
# Crap | |
say "removing unneccessary files...", :yellow | |
git_remove 'public/index.html' | |
git_remove 'public/favicon.ico' | |
git_remove 'public/images/rails.png' | |
git_remove 'README' | |
run 'touch README.md' | |
git_update "Removed unneccessary files" | |
# RVMRC | |
say ".rvmrc setup", :yellow | |
rvm_lib_path = "#{`echo $rvm_path`.strip}/lib" | |
$LOAD_PATH.unshift(rvm_lib_path) unless $LOAD_PATH.include?(rvm_lib_path) | |
require 'rvm' | |
rvm_env = RVM::Environment.current | |
create_file ".rvmrc" do | |
"rvm use #{rvm_env.environment_name} --create\nrvm wrapper #{rvm_env.environment_name} textmate" | |
end | |
git_update "Added .rvmrc" | |
# Gems | |
say "Gemfile setup", :yellow | |
remove_file "Gemfile" | |
create_file "Gemfile" do | |
<<-RUBY | |
source "http://rubygems.org" | |
# Essentials | |
gem 'mysql2' | |
gem 'devise' | |
gem 'simple_form' | |
gem 'responders' | |
# Frontend | |
gem 'jquery-rails' | |
gem 'haml-rails' | |
gem 'compass' | |
gem 'compass-colors' | |
group :development do | |
gem 'awesome_print' | |
gem 'rails3-generators' | |
# html2haml | |
gem 'hpricot' | |
gem 'ruby_parser' | |
end | |
group :test do | |
gem 'rspec' | |
gem 'rspec-rails' | |
gem 'cucumber-rails' | |
gem 'factory_girl_rails' | |
gem 'fuubar' | |
gem 'fuubar-cucumber' | |
gem 'spork', '~> 0.9.0.rc4' | |
gem 'infinity_test' | |
gem 'launchy' | |
gem 'faker' | |
gem 'pickle' | |
gem 'capybara' | |
gem 'database_cleaner' | |
end | |
RUBY | |
end | |
run 'bundle install' | |
git_update "Added some gems" | |
# Gem setup | |
say "jQuery setup", :yellow | |
generate 'jquery:install' | |
git_update "Setup jquery" | |
say "compass setup", :yellow | |
run "compass init rails ." | |
git_update "Setup compass" | |
say "responders setup", :yellow | |
generate "responders:install" | |
git_update "Setup responsers" | |
say "simple_form setup", :yellow | |
generate "simple_form:install" | |
git_update "Setup simple_form" | |
say "RSpec setup", :yellow | |
generate 'rspec:install' | |
append_file ".rspec" do | |
<<-RUBY | |
--format Fuubar | |
--tty | |
--drb | |
RUBY | |
end | |
git_update "Setup rspec" | |
say "Cucumber setup", :yellow | |
generate 'cucumber:install', '--rspec --capybara --spork' | |
gsub_file 'config/cucumber.yml', /'progress'/, "'Cucumber::Formatter::Fuubar'" | |
git_update "Setup cucumber" | |
say "Pickle setup", :yellow | |
generate 'pickle' | |
git_update "Setup pickle" | |
say "Spork setup", :yellow | |
run 'spork rspec --bootstrap' | |
git_update "Setup spork" | |
# Generators | |
initializer 'generators.rb', <<-RUBY | |
Rails.application.config.generators do |g| | |
g.template_engine :haml | |
g.test_framework :rspec | |
g.fixture_replacement :factory_girl, :dir => "spec/factories" | |
g.view_specs false | |
g.helper_specs false | |
g.routing_specs false | |
g.controller_specs false | |
g.stylesheets false | |
g.helper false | |
g.integration_tool false | |
end | |
RUBY | |
git_update "Added generators initializer" | |
# Database | |
say "Database setup", :yellow | |
database_config = "defaults: &defaults | |
adapter: mysql2 | |
encoding: utf8 | |
reconnect: false | |
pool: 5 | |
username: root | |
password: | |
socket: | |
development: | |
<<: *defaults | |
database: #{app_name}_development | |
test: | |
<<: *defaults | |
database: #{app_name}_test | |
production: | |
<<: *defaults" | |
remove_file "config/database.yml" | |
create_file "config/database.yml", database_config | |
create_file "config/database.example.yml", database_config | |
run 'rake db:setup' | |
git_update "Setup database" | |
# Layout | |
create_file "app/views/layouts/application.html.haml", %q{!!! | |
%html | |
%head | |
%title= page_title | |
= stylesheet_link_tag 'screen', :media => 'screen, projection' | |
= stylesheet_link_tag 'print', :media => 'print' | |
/[if IE] | |
= stylesheet_link_tag 'ie', :media => 'screen, projection' | |
= javascript_include_tag :defaults | |
= csrf_meta_tag | |
= yield(:head) | |
%body | |
%header | |
%h1= yield :title | |
#account | |
- if user_signed_in? | |
= "#{t('hello')} #{current_user.email}" | |
= link_to t('sign_out'), destroy_user_session_path | |
- else | |
= link_to t('sign_in'), new_user_session_path | |
| | |
= link_to t('sign_up'), new_user_registration_path | |
%nav | |
= link_to "Home", root_url | |
%content | |
= render :partial => "shared/flash", :object => flash | |
= yield | |
} | |
create_file "app/helpers/layout_helper.rb", %q{module LayoutHelper | |
def title(page_title) | |
content_for :title do | |
page_title.to_s | |
end | |
end | |
def page_title | |
content_for(:title).blank? ? '#{app_name}' : "#{app_name} - #{content_for(:title)}" | |
end | |
def errors_for(*objects) | |
render "shared/error_messages", :objects => objects.flatten | |
end | |
end} | |
create_file "app/views/shared/_flash.html.haml", %q{- flash.each_pair do |key, value| | |
%div{ :class => "flash #{key}" }= value} | |
create_file "app/views/shared/_error_messages.html.haml", %q{- errors = objects.sum { |object| object.errors.full_messages.map { |msg| msg } } | |
- if errors.any? | |
#error_explanation | |
%h2 | |
= pluralize(errors.count, "error") | |
occured: | |
%ul | |
- errors.each do |msg| | |
%li= msg} | |
git_remove "app/views/layouts/application.html.erb" | |
git_update "Added layout and helpers" | |
# Devise | |
say "Devise setup", :yellow | |
generate 'devise:install' | |
puts "modifying environment configuration files for Devise..." | |
gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '### ActionMailer Config' | |
gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do | |
<<-RUBY | |
config.action_mailer.default_url_options = { :host => 'localhost:3000' } | |
# A dummy setup for development - no deliveries, but logged | |
config.action_mailer.delivery_method = :smtp | |
config.action_mailer.perform_deliveries = false | |
config.action_mailer.raise_delivery_errors = true | |
config.action_mailer.default :charset => "utf-8" | |
RUBY | |
end | |
gsub_file 'config/environments/production.rb', /config.i18n.fallbacks = true/ do | |
<<-RUBY | |
config.i18n.fallbacks = true | |
config.action_mailer.default_url_options = { :host => 'yourhost.com' } | |
### ActionMailer Config | |
# Setup for production - deliveries, no errors raised | |
config.action_mailer.delivery_method = :smtp | |
config.action_mailer.perform_deliveries = true | |
config.action_mailer.raise_delivery_errors = false | |
config.action_mailer.default :charset => "utf-8" | |
RUBY | |
end | |
git_update "Setup devise" | |
puts "creating a User model w/ added ame string, modifying routes for Devise..." | |
run 'rails generate devise User' | |
gsub_file 'app/models/user.rb', /attr_accessible :email, :password, :password_confirmation, :remember_me/ do | |
<<-RUBY | |
validates_uniqueness_of :email, :case_sensitive => false | |
attr_accessible :email, :password, :password_confirmation, :remember_me | |
RUBY | |
end | |
run 'rake db:migrate' | |
git_update "Added User model" | |
# i18n | |
gsub_file 'config/application.rb', /# config.i18n.default_locale = :de/, "config.i18n.default_locale = :de" | |
gsub_file 'config/application.rb', /config.action_view.javascript_expansions[:defaults] = %w()/, "# config.action_view.javascript_expansions[:defaults] = %w()" | |
get "https://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/de.yml", "config/locales/rails.de.yml" | |
get "https://gist.github.com/raw/848021/responders.de.yml", "config/locales/responders.de.yml" | |
get "https://gist.github.com/raw/848017/simple_form.de.yml", "config/locales/simple_form.de.yml" | |
get "https://gist.github.com/raw/848028/devise.de.yml", "config/locales/devise.de.yml" | |
git_remove 'config/locales/en.yml' | |
create_file "config/locales/app.de.yml" do | |
<<-RUBY | |
de: | |
hello: "Hallo" | |
show: "Anzeigen" | |
back: "Zurück" | |
save: "Speichern" | |
edit: "Bearbeiten" | |
create: "Anlegen" | |
update: "Bearbeiten" | |
destroy: "Löschen" | |
confirm: "Sind Sie sicher?" | |
# Layout | |
sign_up: "Anmelden" | |
sign_in: "Login" | |
sign_out: "Logout" | |
RUBY | |
end | |
git_update "Setup locale" | |
# Homepage | |
say "Homepage setup", :yellow | |
generate(:controller, "pages index") | |
gsub_file 'config/routes.rb', /get \"pages\/index\"/, 'root :to => "pages#index"' | |
git_update "Added homepage" | |
# JavaScript | |
create_file 'public/javascripts/application.js' do | |
%q{var App = { | |
init: function() { | |
} | |
}; | |
$(function() { | |
App.init(); | |
}); | |
} | |
end | |
git_update "Added basic javascript application" |
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
#!/usr/bin/env ruby | |
rvm_ruby = ARGV[0] | |
app_name = ARGV[1] | |
template = ARGV[2] || "https://gist.github.com/raw/848195/rails-app-template.rb" | |
unless rvm_ruby && app_name && template | |
puts "\nYou need to:\n" | |
puts "- specify which rvm ruby to use\n" unless rvm_ruby | |
puts "- specify the name of your app\n" unless app_name | |
puts "\n" | |
exit | |
end | |
rvm_lib_path = "#{`echo $rvm_path`.strip}/lib" | |
$LOAD_PATH.unshift(rvm_lib_path) unless $LOAD_PATH.include?(rvm_lib_path) | |
require 'rvm' | |
@env = RVM::Environment.new(rvm_ruby) | |
puts "Creating gemset #{app_name} in #{rvm_ruby}" | |
@env.gemset_create(app_name) | |
@env = RVM::Environment.new("#{rvm_ruby}@#{app_name}") | |
puts "Installing bundler and rails." | |
puts "Successfully installed bundler" if @env.system("gem", "install", "bundler") | |
puts "Successfully installed rails" if @env.system("gem", "install", "rails") | |
system("rvm #{rvm_ruby}@#{app_name} exec rails new #{app_name} -JT -d mysql -m #{template}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment