Skip to content

Instantly share code, notes, and snippets.

@pgericson
Forked from martinisoft/tpl-cukeapp.rb
Created January 17, 2011 09:24
Show Gist options
  • Save pgericson/782646 to your computer and use it in GitHub Desktop.
Save pgericson/782646 to your computer and use it in GitHub Desktop.
Install the most common rails things for a new project
## Rails App Template
## Updated for Rails 3.0.3
## Forked on 14-01-11
## Updated on 14-01-11
## Run using $ rails new [appname] -JT -m tpl-railsapp.rb
## Gems
# Devise for security
gem 'devise', '1.1.3'
# Extra Plugins
#gem 'formtastic', '~> 1.1.0'
#Layout
gem 'haml', "3.0.25"
gem 'haml-rails'
#jquery
#It have to be this one, or else it cant download it because of ssl certificate problems
gem 'jquery-rails', :git => "git://github.com/pgericson/jquery-rails.git"
#Test stuff
gem 'rspec-rails', "2.4.1", :group => :test
gem 'cucumber-rails', "0.3.2" , :group => :test
gem 'capybara', "0.4.0", :group => :test
gem 'factory_girl_rails', "1.0.1", :group => :test
run "bundle install"
## Generators
inject_into_file('config/application.rb', :after => "config.i18n.default_locale = :en") do
%q{
# Generator Settings
config.generators do |g|
g.template_engine :haml
g.test_framework :rspec
g.fixture_replacement :factory_girl
end
# Global Sass Option
Sass::Plugin.options[:template_location] = { 'app/stylesheets' => 'public/stylesheets' }
}
end
# Replace the blank one with jQuery served via Google CDN
#gsub_file 'config/application.rb', 'config.action_view.javascript_expansions[:defaults] = %w()', 'config.action_view.javascript_expansions[:defaults] = %w(http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js rails.js)'
# Run all the generators
generate "rspec:install"
generate "cucumber:install --capybara --rspec"
generate "devise:install"
generate "devise User"
#use --ui to install JQuery ui
generate "jquery:install --version 1.4.3"
## Files
# Clear the default index
remove_file "public/index.html"
# Make a blank application javascript file
remove_file "public/javascripts/application.js"
create_file "public/javascripts/application.js"
# Make the SASS directory and base file
empty_directory "app/stylesheets"
create_file "app/stylesheets/application.scss"
#create the reset SCSS by Eric Meyer: http://meyerweb.com/eric/thoughts/2008/01/15/resetting-again/
#Have to make a small hack to download from the httpS server, it gets "certificate verify failed" otherwise
#http://situated.wordpress.com/2008/06/10/opensslsslsslerror-certificate-verify-failed-open-uri/ <--- fix found here
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
reset_css = open("https://gist.github.com/raw/286067/a720291799bb94cd9d58473e5bff2f644adfef34/reset.sass")
create_file "app/stylesheets/reset.scss", reset_css
## Layout
layout = <<-LAYOUT
!!!
%html
%head
%title #{app_name.humanize}
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
%body
%p.notice= flash[:notice]
%p.alert= flash[:alert]
= yield
LAYOUT
remove_file "app/views/layouts/application.html.erb"
create_file "app/views/layouts/application.html.haml", layout
## Git
gitignore = <<-END
.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/**/*
public/stylesheets/*
*.swp
*.swo
*.swn
*.swl
END
# Re-Make gitignore
remove_file ".gitignore"
create_file ".gitignore", gitignore
# Setup Factory_Girl
empty_directory 'spec/support'
create_file 'spec/support/factories.rb'
git :init
git :add => "."
run "git commit -m 'initial commit'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment