-
-
Save gumayunov/1126889 to your computer and use it in GitHub Desktop.
Rails 3, RSpec, Factory_Girl, HAML, SASS, Devise, JQuery, Backbone.js, jammit
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
## Rails App Template | |
## Updated for Rails 3.0.7 | |
## Created on 10/23/10 | |
## Updated on 5/25/11 to simplify for my own use | |
## Run using $ rails new [appname] -JT -m tpl-basicapp.rb | |
## Gems | |
# Warden and Devise for security | |
gem 'warden', '1.0.4' | |
gem 'devise', '1.3.0' | |
# HAML and SASS for Templating | |
gem 'sass' | |
gem 'haml' | |
gem 'haml-rails' | |
# Testing | |
gem "rspec-rails", ">= 2.5.0", :group => [:test] | |
gem "factory_girl_rails", :group => [:test] | |
gem "spork", ">= 0.9.0.rc", :group => [:test] | |
gem "jasmine", :group => [:test] | |
gem "faker", :group => [:test] | |
gem "redgreen", :group => [:test] | |
gem "autotest-fsevent", :group => [:test] | |
gem "autotest-growl", :group => [:test] | |
# development | |
gem 'rails3-generators', '0.17.4', :group => [:development] | |
# all | |
gem "jammit" | |
## Generators | |
inject_into_file('config/application.rb', :after => "config.filter_parameters += [:password]") do | |
%q{ | |
config.generators do |g| | |
g.stylesheets false | |
g.template_engine :haml | |
g.test_framework :rspec, :fixture => true, :views => false | |
g.fixture_replacement :factory_girl, :dir => "spec/support/factories" | |
end | |
# Global Sass Option | |
Sass::Plugin.options[:template_location] = { 'app/stylesheets' => 'public/stylesheets' } | |
} | |
end | |
# Latest jQuery UJS | |
# get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" | |
# HACK: Since the get method hates https and redirects | |
jquery = open("https://github.com/rails/jquery-ujs/raw/master/src/rails.js", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read | |
create_file "public/javascripts/rails.js", jquery | |
# 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 "devise:install" | |
generate "devise:views" | |
generate "devise User" | |
# Setup a basic Welcome Controller as the default route | |
generate "controller Welcome index" | |
inject_into_file('config/routes.rb', :after => %[root :to => "welcome#index"]) do | |
%q{ | |
root :to => "welcome#index" | |
} | |
end | |
## Devise routes | |
routes = <<-ROUTES | |
devise_scope :user do | |
get "signup", :to => "devise/registrations#new" | |
get "login", :to => "devise/sessions#new" | |
get "logout", :to => "devise/sessions#destroy" | |
end | |
ROUTES | |
route routes | |
## Login files | |
# signin = <<-SIGNIN | |
# <h2>Login</h2> | |
# | |
# <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> | |
# <%= f.inputs do %> | |
# <%= f.input :email, :as => :email %> | |
# <%= f.input :password, :as => :password %> | |
# <% if devise_mapping.rememberable? -%> | |
# <%= f.input :remember_me, :as => :boolean %> | |
# <% end -%> | |
# <% end %> | |
# <%= f.buttons do %> | |
# <%= f.commit_button "Login" %> | |
# <% end %> | |
# <% end %> | |
# | |
# <%= render :partial => "devise/shared/links" %> | |
# SIGNIN | |
# | |
# remove_file "app/views/devise/sessions/new.html.erb" | |
# create_file "app/views/devise/sessions/new.html.erb", signin | |
# signup = <<-SIGNUP | |
# <h2>Signup</h2> | |
# | |
# <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> | |
# <%= devise_error_messages! %> | |
# <%= f.inputs do %> | |
# <%= f.input :email, :as => :email %> | |
# <%= f.input :password, :as => :password %> | |
# <% end %> | |
# <%= f.buttons do %> | |
# <%= f.commit_button "Signup" %> | |
# <% end %> | |
# <% end %> | |
# | |
# <%= render :partial => "devise/shared/links" %> | |
# SIGNUP | |
# | |
# remove_file "app/views/devise/registrations/new.html.erb" | |
# create_file "app/views/devise/registrations/new.html.erb", signup | |
# Clear the default index | |
remove_file "public/index.html" | |
remove_file "public/images/rails.png" | |
# 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" | |
default_style = <<-LAYOUT | |
body | |
text-align: left | |
font-size: 12px | |
a, a:hover, a:visited | |
color: blue | |
.horizontal-list li | |
display: inline | |
.horizontal-list li a | |
padding: 0.1em | |
#hd h1 | |
font-size: 1.5em | |
.login-bar | |
float: right | |
LAYOUT | |
create_file "app/stylesheets/application.sass", default_style | |
## Layout | |
layout = <<-LAYOUT | |
!!! | |
%html | |
%head | |
%title #{app_name.humanize} | |
= stylesheet_link_tag :all | |
= javascript_include_tag :defaults | |
= csrf_meta_tag | |
%body#doc | |
.hd | |
%ol.login-bar.horizontal-list | |
- if !user_signed_in? | |
%li= link_to "Login", login_url | |
%li= link_to "Signup", signup_url | |
- else | |
%li= current_user.email | |
%li= link_to "Logout", logout_url | |
%h1 #{app_name.humanize} | |
.bd | |
= yield | |
.ft | |
LAYOUT | |
remove_file "app/views/layouts/application.html.erb" | |
create_file "app/views/layouts/application.html.haml", layout | |
## Backbone Directory Structure | |
empty_directory "public/javascripts/vendor" | |
empty_directory "public/javascripts/models" | |
empty_directory "public/javascripts/collections" | |
empty_directory "public/javascripts/controllers" | |
empty_directory "public/javascripts/views" | |
# Javascript Assets | |
get "http://documentcloud.github.com/underscore/underscore-min.js", "public/javascripts/vendor/underscore-min.js" | |
get "http://documentcloud.github.com/backbone/backbone-min.js", "public/javascripts/vendor/backbone-min.js" | |
## Jammit assets | |
assets = <<-ASSETS | |
package_assets: off | |
template_function: _.template | |
javascripts: | |
app: | |
# - public/javascripts/vendor/excanvas.js | |
- public/javascripts/vendor/jquery.min.js | |
- public/javascripts/vendor/jquery-ui.min.js | |
# - public/javascripts/vendor/jquery.jsPlumb-1.2.5-all-min.js | |
- public/javascripts/vendor/underscore-min.js | |
- public/javascripts/vendor/backbone-min.js | |
- public/javascripts/vendor/autoresize.jquery.js | |
- public/javascripts/application.js | |
- public/javascripts/vendor/jquery.dotimeout.js | |
# - public/javascripts/models/Node.js | |
- public/javascripts/models/*.js | |
- public/javascripts/**/*.js | |
- app/views/**/*.jst | |
templates_js: | |
- app/views/**/*.jst | |
stylesheets: | |
app: | |
- public/stylesheets/reset.css | |
- public/stylesheets/mixins.css | |
- public/stylesheets/*.css | |
ASSETS | |
remove_file "config/assets.yml" | |
create_file "config/assets.yml", assets | |
## Git | |
gitignore = <<-END | |
.bundle | |
.DS_Store | |
db/*.sqlite3 | |
log/*.log | |
tmp/**/* | |
public/stylesheets/* | |
END | |
# Re-Make gitignore | |
remove_file ".gitignore" | |
create_file ".gitignore", gitignore | |
run "bundle install" | |
run "rake db:migrate" | |
git :init | |
git :add => "." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment