-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.rb
335 lines (310 loc) · 10.8 KB
/
template.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
# frozen_string_literal: true
#
# Frontend Gems
#
installed_bootstrap = yes?('Install twitter-bootstrap-rails gem?')
if installed_bootstrap
# Twitter Bootstrap
gem 'twitter-bootstrap-rails'
generate 'bootstrap:install less'
# bootstrap-datepicker-rails | bootstrap styled jQuery date input
gem 'bootstrap-datepicker-rails' if yes?('Install bootstrap datepicker?')
# jquery-rails - JavaScript Library required by Bootstrap v4
gem 'jquery-rails'
# less-rails | Used to ease Bootstrap theme modifications
gem 'less-rails'
# therubyracer | Required to use Less
gem 'therubyracer'
generate 'bootstrap:layout', 'application'
# Add CSS that prevents body content from rendering underneath the navbar and
# footer. Add CSS that renders the alerts in bootstrap alert dialogues.
gsub_file(
'app/assets/stylesheets/application.css',
%r{^ \*\/\n}, " */\n\nbody {\n margin: 50px 0 60px 0;\n}\n"
)
# Add jQuery and Bootstrap JS to the JavaScript manifest
gsub_file(
'app/assets/javascripts/application.js',
%r{^//= require rails-ujs}, "//= require jquery3\n//= require rails-ujs"
)
gsub_file('app/assets/javascripts/application.js',
%r{^//= require rails-ujs\n}, "//= require rails-ujs\n//= "\
"require twitter/bootstrap\n")
end
# font-awesome-rails | icons
if yes?('Install font-awesome-rails icons?')
gem 'font-awesome-rails'
gsub_file(
'app/assets/stylesheets/application.css',
/^ \*= require_tree \./, " *= require_tree .\n *= require font-awesome"
)
end
# kaminari | pagination
if yes?('Install kaminari gem for pagination?')
gem 'kaminari'
generate 'kaminari:views default' # Genrate the default views from Kaminari
end
#
# Core Gems
#
#
# Access Control
#
gem 'pundit'
generate 'pundit:install'
gsub_file(
'app/controllers/application_controller.rb',
/^end\n/, %( include Pundit
protect_from_forgery with: :exception
# Require a User to be logged in for every action by default.
before_action :authenticate_user!
# Rescue from unauthorized with an error.
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
##
# Forward the unauthorized user to the previous page or the home page of the
# application.
#
def user_not_authorized
flash[:alert] = t(:error_not_authorized)
redirect_to(request.referer || root_path)
end
end
)
)
#
# Authentication
#
gem 'devise'
generate 'devise:install'
model_name = ask('What would you like the user model to be called? [User]')
model_name = 'User' if model_name.blank?
generate 'devise', model_name
generate 'controller', model_name.pluralize
gsub_file(
'config/routes.rb',
/devise_for :users/, "devise_for :users\n resources :users"
)
generate 'devise:views' if installed_bootstrap
generate 'bootstrap:themed', model_name.pluralize if installed_bootstrap
generate 'pundit:policy', model_name.pluralize
#
# Require SSL in Production
#
gsub_file(
'config/environments/production.rb', /# config\.force_ssl = true/,
'config.force_ssl = true'
)
#
# Seed an Administrative User
#
require 'securerandom'
# Remove stock file
remove_file 'db/seeds.rb'
# Create a new seeds file containing a user with a random password.
create_file 'db/seeds.rb', "User.create!(
email: '[email protected]', password: '#{SecureRandom.hex}'
)\n"
#
# Setup Static Home Page
#
generate 'controller', 'static home'
route "root to: 'static#home'"
gsub_file('config/routes.rb', %r{^ get 'static\/home'\n$}, '')
# honeybadger | exception reporting
gem 'honeybadger'
#
# Backend Optional Gems
#
# attr_encrypted| encrypt model attributes
gem 'attr_encrypted', '~> 3.0.0' if yes?('Install attr_encrypted gem?')
# Interact with Amazon Web Services (S3, CloudFront, etc.)
gem 'aws-sdk' if yes?('Install aws-sdk gem?')
# city-state | library of US states and cities for forms
gem 'city-state' if yes?('Install city-state gem?')
# Cocoon for implementing forms for associated models.
gem 'cocoon' if yes?('Install cocoon gem for associated model forms?')
# Delayed Job Queue
installed_delayed_job = yes?('Install basic delayed_job queue?')
gem 'delayed_job_active_record' if installed_delayed_job
# A simple ActiveRecord mixin to add conventions for flagging records as
# discarded.
gem 'discard' if yes?('Install discard gem for, "soft deletes"?')
# fuzzily | inexact search matching
gem 'fuzzily' if yes?('Install fuzzily gem for, "fuzzy searches"?')
# geocoder | retrieve latitude and longitude for locations
gem 'geocoder' if yes?('Install geocoder gem?')
# gibbon | MailChimp e-mail marketing
gem 'gibbon' if yes?('Install gibbon for MailChimp integration?')
# Allow hashes of numeric IDs to be calculated to obfuscate sequential access
# to application records.
gem 'hashid-rails' if yes?('Install hashid-rails to obfuscate IDs?')
# koala | Facebook API access.
gem 'koala' if yes?('Install koala for Facebook API access?')
# mandrill-api | Mandrill (MailChimp) Transactional E-Mail
gem 'mandrill-api' if yes?('Install mandrill-api for transactional e-mail?')
# mechanize | web automation and scraping
gem 'mechanize' if yes?('Install mechanize for web automation and scraping?')
# net-sftp| connect to SFTP server for file drops.
gem 'net-sftp' if yes?('Install SFTP capability?')
# paper_trail| track changes to your rails models
if yes?('Install paper_trail gem?')
gem 'paper_trail'
# Track changes to associations of your rails models
gem 'paper_trail-association_tracking' if yes?('Allow association tracking?')
end
# paperclip | file uploads
if yes?('Install paperclip gem for uploading files?')
gem 'paperclip'
gem 'delayed_paperclip' if installed_delayed_job
end
# rack-rewrite | 301 redirects (useful for domain name changes)
gem 'rack-rewrite' if yes?('Install rack-rewrite gem?')
# ransack - search models for specific records
gem 'ransack' if yes?('Install ransack (search) gem?')
# rubyXL - Read XLSX files, for importation of data from Excel. We're only going
# => to include this when we need it, during data importation.
gem 'rubyXL', require: false if yes?('Install rubyXL (.xlsx) gem?')
# For exporting binary Excel XLS format documents. Not to be confused with the
# Open XLSX standard.
gem 'spreadsheet', require: false if yes?('Install spreadsheet (.xls) gem?')
# twilio-ruby| sms and telephone communication
gem 'twilio-ruby' if yes?('Install twilio-ruby gem for sms and telephone?')
if yes?('Install two factor auth gem?')
gem 'two_factor_authentication'
gem 'rqrcode'
end
#
# API Specific Gems
#
# Oj, a faster library for exporting JSON.
if yes?('Install oj gem for faster JSON serialization?')
gem 'oj'
gem 'oj_mimic_json'
end
# Ox, a faster library for exporting XML.
gem 'ox' if yes?('Install ox gem for faster XML?')
#
# Financial
#
if yes?('Do you need to install financial services?')
# ach | write ACH transfer batch files
gem 'ach' if yes?('Install ach gem for writing NACHA files?')
# Monetize, for converting other objects into Money.
gem 'monetize' if yes?('Install monetize for money handling?')
# Plaid for enabling ACH payments
gem 'plaid' if yes?('Install plaid for account authentication and info?')
# stripe | payment processing
gem 'stripe' if yes?('Install stripe for payment processing?')
end
# Heroku
gem_group :production do
gem 'rails_12factor'
gem 'pg'
end
#
# Development Only
#
gem_group :development do
# benchmark-memory | a tool that helps you to benchmark memory usage
gem 'benchmark-memory'
# Used to view mail messages in a web browser without actually sending a
# message through a mail server.
gem 'letter_opener'
# rack-mini-profiler | profile page loading
gem 'rack-mini-profiler', require: false
# rails-erd | generate entity relationship diagrams
gem 'rails-erd'
end
#
# Development and Test
#
gem_group :development, :test do
# brakeman | security scanner
gem 'brakeman', require: false
# https://github.com/flyerhzm/bullet
#
# The Bullet gem is designed to help you increase your application's
# performance by reducing the number of queries it makes.
gem 'bullet'
application(nil, env: 'development') do
%(# Enable Bullet, turn on /log/bullet.log, add notifications to footer.
config.after_initialize do
Bullet.enable = true
Bullet.bullet_logger = true
Bullet.add_footer = true
# Bullet.alert = true
# Bullet.console = true
# Bullet.growl = true
# Bullet.xmpp = { :account => '[email protected]',
# :password => 'bullets_password_for_jabber',
# :receiver => '[email protected]',
# :show_online_status => true }
# Bullet.rails_logger = true
# Bullet.honeybadger = true
# Bullet.bugsnag = true
# Bullet.airbrake = true
# Bullet.rollbar = true
# Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
# Bullet.slack = { webhook_url: 'http://some.slack.url', foo: 'bar' }
end)
end
application(nil, env: 'test') do
%(# Enable Bullet, turn on /log/bullet.log during testing.
config.after_initialize do
Bullet.enable = true
Bullet.bullet_logger = true
end)
end
gem 'database_cleaner'
# Use .env files to automatically load environment variables in development
# and testing environments
gem 'dotenv-rails'
# i18n-tasks | manage internationalization and localization files
gem 'i18n-tasks'
# rubocop | static code analysis
gem 'rubocop'
gem 'rubocop-checkstyle_formatter', require: false
gem 'rubocop-performance'
gem 'spring'
# Remove SQLite from ALL environments. Only want it in development and test.
gsub_file 'Gemfile', /^# Use sqlite3 as the database for Active Record\n/, ''
gsub_file 'Gemfile', /^gem 'sqlite3'\n/, ''
end
# Rubocop Configuration File
create_file 'config/rubocop.yml', "AllCops:
Exclude:
- 'db/**/*'
- 'bin/*'
TargetRubyVersion: 2.7\n"
# Alter Rakefile to include ci_reporter_minitest
gsub_file('Rakefile', "require_relative 'config/application'\n",
"require_relative 'config/application'
if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test'
require 'ci/reporter/rake/minitest'
end")
# Prepend SimpleCov to test_helper
prepend_file('test/test_helper.rb', "# frozen_string_literal: true
require 'simplecov'
SimpleCov.start 'rails'\n")
# Append coverage report directory to .gitignore
append_file('.gitignore', "\n# Ignore Test Coverage Report Directory
/coverage/\n")
# Ignore .env files as they may contain sensitive information
append_file('.gitignore', "\n# Ignore development and test environment files
.env\n")
# Procfile - Process File
create_file 'Procfile', "web: bundle exec puma -C config/puma.rb
worker: bundle exec rake jobs:work"
#
# Test Only -
#
gem_group :test do
gem 'capybara-screenshot'
gem 'capybara-webkit'
gem 'ci_reporter_minitest'
gem 'simplecov', require: false
gem 'vcr'
gem 'webmock'
end
# Run
rake 'db:migrate db:seed'