- ## Rails App Template
- ## Updated for Rails 3.0.7
- ## Created on 10/23/10
- ## Updated on 5/7/11
- ## Run using $ rails new [appname] -JT -m tpl-cukeapp.rb
- ## Gems
- # Warden and Devise for security
- gem 'warden', '1.0.4'
- gem 'devise', '1.3.0'
- # Extra Plugins
- gem 'formtastic', '1.2.3'
- gem 'escape_utils'
- # SASS for Templating
- gem 'sass'
- gem 'compass'
- # Cucumber and Friends
- gem "rspec-rails", ">= 2.5.0", :group => [:test, :cucumber]
- gem "cucumber-rails", ">= 0.4.1", :group => [:test, :cucumber]
- gem "capybara", :group => [:test, :cucumber]
- gem "database_cleaner", :group => [:test, :cucumber]
- gem "factory_girl_rails", :group => [:test, :cucumber]
- gem "launchy", ">= 0.3.7", :group => [:test, :cucumber]
- gem "spork", ">= 0.8.4", :group => [:test, :cucumber]
- # development
- gem 'auto_tagger', '0.2.3', :group => [:development]
- gem 'rails3-generators', '0.17.4', :group => [:development]
- # all
- gem 'mysql2', '0.2.6'
- gem 'json_pure', '1.4.6'
- 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
- Sass::Plugin.options[:template_location] = { 'app/stylesheets' => 'public/stylesheets' }
- }
- 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"
- generate "jquery:install"
- ## 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
- <h2>Sign in</h2>
- <%= 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
- <h2>Sign up</h2>
- <%= 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"
- create_file "public/javascripts/application.js"
- ## Layout
- layout = <<-LAYOUT
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <title>#{app_name.humanize}</title>
- <%= stylesheet_link_tag "application" %>
- <%= csrf_meta_tag %>
- </head>
- <body>
- <div id="doc">
- <div id="hd">
- <ol class="signin-bar">
- <% if !user_signed_in? %>
- <li><%= link_to "Sign in", signin_url %></li>
- <li><%= link_to "Sign up", signup_url %></li>
- <% else %>
- <li><%= current_user.email %></li>
- <li><%= link_to "Sign out", signout_url %></li>
- <% end %>
- </ol>
- <h1>#{app_name.humanize}</h1>
- </div>
- <div id="bd">
- <p class="notice"><%= notice %></p>
- <p class="alert"><%= alert %></p>
- <div>
- <%= yield %>
- </div>
- </div>
- <div id="ft"><p></p></div>
- </div>
- <%= javascript_include_tag :defaults %>
- <script type="text/javascript">
- <%= yield :javascripts %>
- </script>
- </body>
- </html>
- LAYOUT
- remove_file "app/views/layouts/application.html.erb"
- create_file "app/views/layouts/application.html.erb", layout
- # SASS and SCSS
- create_file "app/stylesheets/_general.sass", <<-GENERAL
- @import "compass/typography/lists"
- html
- font: 13px/1.231 arial, 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
- create_file "app/stylesheets/application.sass", <<-APPLICATION
- @import "general"
- @import "formtastic"
- @import "formtastic_changes"
- APPLICATION
- # formtastic
- generate "formtastic:install"
- run "mv public/stylesheets/formtastic.css app/stylesheets/_formtastic.scss"
- remove_file "public/stylesheets/formtastic_changes.css"
- create_file "app/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 => "."