redmint_composer 2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +10 -0
  3. data/bin/redmint_composer +7 -0
  4. data/lib/rails_wizard.rb +7 -0
  5. data/lib/rails_wizard/command.rb +204 -0
  6. data/lib/rails_wizard/config.rb +88 -0
  7. data/lib/rails_wizard/diagnostics.rb +58 -0
  8. data/lib/rails_wizard/recipe.rb +114 -0
  9. data/lib/rails_wizard/recipes.rb +56 -0
  10. data/lib/rails_wizard/template.rb +111 -0
  11. data/recipes/admin.rb +42 -0
  12. data/recipes/analytics.rb +41 -0
  13. data/recipes/core.rb +32 -0
  14. data/recipes/deployment.rb +178 -0
  15. data/recipes/devise.rb +34 -0
  16. data/recipes/email.rb +65 -0
  17. data/recipes/email_dev.rb +92 -0
  18. data/recipes/example.rb +63 -0
  19. data/recipes/extras.rb +283 -0
  20. data/recipes/frontend.rb +33 -0
  21. data/recipes/gems.rb +274 -0
  22. data/recipes/git.rb +27 -0
  23. data/recipes/init.rb +179 -0
  24. data/recipes/learn_rails.rb +89 -0
  25. data/recipes/locale.rb +31 -0
  26. data/recipes/omniauth.rb +38 -0
  27. data/recipes/pages.rb +91 -0
  28. data/recipes/rails_bootstrap.rb +29 -0
  29. data/recipes/rails_devise.rb +26 -0
  30. data/recipes/rails_devise_pundit.rb +25 -0
  31. data/recipes/rails_devise_roles.rb +25 -0
  32. data/recipes/rails_foundation.rb +29 -0
  33. data/recipes/rails_mailinglist_activejob.rb +76 -0
  34. data/recipes/rails_omniauth.rb +27 -0
  35. data/recipes/rails_signup_download.rb +69 -0
  36. data/recipes/rails_stripe_checkout.rb +84 -0
  37. data/recipes/rails_stripe_coupons.rb +125 -0
  38. data/recipes/rails_stripe_membership_saas.rb +112 -0
  39. data/recipes/railsapps.rb +77 -0
  40. data/recipes/readme.rb +161 -0
  41. data/recipes/roles.rb +40 -0
  42. data/recipes/setup.rb +162 -0
  43. data/recipes/tests.rb +59 -0
  44. data/spec/rails_wizard/config_spec.rb +108 -0
  45. data/spec/rails_wizard/recipe_spec.rb +115 -0
  46. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  47. data/spec/rails_wizard/recipes_spec.rb +41 -0
  48. data/spec/rails_wizard/template_spec.rb +92 -0
  49. data/spec/spec_helper.rb +11 -0
  50. data/spec/support/rails_directory.rb +17 -0
  51. data/spec/support/template_runner.rb +28 -0
  52. data/spec/test_recipes/test_recipe_in_file.rb +9 -0
  53. data/templates/helpers.erb +138 -0
  54. data/templates/layout.erb +231 -0
  55. data/templates/recipe.erb +13 -0
  56. data/version.rb +3 -0
  57. metadata +201 -0
