fesplugas (owner)

Fork Of

Forks

Revisions

gist: 81936 Download_button fork
public
Description:
RAILSLOVE.com template.
Public Clone URL: git://gist.github.com/81936.git
Embed All Files: show embed
railslove.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
# RAILSLOVE.com template
#
# with help and ideas from:
# http://gist.github.com/33337 By Peter Cooper
# http://github.com/jeremymcanally/rails-templates/tree/master/suspenders.rb Suspenders by Thoughtbot Nathan Esquenazi
 
 
if yes?("symlink local rails copy to vendor?")
  path = ask("what's the directory of your local rails copy?")
  inside('vendor') { run "ln -s #{path} rails" }
end
 
submodules = yes?("Do you want to add plugins as submodules?")
 
# init the git repository
# files added
git :init
 
 
# ---------------------------------
# gems
# ---------------------------------
 
gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => 'http://gems.github.com'
gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => 'http://gems.github.com'
gem 'ruby-openid', :lib => 'openid'
gem 'mislav-will_paginate', :lib => 'will_paginate', :source => 'http://gems.github.com'
gem 'mocha'
 
 
# ---------------------------------
# plugins
# ---------------------------------
 
plugin 'find_by_param', :git => 'git://github.com/bumi/find_by_param.git', :submodule => submodules
plugin 'redirect_love', :git => 'git://github.com/bumi/redirect_love.git', :submodule => submodules
plugin 'serialize_fu', :git => 'git://github.com/bumi/serializefu.git', :submodule => submodules
plugin 'limerick_rake', :git => "git://github.com/thoughtbot/limerick_rake.git", :submodule => submodules
plugin 'hoptoad_notifier', :git => "git://github.com/thoughtbot/hoptoad_notifier.git", :submodule => submodules
plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => submodules
plugin 'squirrel', :git => "git://github.com/thoughtbot/squirrel.git", :submodule => submodules
plugin 'aasm', :git => 'git://github.com/rubyist/aasm.git', :submodule => submodules
plugin 'annotate_models', :git => 'git://github.com/ctran/annotate_models.git', :submodule => submodules
 
 
# ---------------------------------
# we don't need that
# ---------------------------------
run "rm README && touch README"
run "rm public/index.html"
 
 
# ---------------------------------
# we love edge rails
# ---------------------------------
freeze!
 
 
 
# ---------------------------------
# initializers
# ---------------------------------
 
# mail
initializer 'mail.rb', <<-END
ActionMailer::Base.smtp_settings = {
:address => "smtp.mailer.com",
:port => 25,
:domain => "mailer.com",
:password => ""
}
ActionMailer::Base.default_url_options[:host] = ""
END
 
# exceptions love hoptoad or getexceptional? don't know yet
initializer 'hoptoad.rb',<<-END
 
HoptoadNotifier.configure do |config|
config.api_key = ''
end
END
 
# require extensions
initializer 'requires.rb', <<-END
Dir[File.join(RAILS_ROOT, 'lib', 'extensions', '**/*.rb')].each do |file|
require file
end
Dir[File.join(RAILS_ROOT, 'lib', 'fixes', '**/*.rb')].each do |file|
require file
end
END
 
# ---------------------------------
# Config
# ---------------------------------
 
