## Rails App Template ## Updated for Rails 3.1 ## Created on 10/23/10 ## Updated on 11/6/11 ## Run using $ rails new [appname] -JT -m https://raw.github.com/gist/960988/template.rb ## Gems # Warden and Devise for security gem 'warden', '1.0.5' gem 'devise', '1.4.9' # Extra Plugins gem 'formtastic', '2.0.2' gem 'escape_utils' # SASS for Templating gem 'sass' gem 'compass', '~> 0.12.alpha' # Cucumber and Friends gem "rspec-rails", ">= 2.7.0", :group => [:test, :cucumber] gem "cucumber-rails", ">= 1.2.0", :group => [:test, :cucumber] gem "capybara", :group => [:test, :cucumber] gem "database_cleaner", :group => [:test, :cucumber] gem "factory_girl_rails", :group => [:test, :cucumber] # development gem 'auto_tagger', '0.2.3', :group => [:development] gem 'rails3-generators', '0.17.4', :group => [:development] # all gem 'mysql2' gem 'yajl-ruby' gem 'jquery-rails' ## Generators inject_into_file('config/application.rb', :after => "config.filter_parameters += [:password]") do %q{ config.generators do |g| g.stylesheets false g.test_framework :rspec, :fixture => true, :views => false g.fixture_replacement :factory_girl, :dir => "spec/support/factories" end # Global Sass Option config.generators.stylesheet_engine = :sass } end create_file "public/javascripts/rails.js" # 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 --spork" generate "devise:install" generate "devise:views" generate "devise User" ## Devise routes routes = <<-ROUTES devise_scope :user do get "signup", :to => "devise/registrations#new" get "signin", :to => "devise/sessions#new" get "signout", :to => "devise/sessions#destroy" end ROUTES route routes ## Sign in files signin = <<-SIGNIN

Sign in

<%= semantic_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 %> <% end %> <%= f.buttons do %> <%= f.commit_button "Sign in" %> <% 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

Sign up

<%= semantic_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 "Sign up" %> <% 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" ## Layout layout = <<-LAYOUT #{app_name.humanize} <%= stylesheet_link_tag "application" %> <%= csrf_meta_tag %>

#{app_name.humanize}

<%= notice %>

<%= alert %>

<%= yield %>

<%= javascript_include_tag :application %> LAYOUT remove_file "app/views/layouts/application.html.erb" create_file "app/views/layouts/application.html.erb", layout # SASS and SCSS create_file "app/assets/stylesheets/_general.sass", <<-GENERAL @import "compass" @import "compass/typography/lists" html font: 13px/1.231 helvetica, clean, sans-serif #hd::after, #bd::after, #ft::after content: "." display: block height: 0 clear: both visibility: hidden body text-align: left background-color: #eee #doc margin: auto text-align: left width: 57.69em border: 1px solid #ddd padding: 0 1em background-color: white a, a:hover, a:visited color: blue h1 font-size: 1.5em h2 font-size: 1.3em h3 font-size: 1.1em #hd margin-bottom: 0.5em #hd h1 font-size: 1.5em .signin-bar float: right +horizontal-list GENERAL # formtastic generate "formtastic:install" run "mv public/stylesheets/formtastic.css app/assets/stylesheets/_formtastic.scss" remove_file "public/stylesheets/formtastic_changes.css" create_file "app/assets/stylesheets/_formtastic_changes.scss", <<-CHANGES $leftcolumnsize: 98.5%; form.formtastic fieldset { overflow: visible; } form.formtastic fieldset > ol > li { margin-bottom: 0.5em; overflow: visible; } form.formtastic fieldset > ol > li label { display:block; width: 100%; padding-top:0; } form.formtastic fieldset > ol > li p.inline-errors { margin:0.5em 0 0 0; } form.formtastic fieldset > ol > li ul.errors { margin:0.5em 0 0 0; } form.formtastic fieldset > ol > li.string input, form.formtastic fieldset > ol > li.password input, form.formtastic fieldset > ol > li.numeric input, form.formtastic fieldset > ol > li.email input, form.formtastic fieldset > ol > li.url input, form.formtastic fieldset > ol > li.phone input, form.formtastic fieldset > ol > li.search input { width:$leftcolumnsize; } form.formtastic fieldset > ol > li.string input[size], form.formtastic fieldset > ol > li.password input[size], form.formtastic fieldset > ol > li.numeric input[size], form.formtastic fieldset > ol > li.email input[size], form.formtastic fieldset > ol > li.url input[size], form.formtastic fieldset > ol > li.phone input[size], form.formtastic fieldset > ol > li.search input[size] { width:auto; max-width:$leftcolumnsize; } form.formtastic fieldset > ol > li.search input { width:$leftcolumnsize; } form.formtastic fieldset > ol > li.search input[size] { width:auto; max-width:$leftcolumnsize; } form.formtastic fieldset > ol > li.text textarea { width:$leftcolumnsize; } form.formtastic fieldset > ol > li.text textarea[cols] { width:auto; max-width:$leftcolumnsize; } form.formtastic fieldset.buttons { padding-left: 0; } form.formtastic label abbr { display:none } form.formtastic fieldset.inputs { margin-bottom: 0.5em; } form.formtastic fieldset legend { font-weight: bold; } CHANGES create_file "config/compass.rb", <<-COMPASS # This configuration file works with both the Compass command line tool and within Rails. # Require any additional compass plugins here. project_type = :rails # Set this to the root of your project when deployed: http_path = "/" # You can select your preferred output style here (can be overridden via the command line): # output_style = :expanded or :nested or :compact or :compressed # To enable relative paths to assets via compass helper functions. Uncomment: # relative_assets = true # To disable debugging comments that display the original location of your selectors. Uncomment: # line_comments = false # If you prefer the indented syntax, you might want to regenerate this # project again passing --syntax sass, or you can uncomment this: # preferred_syntax = :sass # and then run: # sass-convert -R --from scss --to sass app/stylesheets scss && rm -rf sass && mv scss sass COMPASS ## 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 => "."