@@ -0,0 +1,33 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/frontend.rb
3
+
4
+ stage_two do
5
+ say_wizard "recipe stage two"
6
+ # set up a front-end framework using the rails_layout gem
7
+ case prefs[:frontend]
8
+ when 'simple'
9
+ generate 'layout:install simple -f'
10
+ when 'bootstrap2'
11
+ generate 'layout:install bootstrap2 -f'
12
+ when 'bootstrap3'
13
+ generate 'layout:install bootstrap3 -f'
14
+ when 'foundation4'
15
+ generate 'layout:install foundation4 -f'
16
+ when 'foundation5'
17
+ generate 'layout:install foundation5 -f'
18
+ end
19
+
20
+ ### GIT ###
21
+ git :add => '-A' if prefer :git, true
22
+ git :commit => '-qm "redmint_composer: front-end framework"' if prefer :git, true
23
+ end
24
+
25
+ __END__
26
+
27
+ name: frontend
28
+ description: "Install a front-end framework for HTML5 and CSS."
29
+ author: RailsApps
30
+
31
+ requires: [setup, gems]
32
+ run_after: [setup, gems, devise, omniauth, roles]
33
+ category: frontend
@@ -0,0 +1,274 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/gems.rb
3
+
4
+ ### GEMFILE ###
5
+
6
+ ## Ruby on Rails
7
+ insert_into_file('Gemfile', "ruby '#{RUBY_VERSION}'\n", :before => /^ *gem 'rails'/, :force => false)
8
+
9
+ ## Cleanup
10
+ # remove the 'sdoc' gem
11
+ if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
12
+ gsub_file 'Gemfile', /gem 'sdoc',\s+'~> 0.4.0',\s+group: :doc/, ''
13
+ else
14
+ gsub_file 'Gemfile', /group :doc do/, ''
15
+ gsub_file 'Gemfile', /\s*gem 'sdoc', require: false\nend/, ''
16
+ end
17
+
18
+ ## Web Server
19
+ if (prefs[:dev_webserver] == prefs[:prod_webserver])
20
+ add_gem 'thin' if prefer :dev_webserver, 'thin'
21
+ add_gem 'unicorn' if prefer :dev_webserver, 'unicorn'
22
+ add_gem 'unicorn-rails' if prefer :dev_webserver, 'unicorn'
23
+ add_gem 'puma' if prefer :dev_webserver, 'puma'
24
+ add_gem 'passenger' if prefer :dev_webserver, 'passenger_standalone'
25
+ else
26
+ add_gem 'thin', :group => [:development, :test] if prefer :dev_webserver, 'thin'
27
+ add_gem 'unicorn', :group => [:development, :test] if prefer :dev_webserver, 'unicorn'
28
+ add_gem 'unicorn-rails', :group => [:development, :test] if prefer :dev_webserver, 'unicorn'
29
+ add_gem 'puma', :group => [:development, :test] if prefer :dev_webserver, 'puma'
30
+ add_gem 'passenger', :group => [:development, :test] if prefer :dev_webserver, 'passenger_standalone'
31
+ add_gem 'thin', :group => :production if prefer :prod_webserver, 'thin'
32
+ add_gem 'unicorn', :group => :production if prefer :prod_webserver, 'unicorn'
33
+ add_gem 'puma', :group => :production if prefer :prod_webserver, 'puma'
34
+ add_gem 'passenger', :group => :production if prefer :prod_webserver, 'passenger_standalone'
35
+ end
36
+
37
+ ## Database Adapter
38
+ gsub_file 'Gemfile', /gem 'sqlite3'\n/, '' unless prefer :database, 'sqlite'
39
+ gsub_file 'Gemfile', /gem 'pg'.*/, ''
40
+ add_gem 'pg' if prefer :database, 'postgresql'
41
+ gsub_file 'Gemfile', /gem 'mysql2'.*/, ''
42
+ add_gem 'mysql2', '~> 0.3.18' if prefer :database, 'mysql'
43
+
44
+ ## Gem to set up controllers, views, and routing in the 'apps4' recipe
45
+ add_gem 'rails_apps_pages', :group => :development if prefs[:apps4]
46
+
47
+ ## Template Engine
48
+ if prefer :templates, 'haml'
49
+ add_gem 'haml-rails'
50
+ add_gem 'html2haml', :group => :development
51
+ end
52
+ if prefer :templates, 'slim'
53
+ add_gem 'slim-rails'
54
+ add_gem 'haml2slim', :group => :development
55
+ add_gem 'html2haml', :group => :development
56
+ end
57
+
58
+ ## Testing Framework
59
+ if prefer :tests, 'rspec'
60
+ add_gem 'rails_apps_testing', :group => :development
61
+ add_gem 'rspec-rails', :group => [:development, :test]
62
+ add_gem 'spring-commands-rspec', :group => :development
63
+ add_gem 'factory_girl_rails', :group => [:development, :test]
64
+ add_gem 'faker', :group => [:development, :test]
65
+ add_gem 'capybara', :group => :test
66
+ add_gem 'database_cleaner', :group => :test
67
+ add_gem 'launchy', :group => :test
68
+ add_gem 'selenium-webdriver', :group => :test
69
+ if prefer :continuous_testing, 'guard'
70
+ add_gem 'guard-bundler', :group => :development
71
+ add_gem 'guard-rails', :group => :development
72
+ add_gem 'guard-rspec', :group => :development
73
+ add_gem 'rb-inotify', :group => :development, :require => false
74
+ add_gem 'rb-fsevent', :group => :development, :require => false
75
+ add_gem 'rb-fchange', :group => :development, :require => false
76
+ end
77
+ end
78
+
79
+ ## Front-end Framework
80
+ add_gem 'rails_layout', :group => :development
81
+ case prefs[:frontend]
82
+ when 'bootstrap2'
83
+ add_gem 'bootstrap-sass', '~> 2.3.2.2'
84
+ when 'bootstrap3'
85
+ add_gem 'bootstrap-sass'
86
+ when 'foundation4'
87
+ add_gem 'zurb-foundation', '~> 4.3.2'
88
+ add_gem 'compass-rails', '~> 1.1.2'
89
+ when 'foundation5'
90
+ add_gem 'foundation-rails'
91
+ end
92
+
93
+ ## Pages
94
+ case prefs[:pages]
95
+ when 'about'
96
+ add_gem 'high_voltage'
97
+ when 'about+users'
98
+ add_gem 'high_voltage'
99
+ end
100
+
101
+ ## Email
102
+ add_gem 'sendgrid' if prefer :email, 'sendgrid'
103
+
104
+ ## Authentication (Devise)
105
+ if prefer :authentication, 'devise'
106
+ add_gem 'devise'
107
+ add_gem 'devise_invitable' if prefer :devise_modules, 'invitable'
108
+ end
109
+
110
+ ## Administratative Interface (Upmin)
111
+ add_gem 'upmin-admin' if prefer :dashboard, 'upmin'
112
+
113
+ ## Authentication (OmniAuth)
114
+ add_gem 'omniauth' if prefer :authentication, 'omniauth'
115
+ add_gem 'omniauth-twitter' if prefer :omniauth_provider, 'twitter'
116
+ add_gem 'omniauth-facebook' if prefer :omniauth_provider, 'facebook'
117
+ add_gem 'omniauth-github' if prefer :omniauth_provider, 'github'
118
+ add_gem 'omniauth-linkedin' if prefer :omniauth_provider, 'linkedin'
119
+ add_gem 'omniauth-google-oauth2' if prefer :omniauth_provider, 'google_oauth2'
120
+ add_gem 'omniauth-tumblr' if prefer :omniauth_provider, 'tumblr'
121
+
122
+ ## Authorization
123
+ add_gem 'pundit' if prefer :authorization, 'pundit'
124
+
125
+ ## Form Builder
126
+ add_gem 'simple_form' if prefer :form_builder, 'simple_form'
127
+
128
+ ## Gems from a defaults file or added interactively
129
+ gems.each do |g|
130
+ add_gem(*g)
131
+ end
132
+
133
+ ## Git
134
+ git :add => '-A' if prefer :git, true
135
+ git :commit => '-qm "redmint_composer: Gemfile"' if prefer :git, true
136
+
137
+ ### CREATE DATABASE ###
138
+ stage_two do
139
+ say_wizard "recipe stage two"
140
+ say_wizard "configuring database"
141
+ unless prefer :database, 'sqlite'
142
+ copy_from_repo 'config/database-postgresql.yml', :prefs => 'postgresql'
143
+ copy_from_repo 'config/database-mysql.yml', :prefs => 'mysql'
144
+ if prefer :database, 'postgresql'
145
+ begin
146
+ pg_username = prefs[:pg_username] || ask_wizard("Username for PostgreSQL?(leave blank to use the app name)")
147
+ pg_host = prefs[:pg_host] || ask_wizard("Host for PostgreSQL in database.yml? (leave blank to use default socket connection)")
148
+ if pg_username.blank?
149
+ say_wizard "Creating a user named '#{app_name}' for PostgreSQL"
150
+ run "createuser --createdb #{app_name}" if prefer :database, 'postgresql'
151
+ gsub_file "config/database.yml", /username: .*/, "username: #{app_name}"
152
+ else
153
+ gsub_file "config/database.yml", /username: .*/, "username: #{pg_username}"
154
+ pg_password = prefs[:pg_password] || ask_wizard("Password for PostgreSQL user #{pg_username}?")
155
+ gsub_file "config/database.yml", /password:/, "password: #{pg_password}"
156
+ say_wizard "set config/database.yml for username/password #{pg_username}/#{pg_password}"
157
+ end
158
+ if pg_host.present?
159
+ gsub_file "config/database.yml", / host: localhost/, " host: #{pg_host}"
160
+ end
161
+ rescue StandardError => e
162
+ raise "unable to create a user for PostgreSQL, reason: #{e}"
163
+ end
164
+ gsub_file "config/database.yml", /database: myapp_development/, "database: #{app_name}_development"
165
+ gsub_file "config/database.yml", /database: myapp_test/, "database: #{app_name}_test"
166
+ gsub_file "config/database.yml", /database: myapp_production/, "database: #{app_name}_production"
167
+ end
168
+ if prefer :database, 'mysql'
169
+ mysql_username = prefs[:mysql_username] || ask_wizard("Username for MySQL? (leave blank to use the app name)")
170
+ if mysql_username.blank?
171
+ gsub_file "config/database.yml", /username: .*/, "username: #{app_name}"
172
+ else
173
+ gsub_file "config/database.yml", /username: .*/, "username: #{mysql_username}"
174
+ mysql_password = prefs[:mysql_password] || ask_wizard("Password for MySQL user #{mysql_username}?")
175
+ gsub_file "config/database.yml", /password:/, "password: #{mysql_password}"
176
+ say_wizard "set config/database.yml for username/password #{mysql_username}/#{mysql_password}"
177
+ end
178
+ gsub_file "config/database.yml", /database: myapp_development/, "database: #{app_name}_development"
179
+ gsub_file "config/database.yml", /database: myapp_test/, "database: #{app_name}_test"
180
+ gsub_file "config/database.yml", /database: myapp_production/, "database: #{app_name}_production"
181
+ end
182
+ unless prefer :database, 'sqlite'
183
+ if (prefs.has_key? :drop_database) ? prefs[:drop_database] :
184
+ (yes_wizard? "Okay to drop all existing databases named #{app_name}? 'No' will abort immediately!")
185
+ run 'bundle exec rake db:drop'
186
+ else
187
+ raise "aborted at user's request"
188
+ end
189
+ end
190
+ run 'bundle exec rake db:create:all'
191
+ ## Git
192
+ git :add => '-A' if prefer :git, true
193
+ git :commit => '-qm "redmint_composer: create database"' if prefer :git, true
194
+ end
195
+ end
196
+
197
+ ### GENERATORS ###
198
+ stage_two do
199
+ say_wizard "recipe stage two"
200
+ say_wizard "running generators"
201
+ ## Form Builder
202
+ if prefer :form_builder, 'simple_form'
203
+ case prefs[:frontend]
204
+ when 'bootstrap2'
205
+ say_wizard "recipe installing simple_form for use with Bootstrap"
206
+ generate 'simple_form:install --bootstrap'
207
+ when 'bootstrap3'
208
+ say_wizard "recipe installing simple_form for use with Bootstrap"
209
+ generate 'simple_form:install --bootstrap'
210
+ when 'foundation5'
211
+ say_wizard "recipe installing simple_form for use with Zurb Foundation"
212
+ generate 'simple_form:install --foundation'
213
+ when 'foundation4'
214
+ say_wizard "recipe installing simple_form for use with Zurb Foundation"
215
+ generate 'simple_form:install --foundation'
216
+ else
217
+ say_wizard "recipe installing simple_form"
218
+ generate 'simple_form:install'
219
+ end
220
+ end
221
+ ## Figaro Gem
222
+ if prefer :local_env_file, 'figaro'
223
+ run 'figaro install'
224
+ gsub_file 'config/application.yml', /# PUSHER_.*\n/, ''
225
+ gsub_file 'config/application.yml', /# STRIPE_.*\n/, ''
226
+ prepend_to_file 'config/application.yml' do <<-FILE
227
+ # Add account credentials and API keys here.
228
+ # See http://railsapps.github.io/rails-environment-variables.html
229
+ # This file should be listed in .gitignore to keep your settings secret!
230
+ # Each entry sets a local environment variable.
231
+ # For example, setting:
232
+ # GMAIL_USERNAME: Your_Gmail_Username
233
+ # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
234
+
235
+ FILE
236
+ end
237
+ end
238
+ ## Foreman Gem
239
+ if prefer :local_env_file, 'foreman'
240
+ create_file '.env' do <<-FILE
241
+ # Add account credentials and API keys here.
242
+ # This file should be listed in .gitignore to keep your settings secret!
243
+ # Each entry sets a local environment variable.
244
+ # For example, setting:
245
+ # GMAIL_USERNAME=Your_Gmail_Username
246
+ # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
247
+
248
+ FILE
249
+ end
250
+ create_file 'Procfile', "web: bundle exec rails server -p $PORT\n" if prefer :prod_webserver, 'thin'
251
+ create_file 'Procfile', "web: bundle exec unicorn -p $PORT\n" if prefer :prod_webserver, 'unicorn'
252
+ create_file 'Procfile', "web: bundle exec puma -p $PORT\n" if prefer :prod_webserver, 'puma'
253
+ create_file 'Procfile', "web: bundle exec passenger start -p $PORT\n" if prefer :prod_webserver, 'passenger_standalone'
254
+ if (prefs[:dev_webserver] != prefs[:prod_webserver])
255
+ create_file 'Procfile.dev', "web: bundle exec rails server -p $PORT\n" if prefer :dev_webserver, 'thin'
256
+ create_file 'Procfile.dev', "web: bundle exec unicorn -p $PORT\n" if prefer :dev_webserver, 'unicorn'
257
+ create_file 'Procfile.dev', "web: bundle exec puma -p $PORT\n" if prefer :dev_webserver, 'puma'
258
+ create_file 'Procfile.dev', "web: bundle exec passenger start -p $PORT\n" if prefer :dev_webserver, 'passenger_standalone'
259
+ end
260
+ end
261
+ ## Git
262
+ git :add => '-A' if prefer :git, true
263
+ git :commit => '-qm "redmint_composer: generators"' if prefer :git, true
264
+ end
265
+
266
+ __END__
267
+
268
+ name: gems
269
+ description: "Add the gems your application needs."
270
+ author: RailsApps
271
+
272
+ requires: [setup]
273
+ run_after: [setup]
274
+ category: configuration
@@ -0,0 +1,27 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/git.rb
3
+
4
+ ## Git
5
+ say_wizard "initialize git"
6
+ prefs[:git] = true unless prefs.has_key? :git
7
+ if prefer :git, true
8
+ copy_from 'https://raw.githubusercontent.com/adrianescat/redmint_composer/master/data/gitignore.txt', '.gitignore'
9
+ git :init
10
+ git :add => '-A'
11
+ git :commit => '-qm "redmint_composer: initial commit"'
12
+ else
13
+ stage_three do
14
+ say_wizard "recipe stage three"
15
+ say_wizard "removing .gitignore and .gitkeep files"
16
+ git_files = Dir[File.join('**','.gitkeep')] + Dir[File.join('**','.gitignore')]
17
+ File.unlink git_files
18
+ end
19
+ end
20
+
21
+ __END__
22
+
23
+ name: git
24
+ description: "Initialize git for your application."
25
+ author: RailsApps
26
+
27
+ category: configuration
@@ -0,0 +1,179 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/init.rb
3
+
4
+ stage_three do
5
+ say_wizard "recipe stage three"
6
+ if (!prefs[:secrets].nil?)
7
+ prefs[:secrets].each do |secret|
8
+ env_var = " #{secret}: <%= ENV[\"#{secret.upcase}\"] %>"
9
+ inject_into_file 'config/secrets.yml', "\n" + env_var, :after => "development:"
10
+ ### 'inject_into_file' doesn't let us inject the same text twice unless we append the extra space, why?
11
+ inject_into_file 'config/secrets.yml', "\n" + env_var + " ", :after => "production:"
12
+ end
13
+ end
14
+ case prefs[:email]
15
+ when 'none'
16
+ secrets_email = foreman_email = ''
17
+ when 'smtp'
18
+ secrets_email = foreman_email = ''
19
+ when 'gmail'
20
+ secrets_email = " email_provider_username: <%= ENV[\"GMAIL_USERNAME\"] %>\n email_provider_password: <%= ENV[\"GMAIL_PASSWORD\"] %>"
21
+ foreman_email = "GMAIL_USERNAME=Your_Username\nGMAIL_PASSWORD=Your_Password\nDOMAIN_NAME=redmintlabs.com\n"
22
+ when 'sendgrid'
23
+ secrets_email = " email_provider_username: <%= ENV[\"SENDGRID_USERNAME\"] %>\n email_provider_password: <%= ENV[\"SENDGRID_PASSWORD\"] %>"
24
+ foreman_email = "SENDGRID_USERNAME=Your_Username\nSENDGRID_PASSWORD=Your_Password\nDOMAIN_NAME=redmintlabs.com\n"
25
+ when 'mandrill'
26
+ secrets_email = " email_provider_username: <%= ENV[\"MANDRILL_USERNAME\"] %>\n email_provider_apikey: <%= ENV[\"MANDRILL_APIKEY\"] %>"
27
+ foreman_email = "MANDRILL_USERNAME=Your_Username\nMANDRILL_APIKEY=Your_API_Key\nDOMAIN_NAME=redmintlabs.com\n"
28
+ end
29
+ figaro_email = foreman_email.gsub('=', ': ')
30
+ secrets_d_devise = " admin_name: First User\n admin_email: admin@redmintlabs.com\n admin_password: redmint123"
31
+ secrets_p_devise = " admin_name: <%= ENV[\"ADMIN_NAME\"] %>\n admin_email: <%= ENV[\"ADMIN_EMAIL\"] %>\n admin_password: <%= ENV[\"ADMIN_PASSWORD\"] %>"
32
+ foreman_devise = "ADMIN_NAME=First User\nADMIN_EMAIL=admin@redmintlabs.com\nADMIN_PASSWORD=redmint123\n"
33
+ figaro_devise = foreman_devise.gsub('=', ': ')
34
+ secrets_omniauth = " omniauth_provider_key: <%= ENV[\"OMNIAUTH_PROVIDER_KEY\"] %>\n omniauth_provider_secret: <%= ENV[\"OMNIAUTH_PROVIDER_SECRET\"] %>"
35
+ foreman_omniauth = "OMNIAUTH_PROVIDER_KEY=Your_Provider_Key\nOMNIAUTH_PROVIDER_SECRET=Your_Provider_Secret\n"
36
+ figaro_omniauth = foreman_omniauth.gsub('=', ': ')
37
+ ## EMAIL
38
+ inject_into_file 'config/secrets.yml', "\n" + " domain_name: redmintlabs.com", :after => "development:"
39
+ inject_into_file 'config/secrets.yml', "\n" + " domain_name: <%= ENV[\"DOMAIN_NAME\"] %>", :after => "production:"
40
+ inject_into_file 'config/secrets.yml', "\n" + secrets_email, :after => "development:"
41
+ unless prefer :email, 'none'
42
+ ### 'inject_into_file' doesn't let us inject the same text twice unless we append the extra space, why?
43
+ inject_into_file 'config/secrets.yml', "\n" + secrets_email + " ", :after => "production:"
44
+ append_file '.env', foreman_email if prefer :local_env_file, 'foreman'
45
+ append_file 'config/application.yml', figaro_email if prefer :local_env_file, 'figaro'
46
+ end
47
+ ## DEVISE
48
+ if prefer :authentication, 'devise'
49
+ inject_into_file 'config/secrets.yml', "\n" + ' domain_name: redmintlabs.com' + " ", :after => "test:"
50
+ inject_into_file 'config/secrets.yml', "\n" + secrets_d_devise, :after => "development:"
51
+ inject_into_file 'config/secrets.yml', "\n" + secrets_p_devise, :after => "production:"
52
+ append_file '.env', foreman_devise if prefer :local_env_file, 'foreman'
53
+ append_file 'config/application.yml', figaro_devise if prefer :local_env_file, 'figaro'
54
+ gsub_file 'config/initializers/devise.rb', /'please-change-me-at-config-initializers-devise@redmintlabs.com'/, "'no-reply@' + Rails.application.secrets.domain_name"
55
+ end
56
+ ## OMNIAUTH
57
+ if prefer :authentication, 'omniauth'
58
+ inject_into_file 'config/secrets.yml', "\n" + secrets_omniauth, :after => "development:"
59
+ ### 'inject_into_file' doesn't let us inject the same text twice unless we append the extra space, why?
60
+ inject_into_file 'config/secrets.yml', "\n" + secrets_omniauth + " ", :after => "production:"
61
+ append_file '.env', foreman_omniauth if prefer :local_env_file, 'foreman'
62
+ append_file 'config/application.yml', figaro_omniauth if prefer :local_env_file, 'figaro'
63
+ end
64
+ ## rails-stripe-coupons
65
+ if prefer :apps4, 'rails-stripe-coupons'
66
+ gsub_file 'config/secrets.yml', /<%= ENV\["PRODUCT_TITLE"\] %>/, 'What is Ruby on Rails'
67
+ gsub_file 'config/secrets.yml', /<%= ENV\["PRODUCT_PRICE"\] %>/, '995'
68
+ end
69
+ ### EXAMPLE FILE FOR FOREMAN AND FIGARO ###
70
+ if prefer :local_env_file, 'figaro'
71
+ copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
72
+ elsif prefer :local_env_file, 'foreman'
73
+ copy_file destination_root + '/.env', destination_root + '/.env.example'
74
+ end
75
+ ### DATABASE SEED ###
76
+ if prefer :authentication, 'devise'
77
+ copy_from_repo 'db/seeds.rb', :repo => 'https://raw.github.com/RailsApps/rails-devise/master/'
78
+ if prefer :authorization, 'roles'
79
+ copy_from_repo 'app/services/create_admin_service.rb', :repo => 'https://raw.github.com/RailsApps/rails-devise-roles/master/'
80
+ elsif prefer :authorization, 'pundit'
81
+ copy_from_repo 'app/services/create_admin_service.rb', :repo => 'https://raw.github.com/RailsApps/rails-devise-pundit/master/'
82
+ else
83
+ copy_from_repo 'app/services/create_admin_service.rb', :repo => 'https://raw.github.com/RailsApps/rails-devise/master/'
84
+ end
85
+ end
86
+ if prefer :apps4, 'rails-stripe-coupons'
87
+ copy_from_repo 'app/services/create_couponcodes_service.rb', :repo => 'https://raw.github.com/RailsApps/rails-stripe-coupons/master/'
88
+ append_file 'db/seeds.rb' do <<-FILE
89
+ CreateCouponcodesService.new.call
90
+ puts 'CREATED PROMOTIONAL CODES'
91
+ FILE
92
+ end
93
+ end
94
+ if prefer :apps4, 'rails-stripe-membership-saas'
95
+ append_file 'db/seeds.rb' do <<-FILE
96
+ CreatePlanService.new.call
97
+ puts 'CREATED PLANS'
98
+ FILE
99
+ end
100
+ end
101
+ if prefer :local_env_file, 'figaro'
102
+ append_file 'db/seeds.rb' do <<-FILE
103
+ # Environment variables (ENV['...']) can be set in the file config/application.yml.
104
+ # See http://railsapps.github.io/rails-environment-variables.html
105
+ FILE
106
+ end
107
+ elsif prefer :local_env_file, 'foreman'
108
+ append_file 'db/seeds.rb' do <<-FILE
109
+ # Environment variables (ENV['...']) can be set in the file .env file.
110
+ FILE
111
+ end
112
+ end
113
+ ## DEVISE-CONFIRMABLE
114
+ if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
115
+ inject_into_file 'app/services/create_admin_service.rb', " user.confirm!\n", :after => "user.password_confirmation = Rails.application.secrets.admin_password\n"
116
+ end
117
+ ## DEVISE-INVITABLE
118
+ if prefer :devise_modules, 'invitable'
119
+ if prefer :local_env_file, 'foreman'
120
+ run 'foreman run bundle exec rake db:migrate'
121
+ else
122
+ run 'bundle exec rake db:migrate'
123
+ end
124
+ generate 'devise_invitable user'
125
+ end
126
+ ### APPLY DATABASE SEED ###
127
+ if File.exists?('db/migrate')
128
+ ## ACTIVE_RECORD
129
+ say_wizard "applying migrations and seeding the database"
130
+ if prefer :local_env_file, 'foreman'
131
+ run 'foreman run bundle exec rake db:migrate'
132
+ else
133
+ run 'bundle exec rake db:migrate'
134
+ end
135
+ end
136
+ unless prefs[:skip_seeds]
137
+ if prefer :local_env_file, 'foreman'
138
+ run 'foreman run bundle exec rake db:seed'
139
+ else
140
+ run 'bundle exec rake db:seed'
141
+ end
142
+ end
143
+ ### GIT ###
144
+ git :add => '-A' if prefer :git, true
145
+ git :commit => '-qm "redmint_composer: set up database"' if prefer :git, true
146
+ ### FRONTEND (must run after database migrations) ###
147
+ # generate Devise views with appropriate styling
148
+ if prefer :authentication, 'devise'
149
+ case prefs[:frontend]
150
+ when 'bootstrap3'
151
+ generate 'layout:devise bootstrap3 -f'
152
+ when 'foundation5'
153
+ generate 'layout:devise foundation5 -f'
154
+ end
155
+ end
156
+ # create navigation links using the rails_layout gem
157
+ generate 'layout:navigation -f'
158
+ if prefer :apps4, 'rails-stripe-coupons'
159
+ inject_into_file 'app/views/layouts/_navigation_links.html.erb', ", data: { no_turbolink: true }", :after => "new_user_registration_path"
160
+ inject_into_file 'app/views/layouts/_navigation_links.html.erb', "\n <li><%= link_to 'Coupons', coupons_path %></li>", :after => "users_path %></li>"
161
+ end
162
+ if prefer :apps4, 'rails-stripe-membership-saas'
163
+ inject_into_file 'app/views/layouts/_navigation_links.html.erb', ", data: { no_turbolink: true }", :after => "new_user_registration_path"
164
+ copy_from_repo 'app/views/devise/registrations/edit.html.erb', :repo => 'https://raw.github.com/RailsApps/rails-stripe-membership-saas/master/'
165
+ end
166
+ ### GIT ###
167
+ git :add => '-A' if prefer :git, true
168
+ git :commit => '-qm "redmint_composer: navigation links"' if prefer :git, true
169
+ end
170
+
171
+ __END__
172
+
173
+ name: init
174
+ description: "Set up and initialize database."
175
+ author: RailsApps
176
+
177
+ requires: [setup, gems, devise, omniauth]
178
+ run_after: [setup, gems, pages]
179
+ category: initialize