Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 8.45 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## Rails App Template
  2. ## Updated for Rails 3.0.7
  3. ## Created on 10/23/10
  4. ## Updated on 5/7/11
  5. ## Run using $ rails new [appname] -JT -m tpl-cukeapp.rb
  6.  
  7. ## Gems
  8.  
  9. # Warden and Devise for security
  10. gem 'warden', '1.0.4'
  11. gem 'devise', '1.3.0'
  12.  
  13. # Extra Plugins
  14. gem 'formtastic', '1.2.3'
  15. gem 'escape_utils'
  16.  
  17. # SASS for Templating
  18. gem 'sass'
  19. gem 'compass'
  20.  
  21. # Cucumber and Friends
  22. gem "rspec-rails", ">= 2.5.0", :group => [:test, :cucumber]
  23. gem "cucumber-rails", ">= 0.4.1", :group => [:test, :cucumber]
  24. gem "capybara", :group => [:test, :cucumber]
  25. gem "database_cleaner", :group => [:test, :cucumber]
  26. gem "factory_girl_rails", :group => [:test, :cucumber]
  27. gem "launchy", ">= 0.3.7", :group => [:test, :cucumber]
  28. gem "spork", ">= 0.8.4", :group => [:test, :cucumber]
  29.  
  30. # development
  31. gem 'auto_tagger', '0.2.3', :group => [:development]
  32. gem 'rails3-generators', '0.17.4', :group => [:development]
  33.  
  34. # all
  35. gem 'mysql2', '0.2.6'
  36. gem 'json_pure', '1.4.6'
  37. gem "jquery-rails"
  38.  
  39. ## Generators
  40.  
  41. inject_into_file('config/application.rb', :after => "config.filter_parameters += [:password]") do
  42.   %q{
  43.     config.generators do |g|
  44.       g.stylesheets false
  45.       g.test_framework :rspec, :fixture => true, :views => false
  46.       g.fixture_replacement :factory_girl, :dir => "spec/support/factories"
  47.     end
  48.  
  49.     # Global Sass Option
  50.     Sass::Plugin.options[:template_location] = { 'app/stylesheets' => 'public/stylesheets' }
  51.   }
  52. end
  53.  
  54. create_file "public/javascripts/rails.js"
  55.  
  56. # Replace the blank one with jQuery served via Google CDN
  57. 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)'
  58.  
  59. # Run all the generators
  60. generate "rspec:install"
  61. generate "cucumber:install --capybara --rspec --spork"
  62. generate "devise:install"
  63. generate "devise:views"
  64. generate "devise User"
  65. generate "jquery:install"
  66.  
  67. ## Devise routes
  68. routes = <<-ROUTES
  69. devise_scope :user do
  70.     get "signup", :to => "devise/registrations#new"
  71.     get "signin", :to => "devise/sessions#new"
  72.     get "signout", :to => "devise/sessions#destroy"
  73.   end
  74. ROUTES
  75. route routes
  76.  
  77. ## Sign in files
  78. signin = <<-SIGNIN
  79. <h2>Sign in</h2>
  80.  
  81. <%= semantic_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
  82.   <%= f.inputs do %>
  83.     <%= f.input :email, :as => :email %>
  84.     <%= f.input :password, :as => :password %>
  85.   <% end %>
  86.   <%= f.buttons do %>
  87.     <%= f.commit_button "Sign in" %>
  88.   <% end %>
  89. <% end %>
  90.  
  91. <%= render :partial => "devise/shared/links" %>
  92. SIGNIN
  93. remove_file "app/views/devise/sessions/new.html.erb"
  94. create_file "app/views/devise/sessions/new.html.erb", signin
  95.  
  96. signup = <<-SIGNUP
  97. <h2>Sign up</h2>
  98.  
  99. <%= semantic_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  100.   <%= devise_error_messages! %>
  101.   <%= f.inputs do %>
  102.     <%= f.input :email, :as => :email %>
  103.     <%= f.input :password, :as => :password %>
  104.   <% end %>
  105.   <%= f.buttons do %>
  106.     <%= f.commit_button "Sign up" %>
  107.   <% end %>
  108. <% end %>
  109.  
  110. <%= render :partial => "devise/shared/links" %>
  111. SIGNUP
  112. remove_file "app/views/devise/registrations/new.html.erb"
  113. create_file "app/views/devise/registrations/new.html.erb", signup
  114.  
  115. # Clear the default index
  116. remove_file "public/index.html"
  117. remove_file "public/images/rails.png"
  118. # Make a blank application javascript file
  119. remove_file "public/javascripts/application.js"
  120. create_file "public/javascripts/application.js"
  121.  
  122. ## Layout
  123.  
  124. layout = <<-LAYOUT
  125. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  126. <html>
  127. <head>
  128.   <title>#{app_name.humanize}</title>
  129.   <%= stylesheet_link_tag "application" %>
  130.   <%= csrf_meta_tag %>
  131. </head>
  132. <body>
  133. <div id="doc">
  134.   <div id="hd">
  135.     <ol class="signin-bar">
  136.       <% if !user_signed_in? %>
  137.         <li><%= link_to "Sign in", signin_url %></li>
  138.         <li><%= link_to "Sign up", signup_url %></li>
  139.       <% else %>
  140.         <li><%= current_user.email %></li>
  141.         <li><%= link_to "Sign out", signout_url %></li>
  142.       <% end %>
  143.     </ol>
  144.     <h1>#{app_name.humanize}</h1>
  145.   </div>
  146.   <div id="bd">
  147.     <p class="notice"><%= notice %></p>
  148.     <p class="alert"><%= alert %></p>
  149.     <div>
  150.       <%= yield %>
  151.     </div>
  152.   </div>
  153.   <div id="ft"><p></p></div>
  154. </div>
  155. <%= javascript_include_tag :defaults %>
  156. <script type="text/javascript">
  157.   <%= yield :javascripts %>
  158. </script>
  159. </body>
  160. </html>
  161. LAYOUT
  162. remove_file "app/views/layouts/application.html.erb"
  163. create_file "app/views/layouts/application.html.erb", layout
  164.  
  165.  
  166. # SASS and SCSS
  167. create_file "app/stylesheets/_general.sass", <<-GENERAL
  168. @import "compass/typography/lists"
  169.  
  170. html
  171.   font: 13px/1.231 arial, helvetica, clean, sans-serif
  172.  
  173. #hd::after, #bd::after, #ft::after
  174.   content: "."
  175.   display: block
  176.   height: 0
  177.   clear: both
  178.   visibility: hidden
  179.  
  180. body
  181.   text-align: left
  182.   background-color: #eee
  183.  
  184. #doc
  185.   margin: auto
  186.   text-align: left
  187.   width: 57.69em
  188.   border: 1px solid #ddd
  189.   padding: 0 1em
  190.   background-color: white
  191.  
  192. a, a:hover, a:visited
  193.   color: blue
  194.  
  195. h1
  196.   font-size: 1.5em
  197.  
  198. h2
  199.   font-size: 1.3em
  200.  
  201. h3
  202.   font-size: 1.1em
  203.  
  204. #hd
  205.   margin-bottom: 0.5em
  206.  
  207. #hd h1
  208.   font-size: 1.5em
  209.  
  210. .signin-bar
  211.   float: right
  212.   +horizontal-list
  213. GENERAL
  214.  
  215. create_file "app/stylesheets/application.sass", <<-APPLICATION
  216. @import "general"
  217. @import "formtastic"
  218. @import "formtastic_changes"
  219. APPLICATION
  220.  
  221. # formtastic
  222.  
  223. generate "formtastic:install"
  224.  
  225. run "mv public/stylesheets/formtastic.css app/stylesheets/_formtastic.scss"
  226.  
  227. remove_file "public/stylesheets/formtastic_changes.css"
  228. create_file "app/stylesheets/_formtastic_changes.scss", <<-CHANGES
  229.  
  230. $leftcolumnsize: 98.5%;
  231.  
  232. form.formtastic fieldset { overflow: visible; }
  233.  
  234. form.formtastic fieldset > ol > li { margin-bottom: 0.5em; overflow: visible; }
  235. form.formtastic fieldset > ol > li label { display:block; width: 100%; padding-top:0; }
  236.  
  237. form.formtastic fieldset > ol > li p.inline-errors { margin:0.5em 0 0 0; }
  238. form.formtastic fieldset > ol > li ul.errors { margin:0.5em 0 0 0; }
  239.  
  240. form.formtastic fieldset > ol > li.string input,
  241. form.formtastic fieldset > ol > li.password input,
  242. form.formtastic fieldset > ol > li.numeric input,
  243. form.formtastic fieldset > ol > li.email input,
  244. form.formtastic fieldset > ol > li.url input,
  245. form.formtastic fieldset > ol > li.phone input,
  246. form.formtastic fieldset > ol > li.search input { width:$leftcolumnsize; }
  247.  
  248. form.formtastic fieldset > ol > li.string input[size],
  249. form.formtastic fieldset > ol > li.password input[size],
  250. form.formtastic fieldset > ol > li.numeric input[size],
  251. form.formtastic fieldset > ol > li.email input[size],
  252. form.formtastic fieldset > ol > li.url input[size],
  253. form.formtastic fieldset > ol > li.phone input[size],
  254. form.formtastic fieldset > ol > li.search input[size] { width:auto; max-width:$leftcolumnsize; }
  255.  
  256. form.formtastic fieldset > ol > li.search input { width:$leftcolumnsize; }
  257. form.formtastic fieldset > ol > li.search input[size] { width:auto; max-width:$leftcolumnsize; }
  258.  
  259. form.formtastic fieldset > ol > li.text textarea { width:$leftcolumnsize; }
  260. form.formtastic fieldset > ol > li.text textarea[cols] { width:auto; max-width:$leftcolumnsize; }
  261.  
  262. form.formtastic fieldset.buttons { padding-left: 0; }
  263.  
  264. form.formtastic label abbr { display:none }
  265.  
  266. form.formtastic fieldset.inputs { margin-bottom: 0.5em; }
  267. form.formtastic fieldset legend { font-weight: bold; }
  268. CHANGES
  269.  
  270. create_file "config/compass.rb", <<-COMPASS
  271.  
  272. # This configuration file works with both the Compass command line tool and within Rails.
  273. # Require any additional compass plugins here.
  274. project_type = :rails
  275.  
  276. # Set this to the root of your project when deployed:
  277. http_path = "/"
  278.  
  279. # You can select your preferred output style here (can be overridden via the command line):
  280. # output_style = :expanded or :nested or :compact or :compressed
  281.  
  282. # To enable relative paths to assets via compass helper functions. Uncomment:
  283. # relative_assets = true
  284.  
  285. # To disable debugging comments that display the original location of your selectors. Uncomment:
  286. # line_comments = false
  287.  
  288.  
  289. # If you prefer the indented syntax, you might want to regenerate this
  290. # project again passing --syntax sass, or you can uncomment this:
  291. # preferred_syntax = :sass
  292. # and then run:
  293. # sass-convert -R --from scss --to sass app/stylesheets scss && rm -rf sass && mv scss sass
  294. COMPASS
  295.  
  296. ## Git
  297.  
  298. gitignore = <<-END
  299. .bundle
  300. .DS_Store
  301. db/*.sqlite3
  302. log/*.log
  303. tmp/**/*
  304. public/stylesheets/*
  305. END
  306.  
  307. # Re-Make gitignore
  308. remove_file ".gitignore"
  309. create_file ".gitignore", gitignore
  310.  
  311. run "bundle install"
  312. run "rake db:migrate"
  313.  
  314. git :init
  315. git :add => "."