kowl 0.0.1
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.
- checksums.yaml +7 -0
- data/LICENSE +7 -0
- data/README.md +383 -0
- data/bin/console +14 -0
- data/bin/kowl +106 -0
- data/bin/setup +13 -0
- data/lib/kowl/actions.rb +240 -0
- data/lib/kowl/docker.rb +447 -0
- data/lib/kowl/generators/README.md +5 -0
- data/lib/kowl/generators/action_generator.rb +113 -0
- data/lib/kowl/generators/admin_generator.rb +114 -0
- data/lib/kowl/generators/assets_generator.rb +188 -0
- data/lib/kowl/generators/base.rb +40 -0
- data/lib/kowl/generators/circleci_generator.rb +11 -0
- data/lib/kowl/generators/config_generator.rb +180 -0
- data/lib/kowl/generators/controller_generator.rb +64 -0
- data/lib/kowl/generators/database_generator.rb +42 -0
- data/lib/kowl/generators/decorators_generator.rb +16 -0
- data/lib/kowl/generators/docker_generator.rb +40 -0
- data/lib/kowl/generators/dotfiles_generator.rb +73 -0
- data/lib/kowl/generators/libs_generator.rb +19 -0
- data/lib/kowl/generators/mailer_generator.rb +58 -0
- data/lib/kowl/generators/misc_generator.rb +20 -0
- data/lib/kowl/generators/overrides/app_base.rb +15 -0
- data/lib/kowl/generators/overrides/app_builder.rb +58 -0
- data/lib/kowl/generators/overrides/app_generator.rb +249 -0
- data/lib/kowl/generators/pages_generator.rb +46 -0
- data/lib/kowl/generators/routes_generator.rb +20 -0
- data/lib/kowl/generators/sidekiq_generator.rb +31 -0
- data/lib/kowl/generators/staging_generator.rb +14 -0
- data/lib/kowl/generators/test_generator.rb +42 -0
- data/lib/kowl/generators/text_files_generator.rb +41 -0
- data/lib/kowl/generators/users_and_auth_generator.rb +143 -0
- data/lib/kowl/generators/uuid_generator.rb +39 -0
- data/lib/kowl/generators/views_and_helpers_generator.rb +104 -0
- data/lib/kowl/geodb.rb +96 -0
- data/lib/kowl/helpers.rb +139 -0
- data/lib/kowl/templates/Gemfile.erb.tt +253 -0
- data/lib/kowl/templates/README.md.erb +33 -0
- data/lib/kowl/templates/app/assets/javascripts/semantic.js.tt +26 -0
- data/lib/kowl/templates/app/assets/stylesheets/administrate/application.scss +44 -0
- data/lib/kowl/templates/app/assets/stylesheets/bootstrap/_custom_styling.scss +38 -0
- data/lib/kowl/templates/app/assets/stylesheets/bootstrap/application-mailer.scss +1 -0
- data/lib/kowl/templates/app/assets/stylesheets/bootstrap/application.scss +14 -0
- data/lib/kowl/templates/app/assets/stylesheets/bootstrap/components/_alerts.scss +7 -0
- data/lib/kowl/templates/app/assets/stylesheets/bootstrap/components/_errors.scss +28 -0
- data/lib/kowl/templates/app/assets/stylesheets/bootstrap/components/_navbar.scss +17 -0
- data/lib/kowl/templates/app/assets/stylesheets/bootstrap/variables.scss +6 -0
- data/lib/kowl/templates/app/assets/stylesheets/semantic/_custom_styling.scss +20 -0
- data/lib/kowl/templates/app/assets/stylesheets/semantic/application.scss +24 -0
- data/lib/kowl/templates/app/controllers/admin/application_controller.rb +29 -0
- data/lib/kowl/templates/app/controllers/admin/login_activities_controller.rb +29 -0
- data/lib/kowl/templates/app/controllers/admin/users_controller.rb +37 -0
- data/lib/kowl/templates/app/controllers/concerns/auth/authentication.rb +18 -0
- data/lib/kowl/templates/app/controllers/concerns/auth/authorization.rb +20 -0
- data/lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb +27 -0
- data/lib/kowl/templates/app/controllers/concerns/noauth/error_handlers.rb +25 -0
- data/lib/kowl/templates/app/controllers/users_controller.rb +17 -0
- data/lib/kowl/templates/app/dashboards/login_activity_dashboard.rb.tt +59 -0
- data/lib/kowl/templates/app/dashboards/rich_text_body_dashboard.rb.tt +17 -0
- data/lib/kowl/templates/app/dashboards/user_dashboard.rb.tt +60 -0
- data/lib/kowl/templates/app/fields/gravatar_field.rb +10 -0
- data/lib/kowl/templates/app/fields/rich_text_area_field.rb +8 -0
- data/lib/kowl/templates/app/inputs/rich_text_area_input.rb +11 -0
- data/lib/kowl/templates/app/javascript/administrate/components/date_time_picker.js.tt +32 -0
- data/lib/kowl/templates/app/javascript/administrate/components/table.js.tt +49 -0
- data/lib/kowl/templates/app/javascript/administrate/index.js +3 -0
- data/lib/kowl/templates/app/javascript/packs/administrate.js.tt +21 -0
- data/lib/kowl/templates/app/javascript/packs/semantic.js +11 -0
- data/lib/kowl/templates/app/mailers/application_mailer.rb +7 -0
- data/lib/kowl/templates/app/mailers/devise_mailer.rb +5 -0
- data/lib/kowl/templates/app/models/login_activity.rb.tt +29 -0
- data/lib/kowl/templates/app/models/user.rb.tt +72 -0
- data/lib/kowl/templates/app/policies/application_policy.rb +38 -0
- data/lib/kowl/templates/app/policies/login_activity_policy.rb +35 -0
- data/lib/kowl/templates/app/policies/user_policy.rb +43 -0
- data/lib/kowl/templates/app/views/admin/templates/navigation.erb.tt +23 -0
- data/lib/kowl/templates/app/views/admin/views/application/_javascript.html.erb +21 -0
- data/lib/kowl/templates/app/views/admin/views/users/_collection.html.erb +102 -0
- data/lib/kowl/templates/app/views/admin/views/users/_form.html.erb +46 -0
- data/lib/kowl/templates/app/views/admin/views/users/edit.html.erb +36 -0
- data/lib/kowl/templates/app/views/admin/views/users/index.html.erb +66 -0
- data/lib/kowl/templates/app/views/fields/gravatar_field/_form.html.erb +6 -0
- data/lib/kowl/templates/app/views/fields/gravatar_field/_index.html.erb +1 -0
- data/lib/kowl/templates/app/views/fields/gravatar_field/_show.html.erb +1 -0
- data/lib/kowl/templates/app/views/fields/rich_text_area_field/_form.html.erb +6 -0
- data/lib/kowl/templates/app/views/fields/rich_text_area_field/_index.html.erb +1 -0
- data/lib/kowl/templates/app/views/fields/rich_text_area_field/_show.html.erb +1 -0
- data/lib/kowl/templates/app/views/layouts/admin.html.erb.tt +47 -0
- data/lib/kowl/templates/app/views/layouts/devise_mailer.html.erb +14 -0
- data/lib/kowl/templates/app/views/pages/welcome/bootstrap.html.erb +18 -0
- data/lib/kowl/templates/app/views/pages/welcome/bootstrap.html.haml +17 -0
- data/lib/kowl/templates/app/views/pages/welcome/bootstrap.html.slim +17 -0
- data/lib/kowl/templates/app/views/pages/welcome/default.html.erb +0 -0
- data/lib/kowl/templates/app/views/pages/welcome/default.html.haml +0 -0
- data/lib/kowl/templates/app/views/pages/welcome/default.html.slim +0 -0
- data/lib/kowl/templates/app/views/pages/welcome/semantic.html.erb +20 -0
- data/lib/kowl/templates/app/views/pages/welcome/semantic.html.haml +17 -0
- data/lib/kowl/templates/app/views/pages/welcome/semantic.html.slim +17 -0
- data/lib/kowl/templates/app/views/shared/footer/bootstrap.html.erb.tt +5 -0
- data/lib/kowl/templates/app/views/shared/footer/bootstrap.html.haml.tt +3 -0
- data/lib/kowl/templates/app/views/shared/footer/bootstrap.html.slim.tt +3 -0
- data/lib/kowl/templates/app/views/shared/footer/semantic.html.erb.tt +7 -0
- data/lib/kowl/templates/app/views/shared/footer/semantic.html.haml.tt +5 -0
- data/lib/kowl/templates/app/views/shared/footer/semantic.html.slim.tt +5 -0
- data/lib/kowl/templates/app/views/shared/navigation/bootstrap.html.erb.tt +51 -0
- data/lib/kowl/templates/app/views/shared/navigation/bootstrap.html.haml.tt +36 -0
- data/lib/kowl/templates/app/views/shared/navigation/bootstrap.html.slim.tt +36 -0
- data/lib/kowl/templates/app/views/shared/navigation/semantic.html.erb.tt +48 -0
- data/lib/kowl/templates/app/views/shared/navigation/semantic.html.haml.tt +36 -0
- data/lib/kowl/templates/app/views/shared/navigation/semantic.html.slim.tt +36 -0
- data/lib/kowl/templates/app/workers/scheduler/pghero_scheduler.rb +11 -0
- data/lib/kowl/templates/config/autoprefixer.yml +4 -0
- data/lib/kowl/templates/config/db/mysql.yml.tt +43 -0
- data/lib/kowl/templates/config/db/oracle.yml.tt +29 -0
- data/lib/kowl/templates/config/db/postgresql.yml.tt +37 -0
- data/lib/kowl/templates/config/db/sqlite3.yml.tt +20 -0
- data/lib/kowl/templates/config/db/sqlserver.yml.tt +28 -0
- data/lib/kowl/templates/config/initializers/administrate.rb.tt +9 -0
- data/lib/kowl/templates/config/initializers/bullet.rb +21 -0
- data/lib/kowl/templates/config/initializers/devise-security.rb +44 -0
- data/lib/kowl/templates/config/initializers/devise_argon2.rb +29 -0
- data/lib/kowl/templates/config/initializers/faker.rb +6 -0
- data/lib/kowl/templates/config/initializers/generators.rb.tt +31 -0
- data/lib/kowl/templates/config/initializers/geocoder.rb +10 -0
- data/lib/kowl/templates/config/initializers/letter_opener.rb +13 -0
- data/lib/kowl/templates/config/initializers/lockbox.rb +11 -0
- data/lib/kowl/templates/config/initializers/logging.rb +6 -0
- data/lib/kowl/templates/config/initializers/lograge.rb +7 -0
- data/lib/kowl/templates/config/initializers/logstop.rb +4 -0
- data/lib/kowl/templates/config/initializers/middleware.rb +9 -0
- data/lib/kowl/templates/config/initializers/oj.rb +7 -0
- data/lib/kowl/templates/config/initializers/pagy.rb.tt +16 -0
- data/lib/kowl/templates/config/initializers/postmark.rb +8 -0
- data/lib/kowl/templates/config/initializers/rack_attack.rb.tt +71 -0
- data/lib/kowl/templates/config/initializers/sass.rb +5 -0
- data/lib/kowl/templates/config/initializers/sidekiq.rb +11 -0
- data/lib/kowl/templates/config/initializers/simpleform/semantic.rb +225 -0
- data/lib/kowl/templates/config/initializers/slim.rb +6 -0
- data/lib/kowl/templates/config/initializers/sparkpost.rb +13 -0
- data/lib/kowl/templates/config/routes.rb.tt +28 -0
- data/lib/kowl/templates/config/sidekiq.yml.tt +17 -0
- data/lib/kowl/templates/db/migrations/create_action_text_tables.action_text.rb.tt +16 -0
- data/lib/kowl/templates/db/migrations/create_active_storage_tables.active_storage.rb.tt +29 -0
- data/lib/kowl/templates/db/migrations/devise.rb.tt +59 -0
- data/lib/kowl/templates/db/migrations/login_activities.rb.tt +41 -0
- data/lib/kowl/templates/db/seeds.rb.tt +14 -0
- data/lib/kowl/templates/docker/Dockerfile.alpine.tt +92 -0
- data/lib/kowl/templates/docker/Dockerfile.debian.tt +133 -0
- data/lib/kowl/templates/docker/docker-compose.yml.tt +55 -0
- data/lib/kowl/templates/docker/mysql/Dockerfile.tt +15 -0
- data/lib/kowl/templates/dotfiles/Aptfile.tt +34 -0
- data/lib/kowl/templates/dotfiles/Brewfile.tt +49 -0
- data/lib/kowl/templates/dotfiles/Procfile.tt +12 -0
- data/lib/kowl/templates/dotfiles/codeclimate.yml +76 -0
- data/lib/kowl/templates/dotfiles/coffeelint.json +10 -0
- data/lib/kowl/templates/dotfiles/coffeelintignore +15 -0
- data/lib/kowl/templates/dotfiles/dockerignore +23 -0
- data/lib/kowl/templates/dotfiles/editorconfig +13 -0
- data/lib/kowl/templates/dotfiles/env.tt +58 -0
- data/lib/kowl/templates/dotfiles/erb-lint.yml +10 -0
- data/lib/kowl/templates/dotfiles/erdconfig.tt +24 -0
- data/lib/kowl/templates/dotfiles/eslintignore +20 -0
- data/lib/kowl/templates/dotfiles/eslintrc.js +31 -0
- data/lib/kowl/templates/dotfiles/fasterer.yml +14 -0
- data/lib/kowl/templates/dotfiles/foreman +1 -0
- data/lib/kowl/templates/dotfiles/gitattributes +15 -0
- data/lib/kowl/templates/dotfiles/gitignore +69 -0
- data/lib/kowl/templates/dotfiles/haml-lint.yml +23 -0
- data/lib/kowl/templates/dotfiles/jsbeautifyrc +15 -0
- data/lib/kowl/templates/dotfiles/jshintrc +3 -0
- data/lib/kowl/templates/dotfiles/mailmap +3 -0
- data/lib/kowl/templates/dotfiles/nvmrc +1 -0
- data/lib/kowl/templates/dotfiles/prettierignore +21 -0
- data/lib/kowl/templates/dotfiles/prettierrc.js +62 -0
- data/lib/kowl/templates/dotfiles/pryrc +7 -0
- data/lib/kowl/templates/dotfiles/rspec +3 -0
- data/lib/kowl/templates/dotfiles/rubocop.yml.tt +78 -0
- data/lib/kowl/templates/dotfiles/scss-lint.yml +132 -0
- data/lib/kowl/templates/dotfiles/simplecov +19 -0
- data/lib/kowl/templates/dotfiles/slim-lint.yml +23 -0
- data/lib/kowl/templates/dotfiles/slugignore +10 -0
- data/lib/kowl/templates/dotfiles/yamllint +7 -0
- data/lib/kowl/templates/dotfiles/yarnclean +46 -0
- data/lib/kowl/templates/lib/tasks/stats.rake +42 -0
- data/lib/kowl/templates/tests/factories/README.md +0 -0
- data/lib/kowl/templates/tests/factories/login_activity.rb +11 -0
- data/lib/kowl/templates/tests/factories/user.rb +11 -0
- data/lib/kowl/templates/tests/minitest/README.md +3 -0
- data/lib/kowl/templates/tests/minitest/application_system_test_case.rb +7 -0
- data/lib/kowl/templates/tests/minitest/controllers/pages_controller_test.rb +10 -0
- data/lib/kowl/templates/tests/minitest/models/login_activity_test.rb +8 -0
- data/lib/kowl/templates/tests/minitest/models/user_test.rb +15 -0
- data/lib/kowl/templates/tests/minitest/policies/login_activity_policy_test.rb +7 -0
- data/lib/kowl/templates/tests/minitest/policies/user_policy_test.rb +7 -0
- data/lib/kowl/templates/tests/minitest/support/capybara.rb +38 -0
- data/lib/kowl/templates/tests/minitest/support/database_cleaner.rb +20 -0
- data/lib/kowl/templates/tests/minitest/support/database_cleaner_support.rb +15 -0
- data/lib/kowl/templates/tests/minitest/support/deferred_garbage_collection.rb +21 -0
- data/lib/kowl/templates/tests/minitest/support/devise.rb +16 -0
- data/lib/kowl/templates/tests/minitest/support/factories.rb +6 -0
- data/lib/kowl/templates/tests/minitest/support/formulaic.rb +8 -0
- data/lib/kowl/templates/tests/minitest/support/helpers/devise_helper.rb +57 -0
- data/lib/kowl/templates/tests/minitest/support/papertrail.rb +17 -0
- data/lib/kowl/templates/tests/minitest/support/pundit.rb +0 -0
- data/lib/kowl/templates/tests/minitest/support/shoulda.rb +11 -0
- data/lib/kowl/templates/tests/minitest/support/simplecov.rb +8 -0
- data/lib/kowl/templates/tests/minitest/test_helper.rb +17 -0
- data/lib/kowl/templates/tests/rspec/README.md +9 -0
- data/lib/kowl/templates/tests/rspec/controllers/admin/application_controller_spec.rb +12 -0
- data/lib/kowl/templates/tests/rspec/controllers/admin/users_controller_spec.rb +14 -0
- data/lib/kowl/templates/tests/rspec/controllers/pages_controller_spec.rb +10 -0
- data/lib/kowl/templates/tests/rspec/features/README.md +15 -0
- data/lib/kowl/templates/tests/rspec/features/visitor_sign_up_spec.rb +25 -0
- data/lib/kowl/templates/tests/rspec/helpers/application_helper_spec.rb +7 -0
- data/lib/kowl/templates/tests/rspec/helpers/pages_helper_spec.rb +15 -0
- data/lib/kowl/templates/tests/rspec/models/login_activity_spec.rb +11 -0
- data/lib/kowl/templates/tests/rspec/models/user_spec.rb +21 -0
- data/lib/kowl/templates/tests/rspec/policies/login_activity_policy_spec.rb +59 -0
- data/lib/kowl/templates/tests/rspec/policies/user_policy_spec.rb +56 -0
- data/lib/kowl/templates/tests/rspec/rails_helper.rb +72 -0
- data/lib/kowl/templates/tests/rspec/requests/pages_spec.rb +11 -0
- data/lib/kowl/templates/tests/rspec/spec_helper.rb +96 -0
- data/lib/kowl/templates/tests/rspec/support/bullet.rb +17 -0
- data/lib/kowl/templates/tests/rspec/support/capybara.rb +37 -0
- data/lib/kowl/templates/tests/rspec/support/controller_testing.rb +10 -0
- data/lib/kowl/templates/tests/rspec/support/database_cleaner.rb +55 -0
- data/lib/kowl/templates/tests/rspec/support/deferred_garbage_collection.rb +32 -0
- data/lib/kowl/templates/tests/rspec/support/devise.rb +21 -0
- data/lib/kowl/templates/tests/rspec/support/factories.rb +5 -0
- data/lib/kowl/templates/tests/rspec/support/formulaic.rb +8 -0
- data/lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb +56 -0
- data/lib/kowl/templates/tests/rspec/support/papertrail.rb +5 -0
- data/lib/kowl/templates/tests/rspec/support/pi_ci.rb +6 -0
- data/lib/kowl/templates/tests/rspec/support/pundit.rb +6 -0
- data/lib/kowl/templates/tests/rspec/support/shoulda.rb +10 -0
- data/lib/kowl/templates/tests/rspec/support/sidekiq.rb +10 -0
- data/lib/kowl/templates/tests/rspec/support/simplecov.rb +7 -0
- data/lib/kowl/templates/tests/rspec/support/warden.rb +8 -0
- data/lib/kowl/templates/text_files/AUTHORS.md +4 -0
- data/lib/kowl/templates/text_files/CHANGELOG.md.tt +12 -0
- data/lib/kowl/templates/text_files/CODE_OF_CONDUCT.md +76 -0
- data/lib/kowl/templates/text_files/TODO.md +7 -0
- data/lib/kowl/templates/text_files/VERSION +1 -0
- data/lib/kowl/templates/text_files/humans.txt.tt +15 -0
- data/lib/kowl/templates/text_files/robots.txt.tt +6 -0
- data/lib/kowl/templates/text_files/security.txt +6 -0
- data/lib/kowl/version.rb +9 -0
- data/lib/kowl.rb +18 -0
- metadata +404 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module Kowl
|
7
|
+
class ActionGenerator < Kowl::Generators::Base
|
8
|
+
hide!
|
9
|
+
source_root File.expand_path(File.join('..', 'templates'), File.dirname(__FILE__))
|
10
|
+
class_option :database, type: :string, default: 'sqlite3'
|
11
|
+
class_option :simpleform, type: :boolean, default: false
|
12
|
+
class_option :skip_javascript, type: :boolean, default: false
|
13
|
+
hide!
|
14
|
+
|
15
|
+
# Because simpleform hasn't Actiontext input types yet, attribute type needs to be added in order for an input type to properly load
|
16
|
+
# => https://github.com/plataformatec/simple_form/issues/1638
|
17
|
+
def copy_simpleform_inputs
|
18
|
+
return nil unless options[:simpleform]
|
19
|
+
|
20
|
+
# If using simpleform tthis allows you to use rich_text_area input type (trix)
|
21
|
+
# ie: `= f.rich_text_area :body`
|
22
|
+
directory('app/inputs', 'app/inputs')
|
23
|
+
end
|
24
|
+
|
25
|
+
# Used to beign setting up action_text based on if options[:skip_javascript] is specified or not
|
26
|
+
def setup_action_text
|
27
|
+
# If javascript is being skipped, you'll only want to generate the migrations.
|
28
|
+
# => But if you're skipping javascript, you'll need to add actiontext javascript components yourself
|
29
|
+
if options[:skip_javascript]
|
30
|
+
rake 'action_text:copy_migrations'
|
31
|
+
else
|
32
|
+
rake 'action_text:install'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Setup and create ActiveStorage migrations
|
37
|
+
def setup_active_storage
|
38
|
+
rake 'active_storage:install'
|
39
|
+
end
|
40
|
+
|
41
|
+
# Correct issue with application index if using Oracle for the applications database
|
42
|
+
# This is because Oracle can only have an index of 30 characters long
|
43
|
+
# So oracle is being used we need to correct the migrations to remove the indexes with huge names
|
44
|
+
def correct_oracle_indexes
|
45
|
+
return nil unless options[:database] == 'oracle'
|
46
|
+
|
47
|
+
# Fix - index_active_storage_attachments_uniqueness
|
48
|
+
Dir.glob('db/migrate/**_create_active_storage_tables.active_storage.rb').select do |migration_file|
|
49
|
+
gsub_file migration_file, 't.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true', 't.index [ :record_type, :record_id, :name, :blob_id ], name: "index_activestorage", unique: true'
|
50
|
+
end
|
51
|
+
Dir.glob('db/migrate/**_create_action_text_tables.action_text.rb').select do |migration_file|
|
52
|
+
gsub_file migration_file, 't.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true', 't.index [ :record_type, :record_id, :name ], name: "index_actiontext", unique: true'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Correct issue with the applications index if using SQLserver for the application database
|
57
|
+
# This is because the active_record migration flagges an error for foreign_key constraints for using blob_ids as the index
|
58
|
+
def correct_sqlserver_indexes
|
59
|
+
return nil unless options[:database] == 'sqlserver'
|
60
|
+
|
61
|
+
Dir.glob('db/migrate/**_create_active_storage_tables.active_storage.rb').select do |migration_file|
|
62
|
+
gsub_file migration_file, 't.foreign_key :active_storage_blobs, column: :blob_id', '# t.foreign_key :active_storage_blobs, column: :blob_id'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# If using javascript this adds trix's import to the applications SCSS file
|
67
|
+
def add_trix_stylesheets
|
68
|
+
return '' if options[:skip_javascript]
|
69
|
+
|
70
|
+
append_to_file('app/assets/stylesheets/application.scss', "\n@import 'trix/dist/trix';")
|
71
|
+
end
|
72
|
+
|
73
|
+
# Add default ActiveStorage FileType and FileSize limits for uploading through trix (this can easily be changed)
|
74
|
+
# Limit trix mimetyps to jpeg and png
|
75
|
+
# Limit max filesizes to 2MB
|
76
|
+
def limit_file_upload_types
|
77
|
+
return nil if options[:skip_javascript]
|
78
|
+
|
79
|
+
trix_action_storage = <<~TRIX_STORAGE
|
80
|
+
window.addEventListener('trix-file-accept', function(event) {
|
81
|
+
const acceptedTypes = ['image/jpg', 'image/jpeg', 'image/png']
|
82
|
+
const maxFileSize = (1024 * 1024) * 2 // 2MB
|
83
|
+
// Limit trix file upload types to the mimetypes listed below
|
84
|
+
if (!acceptedTypes.includes(event.file.type)) {
|
85
|
+
event.preventDefault()
|
86
|
+
alert('Only support attachment of jpeg or png files')
|
87
|
+
}
|
88
|
+
// Limit trix max filesize limits to 2MB
|
89
|
+
if (event.file.size > maxFileSize) {
|
90
|
+
event.preventDefault()
|
91
|
+
alert('Only support of attachment files upto size 2MB!')
|
92
|
+
}
|
93
|
+
})
|
94
|
+
TRIX_STORAGE
|
95
|
+
append_to_file('app/javascript/packs/application.js', "\n\n#{trix_action_storage}")
|
96
|
+
end
|
97
|
+
|
98
|
+
# def update_migration_fields
|
99
|
+
# Dir.glob('db/migrate/**_create_action_text_tables.action_text.rb').select { |e| update_action_migration(e, 'db/migrations/create_action_text_tables.action_text.rb.tt') }
|
100
|
+
# Dir.glob('db/migrate/**_create_active_storage_tables.active_storage.rb').select { |e| update_action_migration(e, 'db/migrations/create_active_storage_tables.active_storage.rb.tt') }
|
101
|
+
# end
|
102
|
+
|
103
|
+
# private
|
104
|
+
|
105
|
+
# def update_action_migration(migration_file, template_file)
|
106
|
+
# return nil if migration_file.blank? || template_file.blank?
|
107
|
+
# return false unless file_exists?(migration_file)
|
108
|
+
#
|
109
|
+
# # override prexisting migration with template contents
|
110
|
+
# template template_file, migration_file, force: true
|
111
|
+
# end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module Kowl
|
7
|
+
class AdminGenerator < Kowl::Generators::Base
|
8
|
+
hide!
|
9
|
+
source_root File.expand_path(File.join('..', 'templates', 'app'), File.dirname(__FILE__))
|
10
|
+
class_option :database, type: :string, default: 'sqlite3'
|
11
|
+
class_option :skip_javascript, type: :boolean, default: false
|
12
|
+
class_option :skip_turbolinks, type: :boolean, default: false
|
13
|
+
class_option :uuid, type: :boolean, default: false
|
14
|
+
|
15
|
+
# NOTE: In most of these I user the administrates native generator, before replacing them
|
16
|
+
# that way if any tests are generates they will be available as well
|
17
|
+
# This is skipped when using UUID's because by default the dashbooards try to us integers for ID's
|
18
|
+
def generate_admin_dashboard
|
19
|
+
generate('administrate:install') unless options[:uuid]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Generate custom field attribute types to show a persons gravatar
|
23
|
+
def generate_avatar_fields
|
24
|
+
generate('administrate:field gravatar')
|
25
|
+
remove_dir('app/fields')
|
26
|
+
copy_file('app/fields/gravatar_field.rb', force: true)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Generate support for the action_text field type to be supported with administrate
|
30
|
+
def generate_action_text_fields
|
31
|
+
generate('administrate:field rich_text_area')
|
32
|
+
copy_file('app/fields/rich_text_area_field.rb', force: true)
|
33
|
+
end
|
34
|
+
|
35
|
+
# We copy dashboards over after the fields are generates.
|
36
|
+
# Otherwise there will be an error about field types unknown (GravatarField)
|
37
|
+
def copy_dashboards
|
38
|
+
# Replace with dashboards showing less user data (this is because even admin and staff should be able to add, edit, or modify certain attributes)
|
39
|
+
remove_dir('app/dashboards/')
|
40
|
+
# This is because if UUID's are used the dashboards try to render them as integers.
|
41
|
+
# Otherwise they'll be displayed as strings
|
42
|
+
mk_dir('app/dashboards')
|
43
|
+
%i[login_activity user rich_text_body].map { |dashboard| template "dashboards/#{dashboard}_dashboard.rb.tt", "app/dashboards/#{dashboard}_dashboard.rb" }
|
44
|
+
end
|
45
|
+
|
46
|
+
# this is to replace default generated gravatar views with ones that will actually show the user gravatars
|
47
|
+
def replace_field_views
|
48
|
+
remove_dir('app/views/fields')
|
49
|
+
directory('views/fields', 'app/views/fields', force: true)
|
50
|
+
end
|
51
|
+
|
52
|
+
# This is because admin controllers should only be viewable if a user is a superuser or staff member
|
53
|
+
def replace_admin_controllers
|
54
|
+
remove_dir('app/controllers/admin')
|
55
|
+
directory('controllers/admin', 'app/controllers/admin', force: true)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Copy views for administrate dependant on if the app will use javascript or not
|
59
|
+
def copy_admin_views
|
60
|
+
if options[:skip_javascript]
|
61
|
+
remove_file('app/views/admin/application/_javascript.html.erb')
|
62
|
+
else
|
63
|
+
copy_file('views/admin/views/application/_javascript.html.erb', 'app/views/admin/application/_javascript.html.erb')
|
64
|
+
end
|
65
|
+
template('views/layouts/admin.html.erb.tt', 'app/views/layouts/admin/application.html.erb')
|
66
|
+
end
|
67
|
+
|
68
|
+
# Unless javascript is skipped this adds the TRIX SCSS the to administrate stylesheets
|
69
|
+
def add_trix_scss
|
70
|
+
return nil if options[:skip_javascript]
|
71
|
+
|
72
|
+
trix_import_str = <<~TRIX_SCSS
|
73
|
+
// Used for creating ActionText content editors
|
74
|
+
@import 'trix/dist/trix';
|
75
|
+
// Used for date/time selection boxes in the admin interface
|
76
|
+
@import 'flatpickr/dist/flatpickr.min';
|
77
|
+
|
78
|
+
// We need to override trix.css’s image gallery styles to accommodate the
|
79
|
+
// <action-text-attachment> element we wrap around attachments. Otherwise,
|
80
|
+
// images in galleries will be squished by the max-width: 33%; rule.
|
81
|
+
.trix-content {
|
82
|
+
.attachment-gallery {
|
83
|
+
>action-text-attachment,
|
84
|
+
>.attachment {
|
85
|
+
flex: 1 0 33%;
|
86
|
+
padding: 0 0.5em;
|
87
|
+
max-width: 33%;
|
88
|
+
}
|
89
|
+
&.attachment-gallery--2,
|
90
|
+
&.attachment-gallery--4 {
|
91
|
+
>action-text-attachment,
|
92
|
+
>.attachment {
|
93
|
+
flex-basis: 50%;
|
94
|
+
max-width: 50%;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
action-text-attachment {
|
99
|
+
.attachment {
|
100
|
+
padding: 0 !important;
|
101
|
+
max-width: 100% !important;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
.field-unit--rich-text-area-field {
|
106
|
+
.field-unit__field {
|
107
|
+
width: 80%;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
TRIX_SCSS
|
111
|
+
append_to_file('app/assets/stylesheets/administrate/application.scss', trix_import_str)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module Kowl
|
7
|
+
class AssetsGenerator < Kowl::Generators::Base
|
8
|
+
hide!
|
9
|
+
source_root File.expand_path(File.join('..', 'templates', 'app', 'assets'), File.dirname(__FILE__))
|
10
|
+
class_option :framework, type: :string, default: 'bootstrap', enum: %w[bootstrap semantic none]
|
11
|
+
class_option :noauth, type: :boolean, default: false
|
12
|
+
class_option :skip_javascript, type: :boolean, default: false
|
13
|
+
class_option :skip_mailer, type: :boolean, default: false
|
14
|
+
class_option :skip_turbolinks, type: :boolean, default: false
|
15
|
+
|
16
|
+
# If javascript is being used, this will setup jquery to be usable through webpack
|
17
|
+
def setup_jquery_with_webpack
|
18
|
+
return nil if options[:skip_javascript]
|
19
|
+
|
20
|
+
add_package('jquery')
|
21
|
+
append_to_file('app/javascript/packs/application.js', "\nrequire('jquery');\n")
|
22
|
+
webpack_jquery_str = <<~JQUERY
|
23
|
+
const webpack = require('webpack')
|
24
|
+
environment.plugins.prepend('Provide',
|
25
|
+
new webpack.ProvidePlugin({
|
26
|
+
$: 'jquery/src/jquery',
|
27
|
+
jQuery: 'jquery/src/jquery'
|
28
|
+
})
|
29
|
+
)
|
30
|
+
JQUERY
|
31
|
+
inject_into_file('config/webpack/environment.js', webpack_jquery_str, after: "const { environment } = require('@rails/webpacker')\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
# This allows us to generate JS assets compressed with brotli and zopfil in production
|
35
|
+
# Which dramatically reduces text based asset sizes
|
36
|
+
# - https://github.com/tootsuite/mastodon/blob/master/config/webpack/production.js
|
37
|
+
# - https://github.com/rails/webpacker/blob/9e671a3ebe368cfdc624309a9b4a55e998f87186/package/environments/production.js
|
38
|
+
def setup_production_asset_compression
|
39
|
+
return nil if options[:skip_javascript]
|
40
|
+
|
41
|
+
# The compression-webpack-plugin package is included in @rails/webpacker.
|
42
|
+
# => But this lets us easily access it from our webpacker config
|
43
|
+
add_package('compression-webpack-plugin brotli-webpack-plugin @gfx/zopfli')
|
44
|
+
webpack_plugins_str = <<~BROTLI
|
45
|
+
// Compress the heck out of any static assets included by webpacker (using Brotlie)
|
46
|
+
environment.plugins.append('BrotliCompression',
|
47
|
+
new CompressionPlugin({
|
48
|
+
filename: '[path].br[query]',
|
49
|
+
algorithm: 'brotliCompress',
|
50
|
+
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/,
|
51
|
+
compressionOptions: {
|
52
|
+
level: 11
|
53
|
+
},
|
54
|
+
cache: true,
|
55
|
+
threshold: 10240,
|
56
|
+
minRatio: 0.8,
|
57
|
+
deleteOriginalAssets: false,
|
58
|
+
})
|
59
|
+
)
|
60
|
+
|
61
|
+
// Override default compression with Zopfli compression
|
62
|
+
environment.plugins.append('Compression',
|
63
|
+
new CompressionPlugin({
|
64
|
+
filename: '[path].gz[query]',
|
65
|
+
algorithm(input, compressionOptions, callback) {
|
66
|
+
return zopfli.gzip(input, compressionOptions, callback);
|
67
|
+
},
|
68
|
+
cache: true,
|
69
|
+
threshold: 8192,
|
70
|
+
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/,
|
71
|
+
}),
|
72
|
+
)
|
73
|
+
BROTLI
|
74
|
+
|
75
|
+
include_plugins_str = <<~PLUGINS
|
76
|
+
const CompressionPlugin = require('compression-webpack-plugin'); // General webpacker library containing compression methods
|
77
|
+
const zopfli = require('@gfx/zopfli'); // Zopfli is used to increase gzip compression ratio for gzip
|
78
|
+
PLUGINS
|
79
|
+
|
80
|
+
inject_into_file('config/webpack/production.js', "#{include_plugins_str}\n\n#{webpack_plugins_str}", after: "const environment = require('./environment')\n")
|
81
|
+
end
|
82
|
+
|
83
|
+
# Unless skipping javascript, this adds some basic linter packages to the webpacker dev environments
|
84
|
+
def setup_js_linters
|
85
|
+
return nil if options[:skip_javascript]
|
86
|
+
|
87
|
+
add_package('eslint prettier prettierrc --dev')
|
88
|
+
end
|
89
|
+
|
90
|
+
# If the application will be using Bootstrap or SemanticUI, this includes their JS files in the javascript packs file
|
91
|
+
def setup_framework_js
|
92
|
+
return nil if options[:skip_javascript]
|
93
|
+
|
94
|
+
if options[:framework] == 'bootstrap'
|
95
|
+
add_package('bootstrap popper.js')
|
96
|
+
js_str = <<~BOOTSTRAP
|
97
|
+
require('bootstrap');
|
98
|
+
require('popper.js');\n
|
99
|
+
BOOTSTRAP
|
100
|
+
elsif options[:framework] == 'semantic'
|
101
|
+
# The version is used because code semantic-ui and fomantic-ui packages require you to build them with gulp
|
102
|
+
# => This makes it easier to get started without a ton of additional setup
|
103
|
+
copy_file('app/javascript/packs/semantic.js', 'app/javascript/packs/semantic.js')
|
104
|
+
js_str = <<~SEMANTIC
|
105
|
+
import Semantic from './semantic';
|
106
|
+
SEMANTIC
|
107
|
+
end
|
108
|
+
append_to_file('app/javascript/packs/application.js', js_str) unless js_str.blank?
|
109
|
+
end
|
110
|
+
|
111
|
+
# Add Bootstrap/Semantic JS to the application.js file
|
112
|
+
def add_framework_js_to_webpack
|
113
|
+
return nil if options[:skip_javascript] || !%w[bootstrap semantic].include?(options[:framework])
|
114
|
+
|
115
|
+
# If you prefere to pass skip_turbolinks, have JS load with jQuery on the page load
|
116
|
+
js_load_str = if options[:skip_turbolinks]
|
117
|
+
'$(document).ready(function() {'
|
118
|
+
else
|
119
|
+
'$(document).on("turbolinks:load", function() {'
|
120
|
+
end
|
121
|
+
|
122
|
+
if options[:framework] == 'bootstrap'
|
123
|
+
framework_js = <<~BOOTSTRAPJS
|
124
|
+
#{js_load_str}
|
125
|
+
// This will dismiss any and all flash alerts after 3 seconds
|
126
|
+
window.setTimeout(function() {
|
127
|
+
$('.alert').fadeTo(1000, 0).slideUp(1000, function() {
|
128
|
+
$(this).remove();
|
129
|
+
});
|
130
|
+
}, 3000);
|
131
|
+
});
|
132
|
+
BOOTSTRAPJS
|
133
|
+
elsif options[:framework] == 'semantic'
|
134
|
+
framework_js = <<~SEMANTICJS
|
135
|
+
#{js_load_str}
|
136
|
+
// Allow the user to close the flash messages
|
137
|
+
$('.message .close')
|
138
|
+
.on('click', function(){
|
139
|
+
$(this).closest('.message').transition('fade');
|
140
|
+
});
|
141
|
+
|
142
|
+
// Automatically close flash messages after 3 seconds
|
143
|
+
window.setTimeout(function() {
|
144
|
+
$('.message').transition('fade');
|
145
|
+
}, 3000);
|
146
|
+
});
|
147
|
+
SEMANTICJS
|
148
|
+
end
|
149
|
+
append_to_file('app/javascript/packs/application.js', framework_js) unless options[:skip_javascript]
|
150
|
+
end
|
151
|
+
|
152
|
+
# If using bootstrap or semsanitic this includes some additional SCSS files with the application
|
153
|
+
def copy_stylesheets
|
154
|
+
return nil unless %w[bootstrap semantic].include? options[:framework]
|
155
|
+
|
156
|
+
# Remove old application stylesheets and replace with new ones
|
157
|
+
remove_file 'app/assets/stylesheets/application.css'
|
158
|
+
directory "stylesheets/#{options[:framework]}", 'app/assets/stylesheets', force: true
|
159
|
+
remove_file 'app/assets/stylesheets/application-mailer.scss' if options[:skip_mailer]
|
160
|
+
end
|
161
|
+
|
162
|
+
# Adds known css files to css assets to precompile
|
163
|
+
def add_assets_to_precompile
|
164
|
+
add_to_assets('application.css')
|
165
|
+
return nil if options[:noauth]
|
166
|
+
|
167
|
+
add_to_assets('administrate/application.css')
|
168
|
+
end
|
169
|
+
|
170
|
+
# If using webpacker, this will generate it's JS webpacker files for the application
|
171
|
+
def add_admin_webpacker_assets
|
172
|
+
return nil if options[:noauth] || options[:skip_javascript]
|
173
|
+
|
174
|
+
template('app/javascript/packs/administrate.js', 'app/javascript/packs/administrate.js')
|
175
|
+
copy_file('app/javascript/administrate/index.js', 'app/javascript/administrate/index.js')
|
176
|
+
|
177
|
+
template('app/javascript/administrate/components/date_time_picker.js.tt', 'app/javascript/administrate/components/date_time_picker.js')
|
178
|
+
template('app/javascript/administrate/components/table.js.tt', 'app/javascript/administrate/components/table.js')
|
179
|
+
end
|
180
|
+
|
181
|
+
# If using webpacker allow CSS Extraction for CSS, SCSS, and SASS to work when compiling webpacker assets
|
182
|
+
def enable_css_extraction
|
183
|
+
return nil if options[:skip_javascript]
|
184
|
+
|
185
|
+
replace_string_in_file('config/webpacker.yml', "[\s]?extract_css[\:][\s]?false[\s]?", ' extract_css: true') unless options[:skip_javascript]
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rails/generators'
|
5
|
+
require_relative '../actions'
|
6
|
+
require_relative '../docker'
|
7
|
+
|
8
|
+
# https://api.rubyonrails.org/v5.2/classes/Rails/Generators/Base.html
|
9
|
+
module Kowl
|
10
|
+
module Generators
|
11
|
+
class Base < Rails::Generators::Base
|
12
|
+
include Kowl::Actions
|
13
|
+
include Kowl::Docker
|
14
|
+
hide!
|
15
|
+
|
16
|
+
# Resolve to using the default Rails gem templates as a fallback in case source_path doesn't exist for generator
|
17
|
+
# NOTE: Do no enable this, as it tends to overwrite the default rails gem past for pulling templates from (ie: database stuff)
|
18
|
+
def self.default_source_root
|
19
|
+
File.expand_path(File.join('..', 'templates'), __dir__)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Used for setting RAILS default source_path
|
23
|
+
# As well as adding the gems source_path to the generators
|
24
|
+
# src: https://github.com/solidusio/solidus/blob/master/core/lib/generators/spree/dummy/dummy_generator.rb#L15
|
25
|
+
def self.source_paths
|
26
|
+
super
|
27
|
+
paths = superclass.source_paths
|
28
|
+
paths << File.expand_path(File.join('..', 'templates'), __dir__)
|
29
|
+
paths.flatten.uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Return a cleaned up version of the name of the application being generated
|
35
|
+
def app_name
|
36
|
+
Rails.app_class.parent_name.demodulize.underscore.dasherize
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module Kowl
|
7
|
+
class ConfigGenerator < Kowl::Generators::Base
|
8
|
+
hide!
|
9
|
+
source_root File.expand_path(File.join('..', 'templates', 'config', 'initializers'), File.dirname(__FILE__))
|
10
|
+
class_option :database, type: :string, default: 'sqlite3'
|
11
|
+
class_option :encrypt, type: :boolean, default: false
|
12
|
+
class_option :framework, type: :string, default: 'bootstrap', enum: %w[bootstrap semantic none]
|
13
|
+
class_option :noauth, type: :boolean, default: false
|
14
|
+
class_option :skip_docker, type: :boolean, default: false
|
15
|
+
class_option :skip_erd, type: :boolean, default: false
|
16
|
+
class_option :skip_pagination, type: :boolean, default: false
|
17
|
+
class_option :skip_sidekiq, type: :boolean, default: false
|
18
|
+
class_option :skip_tests, type: :boolean, default: false
|
19
|
+
class_option :simpleform, type: :boolean, default: false
|
20
|
+
class_option :template_engine, type: :string, default: 'erb', enum: %w[erb slim haml]
|
21
|
+
class_option :test_engine, type: :string, default: 'rspec', enum: %w[minitest rspec none]
|
22
|
+
class_option :uuid, type: :boolean, default: false
|
23
|
+
|
24
|
+
# Generate simpleform config early, so rails generators don't output a ton of simpleform garbage everytime a generator is ran
|
25
|
+
def setup_simpleform
|
26
|
+
return unless options[:simpleform]
|
27
|
+
|
28
|
+
case options[:framework]
|
29
|
+
when 'bootstrap'
|
30
|
+
generate 'simple_form:install', '--bootstrap', '--force'
|
31
|
+
when 'semantic'
|
32
|
+
copy_file 'simpleform/semantic.rb', 'config/initializers/simple_form.rb', force: true
|
33
|
+
else
|
34
|
+
generate 'simple_form:install', '--force'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generate application initializer for devise
|
39
|
+
def copy_devise_config
|
40
|
+
# Encrypt devise passwords using Argon for better password security
|
41
|
+
copy_file 'devise_argon2.rb', 'config/initializers/devise_argon2.rb' unless options[:noauth]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Setup autoprefixer basic configuration
|
45
|
+
def copy_autoprefixer
|
46
|
+
copy_file '../autoprefixer.yml', 'config/autoprefixer.yml', force: true
|
47
|
+
end
|
48
|
+
|
49
|
+
# Generate application initializer for faker/applicatiton tests
|
50
|
+
def copy_faker_config
|
51
|
+
copy_file('faker.rb', 'config/initializers/faker.rb', force: true) unless options[:skip_tests]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Generate application initializer for geocoder
|
55
|
+
def copy_geocoder_config
|
56
|
+
return nil if options[:noauth]
|
57
|
+
|
58
|
+
copy_file('geocoder.rb', 'config/initializers/geocoder.rb')
|
59
|
+
GeoDB.perform(Rails.root)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Generate several application initializers to cleanup to make the application easier to manage
|
63
|
+
def copy_initializers
|
64
|
+
files = %w[bullet logging lograge oj sass]
|
65
|
+
files.push('slim') if options['template_engine'] == 'slim'
|
66
|
+
|
67
|
+
files.map { |file| copy_file "#{file}.rb", "config/initializers/#{file}.rb" }
|
68
|
+
end
|
69
|
+
|
70
|
+
# Generate initializers for rack_attack depending on the applications requirements (devise, sidekiq, etc)
|
71
|
+
def copy_rack_attack
|
72
|
+
# it's a template because it has routes that may not be used if --noauth is specified
|
73
|
+
template('rack_attack.rb.tt', 'config/initializers/rack_attack.rb')
|
74
|
+
end
|
75
|
+
|
76
|
+
# Generatet initializer for pagy if pagination will be used in the application
|
77
|
+
def copy_pagy_config
|
78
|
+
template('pagy.rb.tt', 'config/initializers/pagy.rb', force: true) unless options[:skip_pagination]
|
79
|
+
end
|
80
|
+
|
81
|
+
# Generaet version file used for docker application versioning and deployment
|
82
|
+
def create_version_file
|
83
|
+
create_file('.version', '0.0.1')
|
84
|
+
end
|
85
|
+
|
86
|
+
# Setup Rack::Timeout using slowpoke, in order to kill slow requests
|
87
|
+
def setup_slowpoke
|
88
|
+
generate('slowpoke:install')
|
89
|
+
end
|
90
|
+
|
91
|
+
# This sets the production log_level to info, by default all environments have a log_level of debug.
|
92
|
+
# And this can be dangerous when your application logs are collecting user params and showing Mailers within the logs
|
93
|
+
# https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels
|
94
|
+
def set_production_loglevel
|
95
|
+
inject_into_file('config/environments/production.rb', ' # ', before: " config.log_level = :debug\n")
|
96
|
+
inject_into_file('config/environments/production.rb', "\n config.log_level = :info\n", after: 'config.log_level = :debug')
|
97
|
+
end
|
98
|
+
|
99
|
+
# Generates additional config the appliations config/application.rb file based on the current options (test_engine, template_engine, etc.)
|
100
|
+
def application_config
|
101
|
+
# Moves generating of default stylesheets and set sthe default timezone
|
102
|
+
# => add configuration to config/application.rb
|
103
|
+
# => https://apidock.com/rails/Rails/Generators
|
104
|
+
sidekiq_config = (options[:skip_sidekiq] ? '' : 'config.active_job.queue_adapter = :sidekiq')
|
105
|
+
cache_storage_config = (options[:skip_sidekiq] ? 'config.cache_store = :mem_cache_store' : "config.cache_storage = :redis_cache_store, { driver: :hiredis, url: ENV.fetch('REDIS_URL'){ 'redis://localhost:6379/0' } }")
|
106
|
+
app_config = <<-CONFIG
|
107
|
+
# Set the applications timezone
|
108
|
+
config.time_zone = 'UTC'
|
109
|
+
config.active_record.default_timezone = :local
|
110
|
+
#{sidekiq_config}
|
111
|
+
#{cache_storage_config}
|
112
|
+
|
113
|
+
#{options[:skip_docker] ? '' : "# If you change this to use imagemagick, you'll need to update your Dockerfile as well"}
|
114
|
+
# => https://api.rubyonrails.org/classes/ActiveStorage/Variant.html
|
115
|
+
config.active_storage.variant_processor = :vips
|
116
|
+
CONFIG
|
117
|
+
insert_into_file 'config/application.rb', optimize_indentation(app_config, 4), after: /\s?config.load_defaults\s(\d\S\d)\n/
|
118
|
+
end
|
119
|
+
|
120
|
+
# Generate initializer for the applications generator config
|
121
|
+
def generate_generators_config
|
122
|
+
template 'generators.rb.tt', 'config/initializers/generators.rb', force: true
|
123
|
+
end
|
124
|
+
|
125
|
+
# Generate initializer for application middleware
|
126
|
+
def setup_middleware_config
|
127
|
+
copy_file 'middleware.rb', 'config/initializers/middleware.rb', force: true
|
128
|
+
end
|
129
|
+
|
130
|
+
# Generate initializer for using administrate with the application
|
131
|
+
def copy_administate_config
|
132
|
+
template('administrate.rb.tt', 'config/initializers/administrate.rb') unless options[:noauth]
|
133
|
+
end
|
134
|
+
|
135
|
+
# Run the ERD generator, so the application will generate a new ERB when migrations are added/modified
|
136
|
+
def setup_erd
|
137
|
+
return nil if options[:skip_erd]
|
138
|
+
|
139
|
+
generate('erd:install')
|
140
|
+
end
|
141
|
+
|
142
|
+
##############################
|
143
|
+
# Securtiy Config
|
144
|
+
##############################
|
145
|
+
|
146
|
+
# If wanting to encrypt database attributes, generate lockbox initializer
|
147
|
+
def copy_lockbox_config
|
148
|
+
# Lockbox will be used to secure sensative data attributes throughout the application
|
149
|
+
# => https://github.com/ankane/lockbox
|
150
|
+
copy_file('lockbox.rb', 'config/initializers/lockbox.rb') if options[:encrypt]
|
151
|
+
end
|
152
|
+
|
153
|
+
# Generate a logstop application initializer
|
154
|
+
# To filter out sensative parameteres before they are passed to the applications logs
|
155
|
+
def copy_logstop_config
|
156
|
+
copy_file 'logstop.rb', 'config/initializers/logstop.rb'
|
157
|
+
end
|
158
|
+
|
159
|
+
# Add additional parameters to be filtered from logs
|
160
|
+
def add_filtered_parameters
|
161
|
+
append_to_file('config/initializers/filter_parameter_logging.rb', 'Rails.application.config.filter_parameters += %i[email ip]')
|
162
|
+
end
|
163
|
+
|
164
|
+
# Setup a basic CORS policy for application JS interactions
|
165
|
+
def setup_cors
|
166
|
+
cors_str = <<~CORS
|
167
|
+
Rails.application.config.content_security_policy do |policy|
|
168
|
+
if Rails.env.development?
|
169
|
+
policy.script_src :self, :https, :unsafe_eval
|
170
|
+
|
171
|
+
policy.connect_src :self, :https, 'http://localhost:3000', 'ws://localhost:3000', 'http://localhost:3000', 'ws://localhost:3000'
|
172
|
+
else
|
173
|
+
policy.script_src :self, :https
|
174
|
+
end
|
175
|
+
end
|
176
|
+
CORS
|
177
|
+
append_to_file('config/initializers/content_security_policy.rb', cors_str)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|