onotole 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rubocop.yml +44 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +11 -0
  6. data/Gemfile +3 -0
  7. data/Guardfile +60 -0
  8. data/LICENSE +19 -0
  9. data/README.md +288 -0
  10. data/Rakefile +8 -0
  11. data/bin/onotole +35 -0
  12. data/bin/rake +16 -0
  13. data/bin/rspec +16 -0
  14. data/bin/setup +13 -0
  15. data/lib/onotole.rb +6 -0
  16. data/lib/onotole/actions.rb +33 -0
  17. data/lib/onotole/adapters/heroku.rb +125 -0
  18. data/lib/onotole/add_user_gems/after_install_patch.rb +119 -0
  19. data/lib/onotole/add_user_gems/before_bundle_patch.rb +137 -0
  20. data/lib/onotole/add_user_gems/edit_menu_questions.rb +80 -0
  21. data/lib/onotole/add_user_gems/user_gems_menu_questions.rb +17 -0
  22. data/lib/onotole/app_builder.rb +678 -0
  23. data/lib/onotole/colors.rb +20 -0
  24. data/lib/onotole/generators/app_generator.rb +299 -0
  25. data/lib/onotole/version.rb +6 -0
  26. data/onotole.gemspec +33 -0
  27. data/spec/adapters/heroku_spec.rb +52 -0
  28. data/spec/fakes/bin/heroku +5 -0
  29. data/spec/fakes/bin/hub +5 -0
  30. data/spec/features/github_spec.rb +15 -0
  31. data/spec/features/heroku_spec.rb +93 -0
  32. data/spec/features/new_project_spec.rb +204 -0
  33. data/spec/spec_helper.rb +20 -0
  34. data/spec/support/fake_github.rb +21 -0
  35. data/spec/support/fake_heroku.rb +51 -0
  36. data/spec/support/onotole.rb +59 -0
  37. data/templates/Gemfile.erb +61 -0
  38. data/templates/Procfile +2 -0
  39. data/templates/README.md.erb +30 -0
  40. data/templates/_analytics.html.erb +7 -0
  41. data/templates/_flashes.html.erb +7 -0
  42. data/templates/_javascript.html.erb +12 -0
  43. data/templates/action_mailer.rb +5 -0
  44. data/templates/app.json.erb +39 -0
  45. data/templates/application.scss +1 -0
  46. data/templates/bin_deploy +12 -0
  47. data/templates/bin_setup +21 -0
  48. data/templates/bin_setup_review_app.erb +19 -0
  49. data/templates/browserslist +4 -0
  50. data/templates/bundler_audit.rake +12 -0
  51. data/templates/capybara_webkit.rb +3 -0
  52. data/templates/circle.yml.erb +6 -0
  53. data/templates/config_locales_en.yml.erb +19 -0
  54. data/templates/database_cleaner_rspec.rb +22 -0
  55. data/templates/dev.rake +12 -0
  56. data/templates/devise_rspec.rb +3 -0
  57. data/templates/disable_xml_params.rb +1 -0
  58. data/templates/dotfiles/.ctags +2 -0
  59. data/templates/dotfiles/.env +13 -0
  60. data/templates/dotfiles/.rspec +3 -0
  61. data/templates/errors.rb +34 -0
  62. data/templates/factories.rb +2 -0
  63. data/templates/factory_girl_rspec.rb +3 -0
  64. data/templates/flashes_helper.rb +5 -0
  65. data/templates/gitignore_file +18 -0
  66. data/templates/hound.yml +17 -0
  67. data/templates/i18n.rb +3 -0
  68. data/templates/json_encoding.rb +1 -0
  69. data/templates/newrelic.yml.erb +34 -0
  70. data/templates/onotole_layout.html.erb.erb +21 -0
  71. data/templates/postgresql_database.yml.erb +22 -0
  72. data/templates/puma.rb +28 -0
  73. data/templates/rails_helper.rb +22 -0
  74. data/templates/rubocop.yml +44 -0
  75. data/templates/secrets.yml +14 -0
  76. data/templates/shoulda_matchers_config_rspec.rb +6 -0
  77. data/templates/smtp.rb +9 -0
  78. data/templates/spec_helper.rb +23 -0
  79. data/templates/staging.rb +5 -0
  80. data/templates/tinymce.yml +6 -0
  81. metadata +172 -0