# not sure if that's really needed.
# add session config to environment.rb
in_root do
  gsub_file 'config/environment.rb', /(#{Regexp.escape('Rails::Initializer.run do |config|')})/mi do |match|
<<-END
#{match}\n
config.action_controller.session = { :session_key => '_#{(1..6).map { |x| (65 + rand(26)).chr }.join}_session', :secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}' }
config.action_controller.session_store = :active_record_store
END
  end
end
 
 
# we love factories
inside ('test') do
  run "mkdir factories"
end
 
# folders for extensions and fixes
inside ('lib') do
  run "mkdir extensions"
  run "mkdir fixes"
end
 
 
# ---------------------------------
# common files
# ---------------------------------
 
# get application_controller started
file 'app/controllers/application_controller.rb',
<<-END
class ApplicationController < ActionController::Base
include HoptoadNotifier::Catcher
helper :all
protect_from_forgery
filter_parameter_logging :password
end
END
 
# add partial for flash messages
file 'app/views/layouts/_flash_messages.html.erb',
<<-END
<% %w{error notice ok}.each do |type| %>
<% unless flash[type.to_sym].blank? %>
<div class="flash <%= type %>">
<% if flash[type.to_sym].is_a?(ActiveRecord::Errors) %>
<%= error_messages_for(flash[type.to_sym]) %>
<% else %>
<%= flash[type.to_sym] %>
<% end %>
</div>
<% end %>
<% end %>
END
 
# ---------------------------------
# Deploy scripts
# ---------------------------------
capify!
 
 
file 'config/deploy.rb', %q{
 
set :stages, %w(staging production)
set :default_stage, 'staging'
 
require 'capistrano/ext/multistage'
namespace :deploy do
# from thoughtbot
desc "Default deploy - updated to run migrations"
task :default do
set :migrate_target, :latest
update_code
migrate
symlink
restart
end
end
 
desc "tail log files"
task :tail_log, :roles => :app do
run "tail -f #{shared_path}/log/#{ENV['RAILS_ENV']}.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
 
desc "remotely console"
task :console, :roles => :app do
input = ''
run "cd #{current_path} && ./script/console #{ENV['RAILS_ENV']}" do |channel, stream, data|
next if data.chomp == input.chomp || data.chomp == ''
print data
channel.send_data(input = $stdin.gets) if data =~ /^(>|\?)>/
end
end
 
task :ssh do
#sorry I don't know how to make this nice and DRY... *shame on me*
don_ips = []
# if you enter an role - just connect to these servers
role = Capistrano::CLI.ui.ask("Role: (leave blank to connect to all server)")
if not role.empty?
roles[role.to_sym].each do |server|
if don_ips.include?(server.host)
puts("we've already hacked on #{server.host}")
next
end
puts server.host
system("ssh #{user}@#{server.host}")
don_ips << server.host
sleep 1
end
# else connect to all servers
else
roles.each do |environment,settings|
puts "----------------------"
puts "#{environment.to_s.capitalize}:"
settings.each do |server|
if don_ips.include?(server.host)
puts("we've already hacked on #{server.host}")
next
end
puts server.host
system("ssh #{user}@#{server.host}")
don_ips << server.host
sleep 1
end
end
end
end
}
 
file 'config/deploy/staging.rb',%q{
set :rails_env, 'staging'
set :application, ''
set :repository, "git@github.com:user/#{application}.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, "staging"
 
set :user, "#{application}"
 
set :ssh_options, {:forward_agent => true}
on :start do
`ssh-add`
end
 
 
role :web, "staging.example.com"
role :app, "staging.example.com"
role :db, "staging.example.com", :primary => true
}
 
file 'config/deploy/production.rb', %q{
set :rails_env, 'production'
set :application, ''
set :repository, "git@github.com:user/#{application}.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, "staging"
 
set :user, "#{application}"
 
set :ssh_options, {:forward_agent => true}
on :start do
`ssh-add`
end
 
 
role :web, "production.example.com"
role :app, "production.example.com"
role :db, "production.example.com", :primary => true
 
}
 
run "cp config/database.yml config/database.yml.example"
 
 
file '.gitignore', <<-END
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
*.pid
END
 
 
# ---------------------------------
# find empty filders and add a .gitignore # thanks Peter Cooper
# ---------------------------------
run "touch tmp/.gitignore log/.gitignore"
run 'find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;'
 
 
# ---------------------------------
# run installer and generator
# ---------------------------------
rake('gems:install', :sudo => true)
rake('gems:unpack')
 
generate("authenticated", "user session")
rake('db:sessions:create')
 
# ---------------------------------
# generate your resources
# ---------------------------------
if yes?("Want to generate some resources?")
  resources = ask("Which resources? (comma-seperated list)")
  resources.split(",").each do |resource|
    generate(:resource, resource)
  end
end
 
 
git :add => '.'
 
if submodules
  git :submodule => "init"
end
 
git :commit => "-a -m 'initial commit'"
 
 
puts "DONE"
puts "Happy coding!"