geetarista (owner)

Revisions

gist: 103358 Download_button fork
public
Public Clone URL: git://gist.github.com/103358.git
Embed All Files: show embed
rails app generator.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# Run use this template by running: rails my_new_app -m /path/to/template.rb (can also be an URL)
# Or, to use on an existing project: rake rails:template LOCATION=~/template.rb
 
app_name = ask("What do you want to call this project? ")
 
environment("config.action_controller.session = { :key => '_#{app_name}_session', :secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}' }")
 
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm -f public/javascripts/*"
 
# Download JQuery
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js > public/javascripts/jquery.js"
run "curl -L http://jqueryjs.googlecode.com/svn/trunk/plugins/form/jquery.form.js > public/javascripts/jquery.form.js"
 
# git:hold_empty_dirs
run("find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;")
 
freeze!
 
# Link to local copy of edge rails
inside('vendor') { run 'ln -s ~/dev/rails/rails rails' }
 
# generate(:scaffold, "person name:string")
route "map.root :controller => 'people'"
 
rake("rails:freeze:gems") if yes?("Freeze rails gems ?")
 
run "rake rails:freeze:edge" if yes?("Do you want to use edge rails?")
 
if yes?("Do you want to use RSpec?")
  plugin "rspec", :git => "git://github.com/dchelimsky/rspec.git"
  plugin "rspec-rails", :git => "git://github.com/dchelimsky/rspec-rails.git"
  # generate(:what, "name", "column:type")
  generate :rspec
end
 
if yes?("Do you want authentication?")
  plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git'
  run "mv vendor/plugins/restful-authentication vendor/plugins/restful_authentication"
  
  modle = ask("What do you want your account model to be called? [account]")
  modle = "account" if modle.blank?
  
  controller = ask("What do you want your authentication controller to be called? [sessions]")
  controller = "sessions" if modle.blank?
  
  run "./script/generate authenticated #{modle} #{controller} --include-activation --rspec"
end
 
run "echo 'TODO add readme content' > README"
 
run "cp config/database.yml config/database_sample.yml"
 
plugin "rspec", :git => "git://github.com/dchelimsky/rspec.git", :submodule => true
plugin "rspec-rails", :git => "git://github.com/dchelimsky/rspec-rails.git", :submodule => true
plugin "exception-notifier", :git => "git://github.com/rails/exception_notification.git", :submodule => true
plugin "restful-authentication", :git => "git://github.com/technoweenie/restful-authentication.git", :submodule => true
plugin "semantic-form-builder", :git => "git://github.com/rubypond/semantic_form_builder.git", :submodule => true
plugin "paperclipped", :git => "git://github.com/kbingman/paperclipped.git", :submodule => true
# Or use SVN: plugin 'wtfsvn' :svn => 'svn://crap.com/wtf/trunk'
 
# Install necessary gems
gem "will-paginate", :git => "git://github.com/mislav/will_paginage.git"
gem "haml", :git => "git://github.com/nex3/haml.git" #, :version => '0.6'
rake "gems:install", :sudo => true
run "haml --rails ."
 
# Create a route
route "map.login '/login', :controller => 'sessions', :action => 'new'"
 
initializer 'form_builder.rb', <<-CODE
ActionView::Base.default_form_builder = SemanticFormBuilder
CODE
 
# Set up sessions, RSpec, user model, OpenID, etc, and run migrations
rake('db:sessions:create')
generate("authenticated", "user session")
generate("roles", "Role User")
generate("rspec")
rake('acts_as_taggable:db:create')
rake('open_id_authentication:db:create')
rake('db:migrate')
 
# Set up session store initializer
initializer 'session_store.rb', <<-END
ActionController::Base.session = { :session_key => '_#{(1..6).map { |x| (65 + rand(26)).chr }.join}_session', :secret => q }
ActionController::Base.session_store = :active_record_store
END
 
git :submodule => "init"
 
rake "db:migrate" #, :env => 'test'
 
run "cp config/database.yml config/database.yml.sample"
 
initializer 'action_mailer_configs.rb',
  %q{ ActionMailer::Base.smtp_settings = {
:address => "smtp.thoughtbot.com",
:port => 25,
:domain => "thoughtbot.com"
}
}
 
initializer 'requires.rb',
%q{require 'redcloth'
 
Dir[File.join(RAILS_ROOT, 'lib', 'extensions', '*.rb')].each do |f|
require f
end
 
Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f|
require f
end
}
 
initializer 'time_formats.rb',
%q{# Example time formats
{ :short_date => "%x", :long_date => "%a, %b %d, %Y" }.each do |k, v|
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(k => v)
end
}
 
capify!
 
file 'config/environment.rb',
%q{# Be sure to restart your server when you modify this file
# Change this to the name of your rails project, like carbonrally.
# Just use the same name as the svn repo.
PROJECT_NAME = "CHANGEME"
throw "The project's name in environment.rb is blank" if PROJECT_NAME.empty?
throw "Project name (#{PROJECT_NAME}) must_be_like_this" unless PROJECT_NAME =~ /^[a-z_]*$/
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.0' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# See Rails::Configuration for more options.
# Skip frameworks you're not going to use. To use Rails without a database
# you must remove the Active Record framework.
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
# Specify gems that this application depends on.
config.gem 'RedCloth',
:lib => 'redcloth',
:version => '~> 3.0.4'
config.gem 'mislav-will_paginate',
:lib => 'will_paginate',
:source => 'http://gems.github.com',
:version => '~> 2.3.5'
config.gem 'mocha',
:version => '>= 0.9.2'
config.gem 'quietbacktrace',
:version => '>= 0.1.1'
config.gem 'thoughtbot-factory_girl',
:lib => 'factory_girl',
:source => 'http://gems.github.com',
:version => '>= 1.1.3'
config.gem 'thoughtbot-shoulda',
:lib => 'shoulda',
:source => 'http://gems.github.com',
:version => '>= 2.0.5'
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Add the vendor/gems/*/lib directories to the LOAD_PATH
config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
# Force all environments to use the same logger level
# (by default production uses :info, the others :debug)
# config.log_level = :debug
# Make Time.zone default to the specified zone, and make Active Record store time values
# in the database in UTC, and return them converted to the specified local zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Uncomment to use default local time.
config.time_zone = 'UTC'
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
SESSION_KEY = "CHANGESESSION"
config.action_controller.session = {
:session_key => "_#{PROJECT_NAME}_session",
:secret => SESSION_KEY
}
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
# config.action_controller.session_store = :active_record_store
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
end
}
 
