welaika-suspenders 1.4.0 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -7
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +7 -2
  5. data/CONTRIBUTING.md +24 -26
  6. data/Gemfile.lock +94 -69
  7. data/NEWS.md +183 -0
  8. data/README.md +21 -127
  9. data/Rakefile +3 -3
  10. data/bin/rake +16 -0
  11. data/bin/rspec +16 -0
  12. data/bin/setup +13 -0
  13. data/bin/welaika-suspenders +8 -11
  14. data/lib/{welaika_suspenders → suspenders}/actions.rb +1 -16
  15. data/lib/suspenders/app_builder.rb +424 -0
  16. data/lib/{welaika_suspenders → suspenders}/generators/app_generator.rb +50 -54
  17. data/lib/suspenders/version.rb +5 -0
  18. data/lib/suspenders.rb +4 -0
  19. data/{features/support → spec/fakes}/bin/heroku +0 -0
  20. data/{features/support → spec/fakes}/bin/hub +0 -0
  21. data/spec/features/github_spec.rb +10 -0
  22. data/spec/features/heroku_spec.rb +19 -0
  23. data/spec/features/new_project_spec.rb +115 -0
  24. data/spec/spec_helper.rb +24 -0
  25. data/{features → spec}/support/fake_github.rb +1 -1
  26. data/spec/support/fake_heroku.rb +38 -0
  27. data/spec/support/suspenders.rb +49 -0
  28. data/suspenders.gemspec +36 -0
  29. data/templates/Gemfile.erb +58 -0
  30. data/templates/Procfile +1 -2
  31. data/templates/README.md.erb +28 -2
  32. data/templates/_flashes.html.slim +4 -3
  33. data/templates/_javascript.html.slim +3 -0
  34. data/templates/action_mailer.rb +5 -0
  35. data/templates/application.css.scss +3 -4
  36. data/templates/bin_setup.erb +34 -0
  37. data/templates/config_i18n_tasks.yml +13 -0
  38. data/templates/config_locales_en.yml.erb +19 -0
  39. data/templates/database_cleaner_rspec.rb +1 -4
  40. data/templates/development_seeds.rb +12 -0
  41. data/templates/errors.rb +22 -16
  42. data/templates/{factory_girl_syntax_rspec.rb → factory_girl_rspec.rb} +0 -0
  43. data/templates/i18n.rb +3 -0
  44. data/templates/newrelic.yml.erb +34 -0
  45. data/templates/postgresql_database.yml.erb +1 -1
  46. data/templates/rack_timeout.rb +1 -1
  47. data/templates/rails_helper.rb +23 -0
  48. data/templates/sample.env +1 -12
  49. data/templates/secrets.yml +14 -0
  50. data/templates/smtp.rb +9 -10
  51. data/templates/spec_helper.rb +16 -0
  52. data/templates/staging.rb +5 -0
  53. data/templates/suspenders_gitignore +10 -9
  54. data/templates/suspenders_layout.html.slim +14 -0
  55. data/templates/travis.yml.erb +24 -0
  56. data/templates/unicorn.rb +12 -9
  57. metadata +100 -80
  58. data/.DS_Store +0 -0
  59. data/features/github_repo.feature +0 -8
  60. data/features/heroku_true.feature +0 -9
  61. data/features/rake_clean.feature +0 -15
  62. data/features/step_definitions/suspenders_steps.rb +0 -69
  63. data/features/support/env.rb +0 -10
  64. data/features/support/fake_heroku.rb +0 -21
  65. data/lib/welaika_suspenders/app_builder.rb +0 -318
  66. data/lib/welaika_suspenders/version.rb +0 -4
  67. data/lib/welaika_suspenders/version_check.rb +0 -26
  68. data/templates/.DS_Store +0 -0
  69. data/templates/Gemfile_clean +0 -56
  70. data/templates/bin_setup +0 -11
  71. data/templates/capybara_selectors.rb +0 -29
  72. data/templates/config_locales_en.yml +0 -11
  73. data/templates/create_dragonfly_jobs.rb +0 -9
  74. data/templates/dragonfly.rb +0 -9
  75. data/templates/dragonfly_initializer.rb +0 -47
  76. data/templates/exist_in_db.rb +0 -6
  77. data/templates/factories_spec.rb +0 -14
  78. data/templates/factories_spec_rake_task.rb +0 -9
  79. data/templates/import_common_javascripts +0 -4
  80. data/templates/model_spec_helper.rb +0 -38
  81. data/templates/presenters.rb +0 -3
  82. data/templates/rails_root_definition.rb +0 -2
  83. data/templates/rspec +0 -2
  84. data/templates/rspec_config.rb +0 -16
  85. data/templates/simplecov_init.rb +0 -3
  86. data/templates/suspenders_layout.html.slim.erb +0 -12
  87. data/templates/unit_spec_helper.rb +0 -15
  88. data/welaika-suspenders.gemspec +0 -35
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/setup ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # Run this script immediately after cloning the codebase.
4
+
5
+ # Exit if any subcommand fails
6
+ set -e
7
+
8
+ # Set up Ruby dependencies via Bundler
9
+ bundle install
10
+
11
+ # Add binstubs to PATH in ~/.zshenv like this:
12
+ # export PATH=".git/safe/../../bin:$PATH"
13
+ mkdir -p .git/safe
@@ -1,21 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'pathname'
2
3
 