@@ -0,0 +1,80 @@
1
+ module Onotole
2
+ module EditMenuQuestions
3
+ def choose_frontend
4
+ # do not forget add in def configure_simple_form new frameworks
5
+ variants = { none: 'No front-end framework',
6
+ bootstrap3_sass: 'Twitter bootstrap v.3 sass',
7
+ bootstrap3: 'Twitter bootstrap v.3 asset pipeline'
8
+ }
9
+ gem = choice 'Select front-end framework: ', variants
10
+ add_to_user_choise(gem) if gem
11
+ end
12
+
13
+ def choose_template_engine
14
+ variants = { none: 'Erb', slim: 'Slim', haml: 'Haml' }
15
+ gem = choice 'Select markup language: ', variants
16
+ add_to_user_choise(gem) if gem
17
+ end
18
+
19
+ def choose_authenticate_engine
20
+ variants = { none: 'None', devise: 'devise', devise_with_model: 'devise vs pre-installed model' }
21
+ gem = choice 'Select authenticate engine: ', variants
22
+ if gem == :devise_with_model
23
+ AppBuilder.devise_model = ask_stylish 'Enter devise model name:'
24
+ gem = :devise
25
+ end
26
+ add_to_user_choise(gem) if gem
27
+ end
28
+
29
+ def choose_undroup_gems
30
+ variants = { none: 'None',
31
+ will_paginate: 'Easy pagination implement',
32
+ rails_db: 'For pretty view in browser & xls export for models',
33
+ faker: 'Gem for generate fake data in testing',
34
+ rubocop: 'Code inspector and code formatting tool',
35
+ guard: 'Guard (with RSpec, livereload, rails, migrate, bundler)',
36
+ guard_rubocop: 'Auto-declare code miss in guard',
37
+ bundler_audit: 'Extra possibilities for gems version control',
38
+ airbrake: 'Airbrake error logging',
39
+ responders: 'A set of responders modules to dry up your Rails 4.2+ app.',
40
+ hirbunicode: 'Hirb unicode support',
41
+ dotenv_heroku: 'dotenv-heroku support',
42
+ tinymce: 'Integration of TinyMCE with the Rails asset pipeline',
43
+ meta_request: "Rails meta panel in chrome console. Very usefull in AJAX debugging.\n#{' ' * 24}Link for chrome add-on in Gemfile.\n#{' ' * 24}Do not delete comments if you need this link"
44
+ }
45
+ multiple_choice('Write numbers of all preferred gems.', variants).each do |gem|
46
+ add_to_user_choise gem
47
+ end
48
+ end
49
+
50
+ # template for yes/no question
51
+ #
52
+ # def supeawesome_gem
53
+ # gem_name = __callee__.to_s.gsub(/_gem$/, '')
54
+ # gem_description = 'Awesome gem description'
55
+ # add_to_user_choise( yes_no_question( gem_name,
56
+ # gem_description)) unless options[gem_name]
57
+ # end
58
+
59
+ def users_init_commit_choice
60
+ variants = { none: 'No', gitcommit: 'Yes' }
61
+ sel = choice 'Make init commit in the end? ', variants
62
+ add_to_user_choise(sel) unless sel == :none
63
+ end
64
+
65
+ def ask_cleanup_commens
66
+ unless options[:clean_comments]
67
+ variants = { none: 'No', clean_comments: 'Yes' }
68
+ sel = choice 'Delete comments in Gemfile, routes.rb & config files? ',
69
+ variants
70
+ add_to_user_choise(sel) unless sel == :none
71
+ end
72
+ end
73
+
74
+ def add_github_repo_creation_choice
75
+ variants = { none: 'No', create_github_repo: 'Yes' }
76
+ sel = choice "Create github repo #{app_name}?", variants
77
+ add_to_user_choise(sel) unless sel == :none
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,17 @@
1
+ module Onotole
2
+ module UserGemsMenu
3
+ def users_gems
4
+ choose_authenticate_engine
5
+ choose_template_engine
6
+ choose_frontend
7
+ # Placeholder for other gem additions
8
+ # menu description in add_gems_in_menu.rb
9
+
10
+ choose_undroup_gems
11
+ ask_cleanup_commens
12
+ users_init_commit_choice
13
+ add_github_repo_creation_choice
14
+ add_user_gems
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,678 @@
1
+ require 'forwardable'
2
+ require 'onotole/add_user_gems/user_gems_menu_questions'
3
+ require 'onotole/add_user_gems/edit_menu_questions'
4
+ require 'onotole/add_user_gems/before_bundle_patch'
5
+ require 'onotole/add_user_gems/after_install_patch'
6
+
7
+ module Onotole
8
+ class AppBuilder < Rails::AppBuilder
9
+ include Onotole::Actions
10
+ include Onotole::UserGemsMenu
11
+ include Onotole::EditMenuQuestions
12
+ include Onotole::BeforeBundlePatch
13
+ include Onotole::AfterInstallPatch
14
+ extend Forwardable
15
+
16
+ @use_asset_pipelline = true
17
+ @user_choice = []
18
+ @app_file_scss = 'app/assets/stylesheets/application.scss'
19
+ @app_file_css = 'app/assets/stylesheets/application.css'
20
+ @js_file = 'app/assets/javascripts/application.js'
21
+
22
+ class << self
23
+ attr_accessor :use_asset_pipelline,
24
+ :devise_model,
25
+ :user_choice, :app_file_scss, :app_file_css, :js_file
26
+ end
27
+
28
+ def_delegators :heroku_adapter,
29
+ :create_heroku_pipelines_config_file,
30
+ :create_heroku_pipeline,
31
+ :create_production_heroku_app,
32
+ :create_staging_heroku_app,
33
+ :provide_review_apps_setup_script,
34
+ :set_heroku_rails_secrets,
35
+ :set_heroku_remotes,
36
+ :set_heroku_serve_static_files,
37
+ :set_up_heroku_specific_gems
38
+
39
+ def readme
40
+ template 'README.md.erb', 'README.md'
41
+ end
42
+
43
+ def raise_on_missing_assets_in_test
44
+ inject_into_file(
45
+ 'config/environments/test.rb',
46
+ "\n config.assets.raise_runtime_errors = true",
47
+ after: 'Rails.application.configure do'
48
+ )
49
+ end
50
+
51
+ def raise_on_delivery_errors
52
+ replace_in_file 'config/environments/development.rb',
53
+ 'raise_delivery_errors = false', 'raise_delivery_errors = true'
54
+ end
55
+
56
+ def set_test_delivery_method
57
+ inject_into_file(
58
+ 'config/environments/development.rb',
59
+ "\n config.action_mailer.delivery_method = :test",
60
+ after: 'config.action_mailer.raise_delivery_errors = true'
61
+ )
62
+ end
63
+
64
+ def add_bullet_gem_configuration
65
+ config = <<-RUBY
66
+ config.after_initialize do
67
+ Bullet.enable = true
68
+ Bullet.bullet_logger = true
69
+ Bullet.rails_logger = true
70
+ end
71
+
72
+ RUBY
73
+
74
+ inject_into_file(
75
+ 'config/environments/development.rb',
76
+ config,
77
+ after: "config.action_mailer.raise_delivery_errors = true\n"
78
+ )
79
+ end
80
+
81
+ def raise_on_unpermitted_parameters
82
+ config = "\n config.action_controller.action_on_unpermitted_parameters = :raise\n"
83
+ inject_into_class 'config/application.rb', 'Application', config
84
+ end
85
+
86
+ def configure_quiet_assets
87
+ config = "\n config.quiet_assets = true\n"
88
+ inject_into_class 'config/application.rb', 'Application', config
89
+ end
90
+
91
+ def provide_setup_script
92
+ template 'bin_setup', 'bin/setup', force: true
93
+ run 'chmod a+x bin/setup'
94
+ end
95
+
96
+ def provide_dev_prime_task
97
+ copy_file 'dev.rake', 'lib/tasks/dev.rake'
98
+ end
99
+
100
+ def configure_generators
101
+ config = <<-RUBY
102
+
103
+ config.generators do |generate|
104
+ generate.helper false
105
+ generate.javascript_engine false
106
+ generate.request_specs false
107
+ generate.routing_specs false
108
+ generate.stylesheets false
109
+ generate.test_framework :rspec
110
+ generate.view_specs false
111
+ generate.fixture_replacement :factory_girl
112
+ end
113
+
114
+ RUBY
115
+
116
+ inject_into_class 'config/application.rb', 'Application', config
117
+ end
118
+
119
+ def set_up_factory_girl_for_rspec
120
+ copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
121
+ end
122
+
123
+ def generate_factories_file
124
+ copy_file 'factories.rb', 'spec/factories.rb'
125
+ end
126
+
127
+ def set_up_hound
128
+ copy_file 'hound.yml', '.hound.yml'
129
+ end
130
+
131
+ def configure_newrelic
132
+ template 'newrelic.yml.erb', 'config/newrelic.yml'
133
+ end
134
+
135
+ def configure_smtp
136
+ copy_file 'smtp.rb', 'config/smtp.rb'
137
+
138
+ prepend_file 'config/environments/production.rb',
139
+ %{require Rails.root.join("config/smtp")\n}
140
+
141
+ config = <<-RUBY
142
+
143
+ config.action_mailer.delivery_method = :smtp
144
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
145
+ RUBY
146
+
147
+ inject_into_file 'config/environments/production.rb', config,
148
+ after: 'config.action_mailer.raise_delivery_errors = false'
149
+ end
150
+
151
+ def enable_rack_canonical_host
152
+ config = <<-RUBY
153
+
154
+ if ENV.fetch("HEROKU_APP_NAME", "").include?("staging-pr-")
155
+ ENV["APPLICATION_HOST"] = ENV["HEROKU_APP_NAME"] + ".herokuapp.com"
156
+ end
157
+
158
+ # Ensure requests are only served from one, canonical host name
159
+ config.middleware.use Rack::CanonicalHost, ENV.fetch("APPLICATION_HOST")
160
+ RUBY
161
+
162
+ inject_into_file(
163
+ 'config/environments/production.rb',
164
+ config,
165
+ after: 'Rails.application.configure do'
166
+ )
167
+ end
168
+
169
+ def enable_rack_deflater
170
+ config = <<-RUBY
171
+
172
+ # Enable deflate / gzip compression of controller-generated responses
173
+ config.middleware.use Rack::Deflater
174
+ RUBY
175
+
176
+ inject_into_file(
177
+ 'config/environments/production.rb',
178
+ config,
179
+ after: serve_static_files_line
180
+ )
181
+ end
182
+
183
+ def setup_asset_host
184
+ replace_in_file 'config/environments/production.rb',
185
+ "# config.action_controller.asset_host = 'http://assets.example.com'",
186
+ 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))'
187
+
188
+ replace_in_file 'config/initializers/assets.rb',
189
+ "config.assets.version = '1.0'",
190
+ 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
191
+
192
+ inject_into_file(
193
+ 'config/environments/production.rb',
194
+ ' config.static_cache_control = "public, max-age=#{1.year.to_i}"',
195
+ after: serve_static_files_line
196
+ )
197
+ end
198
+
199
+ def setup_staging_environment
200
+ staging_file = 'config/environments/staging.rb'
201
+ copy_file 'staging.rb', staging_file
202
+
203
+ config = <<-RUBY
204
+
205
+ Rails.application.configure do
206
+ # ...
207
+ end
208
+ RUBY
209
+
210
+ append_file staging_file, config
211
+ end
212
+
213
+ def setup_secret_token
214
+ template 'secrets.yml', 'config/secrets.yml', force: true
215
+ end
216
+
217
+ def disallow_wrapping_parameters
218
+ remove_file 'config/initializers/wrap_parameters.rb'
219
+ end
220
+
221
+ def create_partials_directory
222
+ empty_directory 'app/views/application'
223
+ end
224
+
225
+ def create_shared_flashes
226
+ copy_file '_flashes.html.erb',
227
+ 'app/views/application/_flashes.html.erb'
228
+ copy_file 'flashes_helper.rb',
229
+ 'app/helpers/flashes_helper.rb'
230
+ end
231
+
232
+ def create_shared_javascripts
233
+ copy_file '_javascript.html.erb',
234
+ 'app/views/application/_javascript.html.erb'
235
+ end
236
+
237
+ def create_application_layout
238
+ template 'onotole_layout.html.erb.erb',
239
+ 'app/views/layouts/application.html.erb',
240
+ force: true
241
+ end
242
+
243
+ def use_postgres_config_template
244
+ template 'postgresql_database.yml.erb', 'config/database.yml',
245
+ force: true
246
+ template 'postgresql_database.yml.erb', 'config/database.yml.sample',
247
+ force: true
248
+ end
249
+
250
+ def create_database
251
+ bundle_command 'exec rake db:drop db:create db:migrate'
252
+ end
253
+
254
+ def replace_gemfile
255
+ remove_file 'Gemfile'
256
+ template 'Gemfile.erb', 'Gemfile'
257
+ end
258
+
259
+ def set_ruby_to_version_being_used
260
+ create_file '.ruby-version', "#{Onotole::RUBY_VERSION}\n"
261
+ end
262
+
263
+ def enable_database_cleaner
264
+ copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
265
+ end
266
+
267
+ def provide_shoulda_matchers_config
268
+ copy_file(
269
+ 'shoulda_matchers_config_rspec.rb',
270
+ 'spec/support/shoulda_matchers.rb'
271
+ )
272
+ end
273
+
274
+ def configure_spec_support_features
275
+ empty_directory_with_keep_file 'spec/features'
276
+ empty_directory_with_keep_file 'spec/support/features'
277
+ end
278
+
279
+ def configure_rspec
280
+ remove_file 'spec/rails_helper.rb'
281
+ remove_file 'spec/spec_helper.rb'
282
+ copy_file 'rails_helper.rb', 'spec/rails_helper.rb'
283
+ copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
284
+ end
285
+
286
+ def configure_ci
287
+ template 'circle.yml.erb', 'circle.yml'
288
+ end
289
+
290
+ def configure_i18n_for_test_environment
291
+ copy_file 'i18n.rb', 'spec/support/i18n.rb'
292
+ end
293
+
294
+ def configure_i18n_for_missing_translations
295
+ raise_on_missing_translations_in('development')
296
+ raise_on_missing_translations_in('test')
297
+ end
298
+
299
+ def configure_background_jobs_for_rspec
300
+ generate 'delayed_job:active_record'
301
+ end
302
+
303
+ def configure_action_mailer_in_specs
304
+ copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
305
+ end
306
+
307
+ def configure_capybara_webkit
308
+ copy_file 'capybara_webkit.rb', 'spec/support/capybara_webkit.rb'
309
+ end
310
+
311
+ def configure_time_formats
312
+ remove_file 'config/locales/en.yml'
313
+ template 'config_locales_en.yml.erb', 'config/locales/en.yml'
314
+ end
315
+
316
+ def configure_rack_timeout
317
+ rack_timeout_config = 'Rack::Timeout.timeout = (ENV["RACK_TIMEOUT"] || 10).to_i'
318
+ append_file 'config/environments/production.rb', rack_timeout_config
319
+ end
320
+
321
+ def configure_simple_form
322
+ if user_choose?(:bootstrap3_sass) || user_choose?(:bootstrap3)
323
+ bundle_command 'exec rails generate simple_form:install --bootstrap'
324
+ else
325
+ bundle_command 'exec rails generate simple_form:install'
326
+ end
327
+ end
328
+
329
+ def configure_action_mailer
330
+ action_mailer_host 'development', %("localhost:3000")
331
+ action_mailer_host 'test', %("www.example.com")
332
+ action_mailer_host 'production', %{ENV.fetch("APPLICATION_HOST")}
333
+ end
334
+
335
+ def configure_active_job
336
+ configure_application_file(
337
+ 'config.active_job.queue_adapter = :delayed_job'
338
+ )
339
+ configure_environment 'test', 'config.active_job.queue_adapter = :inline'
340
+ end
341
+
342
+ def fix_i18n_deprecation_warning
343
+ config = ' config.i18n.enforce_available_locales = true'
344
+ inject_into_class 'config/application.rb', 'Application', config
345
+ end
346
+
347
+ def generate_rspec
348
+ generate 'rspec:install'
349
+ end
350
+
351
+ def configure_puma
352
+ copy_file 'puma.rb', 'config/puma.rb'
353
+ end
354
+
355
+ def set_up_forego
356
+ copy_file 'Procfile', 'Procfile'
357
+ end
358
+
359
+ def setup_stylesheets
360
+ remove_file 'app/assets/stylesheets/application.css'
361
+ copy_file 'application.scss',
362
+ 'app/assets/stylesheets/application.scss'
363
+ end
364
+
365
+ def install_refills
366
+ generate 'refills:import flashes'
367
+ run 'rm app/views/refills/_flashes.html.erb'
368
+ run 'rmdir app/views/refills'
369
+ end
370
+
371
+ def install_bitters
372
+ run 'bitters install --path app/assets/stylesheets'
373
+ end
374
+
375
+ def gitignore_files
376
+ remove_file '.gitignore'
377
+ copy_file 'gitignore_file', '.gitignore'
378
+ [
379
+ 'app/views/pages',
380
+ 'spec/lib',
381
+ 'spec/controllers',
382
+ 'spec/helpers',
383
+ 'spec/support/matchers',
384
+ 'spec/support/mixins',
385
+ 'spec/support/shared_examples'
386
+ ].each do |dir|
387
+ run "mkdir #{dir}"
388
+ run "touch #{dir}/.keep"
389
+ end
390
+ end
391
+
392
+ def copy_dotfiles
393
+ directory 'dotfiles', '.', force: true
394
+ end
395
+
396
+ def init_git
397
+ run 'git init'
398
+ end
399
+
400
+ def git_init_commit
401
+ if user_choose?(:gitcommit)
402
+ say 'Init commit'
403
+ run 'git add .'
404
+ run 'git commit -m "Init commit"'
405
+ end
406
+ end
407
+
408
+ def create_heroku_apps(flags)
409
+ create_staging_heroku_app(flags)
410
+ create_production_heroku_app(flags)
411
+ end
412
+
413
+ def provide_deploy_script
414
+ copy_file 'bin_deploy', 'bin/deploy'
415
+
416
+ instructions = <<-MARKDOWN
417
+
418
+ ## Deploying
419
+
420
+ If you have previously run the `./bin/setup` script,
421
+ you can deploy to staging and production with:
422
+
423
+ $ ./bin/deploy staging
424
+ $ ./bin/deploy production
425
+ MARKDOWN
426
+
427
+ append_file 'README.md', instructions
428
+ run 'chmod a+x bin/deploy'
429
+ end
430
+
431
+ def configure_automatic_deployment
432
+ deploy_command = <<-YML.strip_heredoc
433
+ deployment:
434
+ staging:
435
+ branch: master
436
+ commands:
437
+ - bin/deploy staging
438
+ YML
439
+
440
+ append_file 'circle.yml', deploy_command
441
+ end
442
+
443
+ def create_github_repo(repo_name)
444
+ system "hub create #{repo_name}"
445
+ end
446
+
447
+ def setup_segment
448
+ copy_file '_analytics.html.erb',
449
+ 'app/views/application/_analytics.html.erb'
450
+ end
451
+
452
+ def setup_spring
453
+ bundle_command 'exec spring binstub --all'
454
+ run 'spring stop'
455
+ end
456
+
457
+ def copy_miscellaneous_files
458
+ copy_file 'browserslist', 'browserslist'
459
+ copy_file 'errors.rb', 'config/initializers/errors.rb'
460
+ copy_file 'json_encoding.rb', 'config/initializers/json_encoding.rb'
461
+ end
462
+
463
+ def customize_error_pages
464
+ meta_tags = <<-EOS
465
+ <meta charset="utf-8" />
466
+ <meta name="ROBOTS" content="NOODP" />
467
+ <meta name="viewport" content="initial-scale=1" />
468
+ EOS
469
+
470
+ %w(500 404 422).each do |page|
471
+ inject_into_file "public/#{page}.html", meta_tags, after: "<head>\n"
472
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
473
+ end
474
+ end
475
+
476
+ def remove_config_comment_lines
477
+ config_files = [
478
+ 'application.rb',
479
+ 'environment.rb',
480
+ 'environments/development.rb',
481
+ 'environments/production.rb',
482
+ 'environments/test.rb'
483
+ ]
484
+
485
+ config_files.each do |config_file|
486
+ cleanup_comments File.join(destination_root, "config/#{config_file}")
487
+ end
488
+ end
489
+
490
+ def remove_routes_comment_lines
491
+ replace_in_file 'config/routes.rb',
492
+ /Rails\.application\.routes\.draw do.*end/m,
493
+ "Rails.application.routes.draw do\nend"
494
+ end
495
+
496
+ def disable_xml_params
497
+ copy_file 'disable_xml_params.rb',
498
+ 'config/initializers/disable_xml_params.rb'
499
+ end
500
+
501
+ def setup_default_rake_task
502
+ append_file 'Rakefile' do
503
+ <<-EOS
504
+ task(:default).clear
505
+ task default: [:spec]
506
+
507
+ if defined? RSpec
508
+ task(:spec).clear
509
+ RSpec::Core::RakeTask.new(:spec) do |t|
510
+ t.verbose = false
511
+ end
512
+ end
513
+ EOS
514
+ end
515
+ end
516
+
517
+ def install_user_gems_from_github
518
+ File.readlines('Gemfile').each do |l|
519
+ possible_gem_name = l.match(/(?:github:\s+)(?:'|")\w+\/(.*)(?:'|")/i)
520
+ install_from_github possible_gem_name[1] if possible_gem_name
521
+ end
522
+ end
523
+
524
+ # def rvm_bundler_stubs_install
525
+ # if system "rvm -v | grep 'rvm.io'"
526
+ # run 'chmod +x $rvm_path/hooks/after_cd_bundler'
527
+ # run 'bundle install --binstubs=./bundler_stubs'
528
+ # end
529
+ # end
530
+
531
+ def user_gems_from_args_or_default_set
532
+ gems_flags = []
533
+ options.each { |k, v| gems_flags.push k.to_sym if v == true }
534
+ gems = GEMPROCLIST & gems_flags
535
+ if gems.empty?
536
+ AppBuilder.user_choice = DEFAULT_GEMSET
537
+ else
538
+ gems.each { |g| AppBuilder.user_choice << g }
539
+ end
540
+ add_user_gems
541
+ end
542
+
543
+ def show_goodbye_message
544
+ say_color BOLDGREEN, "Congratulations! Onotole gives you: 'Intellect+= 1'"
545
+ say_color BOLDGREEN, "You can 'git push -u origin master' to your new repo
546
+ #{app_name} or check log for errors"
547
+ if user_choose? :create_github_repo
548
+ say_color YELLOW, "Remember to run 'rails generate airbrake' with your API key." if user_choose? :airbrake
549
+ end
550
+
551
+ private
552
+
553
+ def yes_no_question(gem_name, gem_description)
554
+ gem_name_color = "#{gem_name.capitalize}.\n"
555
+ variants = { none: 'No', gem_name.to_sym => gem_name_color }
556
+ choice "Use #{gem_name}? #{gem_description}", variants
557
+ end
558
+
559
+ def choice(selector, variants)
560
+ unless variants.keys[1..-1].map { |a| options[a] }.include? true
561
+ values = []
562
+ say "\n #{BOLDGREEN}#{selector}#{COLOR_OFF}"
563
+ variants.each_with_index do |variant, i|
564
+ values.push variant[0]
565
+ say "#{i.to_s.rjust(5)}. #{BOLDBLUE}#{variant[1]}#{COLOR_OFF}"
566
+ end
567
+ answer = ask_stylish('Enter choice:') until (0...variants.length)
568
+ .map(&:to_s).include? answer
569
+ values[answer.to_i] == :none ? nil : values[answer.to_i]
570
+ end
571
+ end
572
+
573
+ def multiple_choice(selector, variants)
574
+ values = []
575
+ result = []
576
+ answers = ''
577
+ say "\n #{BOLDGREEN}#{selector} Use space as separator#{COLOR_OFF}"
578
+ variants.each_with_index do |variant, i|
579
+ values.push variant[0]
580
+ say "#{i.to_s.rjust(5)}. #{BOLDBLUE}#{variant[0]
581
+ .to_s.ljust(15)}-#{COLOR_OFF} #{variant[1]}"
582
+ end
583
+ loop do
584
+ answers = ask_stylish('Enter choices:').split ' '
585
+ break if answers.any? && (answers - (0...variants.length)
586
+ .to_a.map(&:to_s)).empty?
587
+ end
588
+ answers.delete '0'
589
+ answers.uniq.each { |a| result.push values[a.to_i] }
590
+ result
591
+ end
592
+
593
+ def ask_stylish(str)
594
+ ask "#{BOLDGREEN} #{str} #{COLOR_OFF}".rjust(10)
595
+ end
596
+
597
+ def say_color(color, str)
598
+ say "#{color}#{str}#{COLOR_OFF}".rjust(4)
599
+ end
600
+
601
+ def raise_on_missing_translations_in(environment)
602
+ config = 'config.action_view.raise_on_missing_translations = true'
603
+ uncomment_lines("config/environments/#{environment}.rb", config)
604
+ end
605
+
606
+ def heroku_adapter
607
+ @heroku_adapter ||= Adapters::Heroku.new(self)
608
+ end
609
+
610
+ def serve_static_files_line
611
+ "config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?\n"
612
+ end
613
+
614
+ def add_gems_from_args
615
+ ARGV.each do |g|
616
+ next unless g[0] == '-' && g[1] == '-'
617
+ add_to_user_choise g[2..-1].to_sym
618
+ end
619
+ end
620
+
621
+ def cleanup_comments(file)
622
+ accepted_content = File.readlines(file).reject do |line|
623
+ line =~ /^\s*#.*$/ || line =~ /^$\n/
624
+ end
625
+
626
+ File.open(file, 'w') do |f|
627
+ accepted_content.each { |line| f.puts line }
628
+ end
629
+ end
630
+
631
+ def delete_comments
632
+ if options[:clean_comments] || user_choose?(:clean_comments)
633
+ cleanup_comments 'Gemfile'
634
+ remove_config_comment_lines
635
+ remove_routes_comment_lines
636
+ end
637
+ end
638
+
639
+ # does not recognize variable nesting, but now it does not matter
640
+ def cover_def_by(file, lookup_str, external_def)
641
+ expect_end = 0
642
+ found = false
643
+ accepted_content = ''
644
+ File.readlines(file).each do |line|
645
+ expect_end += 1 if found && line =~ /\sdo\s/
646
+ expect_end -= 1 if found && line =~ /(\s+end|^end)/
647
+ if line =~ Regexp.new(lookup_str)
648
+ accepted_content += "#{external_def}\n#{line}"
649
+ expect_end += 1
650
+ found = true
651
+ else
652
+ accepted_content += line
653
+ end
654
+ if found && expect_end == 0
655
+ accepted_content += "\nend"
656
+ found = false
657
+ end
658
+ end
659
+ File.open(file, 'w') do |f|
660
+ f.puts accepted_content
661
+ end
662
+ end
663
+
664
+ def install_from_github(gem_name)
665
+ return nil unless gem_name
666
+ path = `bundle list #{gem_name}`.chomp
667
+ run "cd #{path} && gem build #{gem_name}.gemspec && gem install #{gem_name}"
668
+ end
669
+
670
+ def user_choose?(g)
671
+ AppBuilder.user_choice.include? g
672
+ end
673
+
674
+ def add_to_user_choise(g)
675
+ AppBuilder.user_choice.push g
676
+ end
677
+ end
678
+ end