-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.rb
More file actions
402 lines (311 loc) · 10.1 KB
/
init.rb
File metadata and controls
402 lines (311 loc) · 10.1 KB
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
# RubyX Standard Init Script for Rails 3
RailsVersion = "3.0.9"
instructions =<<-END
Running the RubyX Standard Init Script for Rails 3
--------------------------------------------------
During installation you will be asked for a number
of credentials for different services, these are
entirely optional however you might like to gather
these now.
- Hoptoad API key
- Google Analytics tracking code e.g UA-XXXXXX-XX
This can be found on your Google Analytics settings page.
- TellThemWhen.com Site API key
We are installing Rails #{RailsVersion} on Ruby #{RUBY_VERSION}
--------------------------------------------------
END
say(instructions)
############################################################
# Remove unnecessary Rails files and improve gitignore
#
# ReadME first development :)
run 'rm README'
file "README.md", <<-END
#{app_name.titleize}
===========================
END
git :init
git :add => "README.md"
git :commit => "-m 'Fix up the README'"
# Setup RVM RC and trust it
file ".rvmrc", <<-END
rvm ruby-#{RUBY_VERSION}@#{app_name.titleize} --create
END
run "rvm rvmrc trust"
# Change to the new RVM gemset
run "rvm ruby-#{RUBY_VERSION}@#{app_name.titleize} --create"
git :add => ".rvmrc -f"
git :commit => ".rvmrc -m 'Adding explicit RVMRC'"
# Improve the Gitignore
append_file ".gitignore", "\nconfig/database.yml"
append_file ".gitignore", "\n.rspec"
append_file ".gitignore", "\nvendor/bundle"
append_file ".gitignore", "\n.DS_Store"
git :add => ".gitignore"
git :commit => ".gitignore -m 'Ignore what we need to ignore'"
# Remove the other static files
run 'rm Gemfile'
run 'rm public/index.html'
run 'rm public/favicon.ico'
run 'rm public/images/rails.png'
run 'rm -f public/javascripts/*'
# Add the base system
git :add => "."
git :commit => "-a -m 'Initial commit of clean Rails #{RailsVersion} App'"
############################################################
# Setup Gemfile and RVM
#
file "Gemfile", <<-END
source :rubygems
gem "rails", "#{RailsVersion}"
gem "pg"
gem "sass"
gem "hoptoad_notifier"
gem "devise"
gem "simple_form"
gem "jquery-rails"
gem 'unicorn'
gem "app"
group :development, :test do
gem "rspec-rails"
gem 'capybara'
gem 'database_cleaner'
gem "launchy"
gem "cucumber-rails"
gem "autotest-rails"
gem "shoulda"
gem "machinist"
gem "faker"
end
END
# Bundle install
run "gem install bundler"
run "bundle install"
git :add => "."
git :commit => "-a -m 'Gemset created and bundle installed'"
############################################################
# Database and create
#
# Remove default database file
run 'rm config/database.yml'
# Use the only real database with database swapping per branch
file "config/database.yml", <<-END
development: &DEVELOPMENT
adapter: postgresql
database: #{app_name}_development_<%= `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '').gsub(/\W/,'_') %>
encoding: unicode
pool: 15
username: postgres
password:
test: &TEST
adapter: postgresql
database: #{app_name}_test_<%= `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '').gsub(/\W/,'_') %>
encoding: unicode
pool: 15
username: postgres
password:
cucumber:
<<: *TEST
END
environment " config.time_zone = 'UTC'"
# Make a copy to check in
run 'cp config/database.yml config/database.example.yml'
# Create the DB
rake("db:create")
git :add => "."
git :commit => "-a -m 'Setup Database'"
############################################################
# Install App Config
#
generate "configurable"
git :add => "."
git :commit => "-a -m 'Setup App Configurable'"
############################################################
# Install JQuery
#
generate "jquery:install --ui"
git :add => "."
git :commit => "-a -m 'Installed JQuery'"
############################################################
# Install Reset CSS, SASS
#
# Download reset.css
get 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css', 'public/stylesheets/reset.css'
# Create the SASS directory
run 'mkdir public/stylesheets/sass'
run 'touch public/stylesheets/sass/layout.scss'
# Override stylesheet_link_tag :defaults
environment " config.action_view.stylesheet_expansions[:defaults] = ['reset', 'layout']"
# Sass config initializer
initializer('sass.rb') do
<<-END
# SASS config
Sass::Plugin.options[:style] = :compressed
Sass::Plugin.options[:template_location] = {}
Dir.glob("\#{Rails.root}/public/stylesheets/**/sass").each { |dir| Sass::Plugin.options[:template_location].merge!({dir => dir.to_s.split('/sass')[0]}) }
END
end
git :add => "."
git :commit => "-am 'Installed Sass configuration'"
# Clean up layout
run 'rm app/views/layouts/application.html.erb'
file "app/views/layouts/application.html.erb", <<-END
<!DOCTYPE html>
<html>
<head>
<title><%= @title || "#{app_name.titleize}" %></title>
<%= stylesheet_link_tag :defaults %>
<%= csrf_meta_tag %>
<head>
<body class="<%= controller.controller_name %>">
<div id="Content">
<%= yield %>
</div>
<%= yield :before_javascript %>
<%= javascript_include_tag :defaults %>
<%= yield :after_javascript %>
</body>
<html>
END
git :add => "."
git :commit => "-am 'Updated application.html.erb, including javascripts and default styles'"
############################################################
# Remove test folder
#
git :rm => "-rf test"
git :commit => "-am 'Removing test folder'"
############################################################
# Generate RSpec and Cucumber
#
# Setup RSpec and Cucumber
generate "rspec:install"
generate "cucumber:install", "--rspec --capybara"
# Setup Machinist and Faker
run 'mkdir -p spec/support'
file 'spec/support/blueprints.rb', <<-END
require 'machinist/active_record'
require 'faker'
require 'sham'
Sham.email { Faker::Internet.email }
Sham.hostname { Faker::Internet.domain_name }
Sham.name { Faker::Name.name }
Sham.text { Faker::Lorem.sentence }
END
# doing { something }.should change(Something, :count).by(1)
file 'spec/support/custom.rb', <<-END
alias :doing :lambda
END
git :add => "."
git :commit => "-a -m 'Installed RSpec, Cucumber and Machinist'"
############################################################
# Setup base home controller and my/dashboard
#
# Setup home and dashboard
generate 'controller', 'home'
route("root :to => 'home#index'")
file 'app/views/home/index.html.erb', <<-END
<h1>Home</h1>
END
git :add => "."
git :commit => "-a -m 'Setup home controller and mapped root'"
############################################################
# Setup Additional Gems
#
# Setup Simple Form
generate "simple_form:install"
plugin 'country_select', :git => 'git://github.com/rails/country_select.git'
git :add => "."
git :commit => "-a -m 'Installed Simple Form'"
# Setup Devise
if ask("Setup Devise? (N/y)").upcase == 'Y'
generate "devise:install"
model_name = ask("What model name should devise use? (default: user)?")
model_name = 'user' if model_name.blank?
generate "devise", model_name
generate 'devise:views'
git :add => "."
git :commit => "-a -m 'Setup devise'"
else
say "=> Skipping Devise setup"
end
############################################################
# Setup Hoptoad and Google Analytics
#
# Setup HopToad
if ask("Setup Hoptoad? (N/y)").upcase == 'Y'
hop_toad_key = ask("Please provide HopToad API Key:")
generate "hoptoad", "--api-key #{hop_toad_key}"
git :add => "."
git :commit => "-a -m 'Installed HopToad'"
else
say "=> Skipping HopToad setup"
end
# Setup Google Analytics
if ask("Do you have Google Analytics key? (N/y)").upcase == 'Y'
ga_key = ask("Please provide your Google Analytics tracking key: (e.g UA-XXXXXX-XX)")
else
ga_key = nil
end
file "app/views/shared/_google_analytics.html.erb", <<-CODE
<script type="text/javascript" charset="utf-8">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '#{ga_key || "INSERT-URCHIN-CODE"}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
CODE
if ga_key
append_file "app/views/layouts/application.html.erb", <<-CODE
<%= render :partial => 'shared/google_analytics' %>
CODE
else
append_file "app/views/layouts/application.html.erb", <<-CODE
<%#= render :partial => 'shared/google_analytics' %>
CODE
end
git :add => "."
git :commit => "-am 'Added Google Analytics tracking code'"
# Setup TellThemWhen site support
if ask("Do you have a TellThemWhen Site Notification key? (N/y)").upcase == 'Y'
tellthemwhenkey = ask("Please provide your TellThemWhen tracking key: (e.g 1a2b3c4d5e6f)")
else
tellthemwhenkey = nil
end
file "app/views/shared/_tellthemwhen.html.erb", <<-CODE
<div id="TTWNotify" style="display:none;"></div>
<script type="text/javascript" charset="utf-8">
(function(){
t = document.createElement('script');t.async=true;t.type ='text/javascript';
t.src = ('https:' == document.location.protocol ? 'https://secure.' : 'http://api.') + 'tellthemwhen.com/api/v2/notices/#{tellthemwhenkey || "INSERT-TELLTHEMWHE-KEY"}.js';
var s=document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(t,s);
})();
</script>
CODE
if tellthemwhenkey
append_file "app/views/layouts/application.html.erb", <<-CODE
<%= render :partial => 'shared/tellthemwhen' %>
CODE
else
append_file "app/views/layouts/application.html.erb", <<-CODE
<%#= render :partial => 'shared/tellthemwhen' %>
CODE
end
git :add => "."
git :commit => "-am 'Added TellThemWhen Site Notification code'"
instructions =<<-END
Rails Template Install Complete
--------------------------------
All complete, please configure:
initializers/devise.rb
initializers/simple_form.rb
Also setup actionmailer in your production and development environments.
config.action_mailer.default_url_options = { :host => 'localhost:3000' } # dev + test
config.action_mailer.default_url_options = { :host => '#{app_name}.com' } # production
Then edit the db/migrate/TIMESTAMP_create_#{model_name}.rb file to suit and run
rake db:migrate
END
say(instructions)