3
- root = File.expand_path('../../lib', __FILE__)
4
- $LOAD_PATH.unshift(root) unless $LOAD_PATH.include?(root)
4
+ source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
+ $LOAD_PATH << source_path
5
6
 
6
- require 'welaika_suspenders/generators/app_generator'
7
- require 'welaika_suspenders/actions'
8
- require 'welaika_suspenders/app_builder'
9
- require 'welaika_suspenders/version_check'
7
+ require 'suspenders'
10
8
 
11
9
  if ['create', '--create'].include? ARGV[0]
12
10
  ARGV.shift
13
- puts "[WARNING] the welaika-suspenders create argument is deprecated. Just use `suspenders #{ARGV.join}` instead"
11
+ puts "[WARNING] the suspenders create argument is deprecated. Just use `suspenders #{ARGV.join}` instead"
14
12
  end
15
13
 
16
14
  templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
17
- WelaikaSuspenders::AppGenerator.source_root templates_root
18
- WelaikaSuspenders::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
15
+ Suspenders::AppGenerator.source_root templates_root
16
+ Suspenders::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
19
17
 
20
- WelaikaSuspenders::VersionCheck.check_if_up_to_date!
21
- WelaikaSuspenders::AppGenerator.start
18
+ Suspenders::AppGenerator.start
@@ -1,10 +1,5 @@
1
- module WelaikaSuspenders
1
+ module Suspenders
2
2
  module Actions
3
- def concat_file(source, destination)
4
- contents = IO.read(find_in_source_paths(source))
5
- append_file destination, contents
6
- end
7
-
8
3
  def replace_in_file(relative_path, find, replace)
9
4
  path = File.join(destination_root, relative_path)
10
5
  contents = IO.read(path)
@@ -26,15 +21,5 @@ module WelaikaSuspenders
26
21
  before: "\nend"
27
22
  )
28
23
  end
29
-
30
- def download_file(uri_string, destination)
31
- uri = URI.parse(uri_string)
32
- http = Net::HTTP.new(uri.host, uri.port)
33
- http.use_ssl = true if uri_string =~ /^https/
34
- request = Net::HTTP::Get.new(uri.path)
35
- contents = http.request(request).body
36
- path = File.join(destination_root, destination)
37
- File.open(path, "w") { |file| file.write(contents) }
38
- end
39
24
  end
40
25
  end