file 'Capfile',
%q{load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
}
 
file 'config/database.yml',
%q{<% PASSWORD_FILE = File.join(RAILS_ROOT, '..', '..', 'shared', 'config', 'dbpassword') %>
development:
adapter: mysql
database: <%= PROJECT_NAME %>_development
username: root
password:
host: localhost
encoding: utf8
test:
adapter: mysql
database: <%= PROJECT_NAME %>_test
username: root
password:
host: localhost
encoding: utf8
staging:
adapter: mysql
database: <%= PROJECT_NAME %>_staging
username: <%= PROJECT_NAME %>
password: <%= File.read(PASSWORD_FILE).chomp if File.readable? PASSWORD_FILE %>
host: localhost
encoding: utf8
socket: /var/lib/mysql/mysql.sock
production:
adapter: mysql
database: <%= PROJECT_NAME %>_production
username: <%= PROJECT_NAME %>
password: <%= File.read(PASSWORD_FILE).chomp if File.readable? PASSWORD_FILE %>
host: localhost
encoding: utf8
socket: /var/lib/mysql/mysql.sock
}
 
file 'config/deploy.rb',
%q{set :stages, %w(staging production)
set :default_stage, 'staging'
require 'capistrano/ext/multistage'
before "deploy:setup", "db:password"
namespace :deploy do
desc "Default deploy - updated to run migrations"
task :default do
set :migrate_target, :latest
update_code
migrate
symlink
restart
end
desc "Start the mongrels"
task :start do
send(run_method, "cd #{deploy_to}/#{current_dir} && #{mongrel_rails} cluster::start --config #{mongrel_cluster_config}")
end
desc "Stop the mongrels"
task :stop do
send(run_method, "cd #{deploy_to}/#{current_dir} && #{mongrel_rails} cluster::stop --config #{mongrel_cluster_config}")
end
desc "Restart the mongrels"
task :restart do
send(run_method, "cd #{deploy_to}/#{current_dir} && #{mongrel_rails} cluster::restart --config #{mongrel_cluster_config}")
end
desc "Run this after every successful deployment"
task :after_default do
cleanup
end
end
namespace :db do
desc "Create database password in shared path"
task :password do
set :db_password, Proc.new { Capistrano::CLI.password_prompt("Remote database password: ") }
run "mkdir -p #{shared_path}/config"
put db_password, "#{shared_path}/config/dbpassword"
end
end
}
 
file 'config/deploy/staging.rb',
%q{# For migrations
set :rails_env, 'staging'
# Who are we?
set :application, 'CHANGEME'
set :repository, "git@github.com:thoughtbot/#{application}.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, "staging"
# Where to deploy to?
role :web, "staging.example.com"
role :app, "staging.example.com"
role :db, "staging.example.com", :primary => true
# Deploy details
set :user, "#{application}"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :use_sudo, false
set :checkout, 'export'
# We need to know how to use mongrel
set :mongrel_rails, '/usr/local/bin/mongrel_rails'
set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_staging.yml"
}
 
file 'config/deploy/production.rb',
%q{# For migrations
set :rails_env, 'production'
# Who are we?
set :application, 'CHANGEME'
set :repository, "git@github.com:thoughtbot/#{application}.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, "production"
# Where to deploy to?
role :web, "production.example.com"
role :app, "production.example.com"
role :db, "production.example.com", :primary => true
# Deploy details
set :user, "#{application}"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :use_sudo, false
set :checkout, 'export'
# We need to know how to use mongrel
set :mongrel_rails, '/usr/local/bin/mongrel_rails'
set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_production.yml"
}
 
file 'config/environments/development.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_view.debug_rjs = true
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
HOST = 'localhost'
}
 
file 'config/environments/production.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = false
}
 
file 'config/environments/staging.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# We'd like to stay as close to prod as possible
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable delivery errors if you bad email addresses should just be ignored
config.action_mailer.raise_delivery_errors = false
}
 
file 'config/environments/test.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
HOST = 'localhost'
require 'quietbacktrace'
require 'factory_girl'
require 'mocha'
begin require 'redgreen'; rescue LoadError; end
}
 
# generate(:scaffold, "person name:string")
route "map.root :controller => 'people'"
 
# Install necessary gems
gem "will-paginate", :git => "git://github.com/mislav/will_paginage.git"
gem "haml", :git => "git://github.com/nex3/haml.git" #, :version => '0.6'
rake "gems:install", :sudo => true
run "haml --rails ."
 
rake "db:migrate" #, :env => 'test'
 
# Setup git ignore file
file '.gitignore', <<-END
*~
*.cache
config/database.yml
public/stylesheets/*.css
*.swo
*.swp
.DS_Store
*.tmproj
log/*
tmp/*
TAGS
.#*
.hgignore
.hg/*
.svn/*
END
 
git :add => "."
git :commit => "-a -m 'Initial commit'"
 
puts "Great success!"