@@ -0,0 +1,424 @@
1
+ module Suspenders
2
+ class AppBuilder < Rails::AppBuilder
3
+ include Suspenders::Actions
4
+
5
+ def readme
6
+ template 'README.md.erb', 'README.md'
7
+ end
8
+
9
+ def raise_on_delivery_errors
10
+ replace_in_file 'config/environments/development.rb',
11
+ 'raise_delivery_errors = false', 'raise_delivery_errors = true'
12
+ end
13
+
14
+ def configure_letter_opener
15
+ config = <<-RUBY
16
+
17
+ config.action_mailer.delivery_method = :letter_opener
18
+ RUBY
19
+
20
+ # this method must be called after `raise_on_delivery_errors`
21
+ # because the `after` clause search for `raise_delivery_errors = true`
22
+ inject_into_file 'config/environments/development.rb', config,
23
+ :after => 'config.action_mailer.raise_delivery_errors = true'
24
+ end
25
+
26
+ def raise_on_unpermitted_parameters
27
+ config = <<-RUBY
28
+ config.action_controller.action_on_unpermitted_parameters = :raise
29
+ RUBY
30
+
31
+ inject_into_class "config/application.rb", "Application", config
32
+ end
33
+
34
+ def provide_setup_script
35
+ template 'bin_setup.erb', 'bin/setup', port_number: port_number
36
+ run 'chmod a+x bin/setup'
37
+ end
38
+
39
+ def provide_dev_prime_task
40
+ copy_file 'development_seeds.rb', 'lib/tasks/development_seeds.rake'
41
+ end
42
+
43
+ def configure_generators
44
+ config = <<-RUBY
45
+
46
+ config.generators do |generate|
47
+ generate.helper false
48
+ generate.javascript_engine false
49
+ generate.request_specs false
50
+ generate.routing_specs false
51
+ generate.stylesheets false
52
+ generate.test_framework :rspec
53
+ generate.view_specs false
54
+ end
55
+
56
+ RUBY
57
+
58
+ inject_into_class 'config/application.rb', 'Application', config
59
+ end
60
+
61
+ def set_up_factory_girl_for_rspec
62
+ copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
63
+ end
64
+
65
+ def configure_newrelic
66
+ template 'newrelic.yml.erb', 'config/newrelic.yml'
67
+ end
68
+
69
+ def configure_smtp
70
+ copy_file 'smtp.rb', 'config/smtp.rb'
71
+
72
+ prepend_file 'config/environments/production.rb',
73
+ %{require Rails.root.join("config/smtp")\n}
74
+
75
+ config = <<-RUBY
76
+
77
+ config.action_mailer.delivery_method = :smtp
78
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
79
+ RUBY
80
+
81
+ inject_into_file 'config/environments/production.rb', config,
82
+ :after => 'config.action_mailer.raise_delivery_errors = false'
83
+ end
84
+
85
+ def enable_rack_deflater
86
+ config = <<-RUBY
87
+
88
+ # Enable deflate / gzip compression of controller-generated responses
89
+ config.middleware.use Rack::Deflater
90
+ RUBY
91
+
92
+ inject_into_file 'config/environments/production.rb', config,
93
+ :after => "config.serve_static_assets = false\n"
94
+ end
95
+
96
+ def setup_asset_host
97
+ replace_in_file 'config/environments/production.rb',
98
+ '# config.action_controller.asset_host = "http://assets.example.com"',
99
+ 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST")'
100
+
101
+ replace_in_file 'config/initializers/assets.rb',
102
+ "config.assets.version = '1.0'",
103
+ 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
104
+
105
+ replace_in_file 'config/environments/production.rb',
106
+ 'config.serve_static_assets = false',
107
+ 'config.static_cache_control = "public, max-age=#{1.year.to_i}"'
108
+ end
109
+
110
+ def setup_staging_environment
111
+ staging_file = 'config/environments/staging.rb'
112
+ copy_file 'staging.rb', staging_file
113
+
114
+ config = <<-RUBY
115
+
116
+ Rails.application.configure do
117
+ # ...
118
+ end
119
+ RUBY
120
+
121
+ append_file staging_file, config
122
+ end
123
+
124
+ def setup_secret_token
125
+ template 'secrets.yml', 'config/secrets.yml', force: true
126
+ end
127
+
128
+ def create_partials_directory
129
+ empty_directory 'app/views/application'
130
+ end
131
+
132
+ def create_shared_flashes
133
+ copy_file '_flashes.html.slim', 'app/views/application/_flashes.html.slim'
134
+ end
135
+
136
+ def create_shared_javascripts
137
+ copy_file '_javascript.html.slim', 'app/views/application/_javascript.html.slim'
138
+ end
139
+
140
+ def create_application_layout
141
+ remove_file 'app/views/layouts/application.html.erb'
142
+ template 'suspenders_layout.html.slim',
143
+ 'app/views/layouts/application.html.slim',
144
+ force: true
145
+ end
146
+
147
+ def remove_turbolinks
148
+ replace_in_file 'app/assets/javascripts/application.js',
149
+ /\/\/= require turbolinks\n/,
150
+ ''
151
+ end
152
+
153
+ def use_postgres_config_template
154
+ template 'postgresql_database.yml.erb', 'config/database.yml',
155
+ force: true
156
+ end
157
+
158
+ def create_database
159
+ bundle_command 'exec rake db:create db:migrate'
160
+ end
161
+
162
+ def replace_gemfile
163
+ remove_file 'Gemfile'
164
+ template 'Gemfile.erb', 'Gemfile'
165
+ end
166
+
167
+ def set_ruby_to_version_being_used
168
+ create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n"
169
+ end
170
+
171
+ def setup_heroku_specific_gems
172
+ inject_into_file 'Gemfile', "\n\s\sgem 'rails_12factor'",
173
+ after: /group :staging, :production do/
174
+ end
175
+
176
+ def enable_database_cleaner
177
+ copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
178
+ end
179
+
180
+ def configure_spec_support_features
181
+ empty_directory_with_keep_file 'spec/features'
182
+ empty_directory_with_keep_file 'spec/support/features'
183
+ end
184
+
185
+ def configure_rspec
186
+ remove_file "spec/rails_helper.rb"
187
+ remove_file "spec/spec_helper.rb"
188
+ copy_file "rails_helper.rb", "spec/rails_helper.rb"
189
+ copy_file "spec_helper.rb", "spec/spec_helper.rb"
190
+ end
191
+
192
+ def configure_travis
193
+ template 'travis.yml.erb', '.travis.yml'
194
+ end
195
+
196
+ def configure_i18n_for_test_environment
197
+ copy_file "i18n.rb", "spec/support/i18n.rb"
198
+ end
199
+
200
+ def configure_i18n_for_missing_translations
201
+ raise_on_missing_translations_in("development")
202
+ raise_on_missing_translations_in("test")
203
+ end
204
+
205
+ def configure_i18n_tasks
206
+ run "cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/"
207
+ copy_file "config_i18n_tasks.yml", "config/i18n-tasks.yml"
208
+ end
209
+
210
+ def configure_background_jobs_for_rspec
211
+ copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb'
212
+ run 'rails g delayed_job:active_record'
213
+ end
214
+
215
+ def configure_action_mailer_in_specs
216
+ copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
217
+ end
218
+
219
+ def configure_time_zone
220
+ config = <<-RUBY
221
+ config.active_record.default_timezone = :utc
222
+ RUBY
223
+
224
+ inject_into_class 'config/application.rb', 'Application', config
225
+ end
226
+
227
+ def configure_time_formats
228
+ remove_file "config/locales/en.yml"
229
+ template "config_locales_en.yml.erb", "config/locales/en.yml"
230
+ end
231
+
232
+ def configure_rack_timeout
233
+ copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb'
234
+ end
235
+
236
+ def configure_action_mailer
237
+ action_mailer_host 'development', "localhost:#{port_number}"
238
+ action_mailer_host 'test', 'www.example.com'
239
+ action_mailer_host 'staging', "staging.#{app_name}.com"
240
+ action_mailer_host 'production', "#{app_name}.com"
241
+ end
242
+
243
+ def configure_available_locales
244
+ config = <<-RUBY
245
+ config.i18n.available_locales = [:en, :it]
246
+ RUBY
247
+
248
+ inject_into_class 'config/application.rb', 'Application', config
249
+ end
250
+
251
+ def fix_i18n_deprecation_warning
252
+ config = <<-RUBY
253
+ config.i18n.enforce_available_locales = true
254
+ RUBY
255
+
256
+ inject_into_class 'config/application.rb', 'Application', config
257
+ end
258
+
259
+ def generate_rspec
260
+ generate 'rspec:install'
261
+ end
262
+
263
+ def configure_unicorn
264
+ copy_file 'unicorn.rb', 'config/unicorn.rb'
265
+ end
266
+
267
+ def setup_foreman
268
+ copy_file 'sample.env', '.sample.env'
269
+ copy_file 'Procfile', 'Procfile'
270
+ end
271
+
272
+ def setup_stylesheets
273
+ remove_file 'app/assets/stylesheets/application.css'
274
+ copy_file 'application.css.scss',
275
+ 'app/assets/stylesheets/application.css.scss'
276
+ end
277
+
278
+ def install_bitters
279
+ run "bitters install --path app/assets/stylesheets"
280
+ end
281
+
282
+ def gitignore_files
283
+ remove_file '.gitignore'
284
+ copy_file 'suspenders_gitignore', '.gitignore'
285
+ [
286
+ 'app/views/pages',
287
+ 'spec/lib',
288
+ 'spec/controllers',
289
+ 'spec/helpers',
290
+ 'spec/support/matchers',
291
+ 'spec/support/mixins',
292
+ 'spec/support/shared_examples'
293
+ ].each do |dir|
294
+ run "mkdir #{dir}"
295
+ run "touch #{dir}/.keep"
296
+ end
297
+ end
298
+
299
+ def init_git
300
+ run 'git init'
301
+ end
302
+
303
+ def create_heroku_apps
304
+ run_heroku "create #{app_name}-production", "production"
305
+ run_heroku "create #{app_name}-staging", "staging"
306
+ run_heroku "config:add RACK_ENV=staging RAILS_ENV=staging", "staging"
307
+ end
308
+
309
+ def set_heroku_remotes
310
+ remotes = <<-SHELL
311
+
312
+ # Set up the staging and production apps.
313
+ #{join_heroku_app('staging')}
314
+ #{join_heroku_app('production')}
315
+ SHELL
316
+
317
+ append_file 'bin/setup', remotes
318
+ end
319
+
320
+ def join_heroku_app(environment)
321
+ heroku_app_name = "#{app_name}-#{environment}"
322
+ <<-SHELL
323
+ if heroku join --app #{heroku_app_name} &> /dev/null; then
324
+ git remote add #{environment} git@heroku.com:#{heroku_app_name}.git || true
325
+ printf 'You are a collaborator on the "#{heroku_app_name}" Heroku app\n'
326
+ else
327
+ printf 'Ask for access to the "#{heroku_app_name}" Heroku app\n'
328
+ fi
329
+ SHELL
330
+ end
331
+
332
+ def set_heroku_rails_secrets
333
+ %w(staging production).each do |environment|
334
+ run_heroku "config:add SECRET_KEY_BASE=#{generate_secret}", environment
335
+ end
336
+ end
337
+
338
+ def set_memory_management_variable
339
+ %w(staging production).each do |environment|
340
+ run_heroku "config:add NEW_RELIC_AGGRESSIVE_KEEPALIVE=1", environment
341
+ end
342
+ end
343
+
344
+ def create_github_repo(repo_name)
345
+ path_addition = override_path_for_tests
346
+ run "#{path_addition} hub create #{repo_name}"
347
+ end
348
+
349
+ def copy_miscellaneous_files
350
+ copy_file 'errors.rb', 'config/initializers/errors.rb'
351
+ end
352
+
353
+ def customize_error_pages
354
+ meta_tags =<<-EOS
355
+ <meta charset="utf-8" />
356
+ <meta name="ROBOTS" content="NOODP" />
357
+ <meta name="viewport" content="initial-scale=1" />
358
+ EOS
359
+
360
+ %w(500 404 422).each do |page|
361
+ inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
362
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
363
+ end
364
+ end
365
+
366
+ def remove_routes_comment_lines
367
+ replace_in_file 'config/routes.rb',
368
+ /Rails\.application\.routes\.draw do.*end/m,
369
+ "Rails.application.routes.draw do\nend"
370
+ end
371
+
372
+ def disable_xml_params
373
+ copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
374
+ end
375
+
376
+ def setup_default_rake_task
377
+ append_file 'Rakefile' do
378
+ <<-EOS
379
+ task(:default).clear
380
+ task default: [:spec]
381
+
382
+ if defined? RSpec
383
+ task(:spec).clear
384
+ RSpec::Core::RakeTask.new(:spec) do |t|
385
+ t.verbose = false
386
+ end
387
+ end
388
+ EOS
389
+ end
390
+ end
391
+
392
+ private
393
+
394
+ def raise_on_missing_translations_in(environment)
395
+ config = 'config.action_view.raise_on_missing_translations = true'
396
+
397
+ uncomment_lines("config/environments/#{environment}.rb", config)
398
+ end
399
+
400
+ def override_path_for_tests
401
+ if ENV['TESTING']
402
+ support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
403
+ "PATH=#{support_bin}:$PATH"
404
+ end
405
+ end
406
+
407
+ def run_heroku(command, environment)
408
+ path_addition = override_path_for_tests
409
+ run "#{path_addition} heroku #{command} --remote #{environment}"
410
+ end
411
+
412
+ def factories_spec_rake_task
413
+ IO.read find_in_source_paths('factories_spec_rake_task.rb')
414
+ end
415
+
416
+ def generate_secret
417
+ SecureRandom.hex(64)
418
+ end
419
+
420
+ def port_number
421
+ @port_number ||= [3000, 4000, 5000, 7000, 8000, 9000].sample
422
+ end
423
+ end
424
+ end