rails_app_generator 0.0.5 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.vscode/settings.json +3 -0
  4. data/CHANGELOG.md +23 -0
  5. data/README.md +9 -0
  6. data/after_templates/README.md +3 -0
  7. data/after_templates/___base_template.rb +1 -0
  8. data/after_templates/___r7_hotwire.rb +1 -0
  9. data/after_templates/rag_bootstrap/application-yield.html.erb +5 -0
  10. data/after_templates/rag_bootstrap/application.html.erb +4 -0
  11. data/after_templates/rag_bootstrap/component-cards-fancy.css +84 -0
  12. data/after_templates/rag_bootstrap/component-cards-fancy.html +80 -0
  13. data/after_templates/rag_bootstrap/component-cards-staff.css +90 -0
  14. data/after_templates/rag_bootstrap/component-cards-staff.html +140 -0
  15. data/after_templates/rag_bootstrap/component-cards-styled.html +31 -0
  16. data/after_templates/rag_bootstrap/component-footer.html +34 -0
  17. data/after_templates/rag_bootstrap/component-hero.html +15 -0
  18. data/after_templates/rag_bootstrap/component-nav.html +36 -0
  19. data/after_templates/rag_bootstrap/custom-bootstrap-import.scss +5 -0
  20. data/after_templates/rag_bootstrap/custom-using-css.css +3 -0
  21. data/after_templates/rag_bootstrap/custom-using-scss.scss +5 -0
  22. data/after_templates/rag_bootstrap/manifest.js +3 -0
  23. data/after_templates/rag_bootstrap.rb +1 -0
  24. data/after_templates/rag_simple.rb +25 -0
  25. data/after_templates/rag_tailwind.rb +74 -0
  26. data/exe/rag +41 -0
  27. data/lib/rails_app_generator/add_on.rb +73 -0
  28. data/lib/rails_app_generator/addons/annotate.rb +15 -0
  29. data/lib/rails_app_generator/addons/continuous_integration.rb +14 -0
  30. data/lib/rails_app_generator/addons/devise.rb +50 -0
  31. data/lib/rails_app_generator/addons/docker.rb +14 -0
  32. data/lib/rails_app_generator/addons/docker_compose.rb +13 -0
  33. data/lib/rails_app_generator/addons/dotenv.rb +13 -0
  34. data/lib/rails_app_generator/addons/factory_bot.rb +19 -0
  35. data/lib/rails_app_generator/addons/foreman.rb +15 -0
  36. data/lib/rails_app_generator/addons/generators.rb +31 -0
  37. data/lib/rails_app_generator/addons/high_voltage.rb +15 -0
  38. data/lib/rails_app_generator/addons/inline_svg.rb +11 -0
  39. data/lib/rails_app_generator/addons/irbrc.rb +13 -0
  40. data/lib/rails_app_generator/addons/lograge.rb +13 -0
  41. data/lib/rails_app_generator/addons/pundit.rb +16 -0
  42. data/lib/rails_app_generator/addons/rspec.rb +17 -0
  43. data/lib/rails_app_generator/addons/rubocop.rb +13 -0
  44. data/lib/rails_app_generator/addons/scaffold.rb +15 -0
  45. data/lib/rails_app_generator/addons/services.rb +13 -0
  46. data/lib/rails_app_generator/addons/sidekiq.rb +18 -0
  47. data/lib/rails_app_generator/addons/stimulus.rb +15 -0
  48. data/lib/rails_app_generator/addons/stimulus_components.rb +33 -0
  49. data/lib/rails_app_generator/addons/tailwind.rb +22 -0
  50. data/lib/rails_app_generator/addons/views.rb +21 -0
  51. data/lib/rails_app_generator/app_builder.rb +7 -5
  52. data/lib/rails_app_generator/app_generator.rb +187 -99
  53. data/lib/rails_app_generator/context.rb +75 -0
  54. data/lib/rails_app_generator/dependencies.rb +34 -0
  55. data/lib/rails_app_generator/notes/a1.txt +1 -1
  56. data/lib/rails_app_generator/notes/a2.txt +1 -1
  57. data/lib/rails_app_generator/notes/kw01-b.txt +86 -0
  58. data/lib/rails_app_generator/notes/kw01.txt +91 -0
  59. data/lib/rails_app_generator/options/map_option_string.rb +2 -0
  60. data/lib/rails_app_generator/options/rails_options.rb +52 -32
  61. data/lib/rails_app_generator/starter.rb +17 -8
  62. data/lib/rails_app_generator/version.rb +1 -1
  63. data/lib/rails_app_generator.rb +5 -1
  64. data/package-lock.json +2 -2
  65. data/package.json +1 -1
  66. data/profiles/rag-add-some-pages.json +11 -0
  67. data/profiles/rag-bootstrap.json +12 -0
  68. data/profiles/rag-simple.json +11 -0
  69. data/profiles/rag-tailwind.json +12 -0
  70. data/templates/README.md.erb +43 -0
  71. data/templates/addons/annotate/auto_annotate_models.rake +60 -0
  72. data/templates/addons/continuous_integration/.github/workflows/build.yml.erb +49 -0
  73. data/templates/addons/devise/app/views/devise/confirmations/new.html.erb +24 -0
  74. data/templates/addons/devise/app/views/devise/passwords/edit.html.erb +34 -0
  75. data/templates/addons/devise/app/views/devise/passwords/new.html.erb +23 -0
  76. data/templates/addons/devise/app/views/devise/registrations/edit.html.erb +62 -0
  77. data/templates/addons/devise/app/views/devise/registrations/new.html.erb +45 -0
  78. data/templates/addons/devise/app/views/devise/sessions/new.html.erb +33 -0
  79. data/templates/addons/devise/app/views/devise/shared/_error_messages.html.erb +15 -0
  80. data/templates/addons/devise/app/views/devise/shared/_form_wrap.html.erb +5 -0
  81. data/templates/addons/devise/app/views/devise/shared/_links.html.erb +25 -0
  82. data/templates/addons/devise/app/views/devise/unlocks/new.html.erb +22 -0
  83. data/templates/addons/docker/.dockerignore.erb +51 -0
  84. data/templates/addons/docker/Dockerfile.erb +45 -0
  85. data/templates/addons/docker_compose/docker-compose.yml.erb +21 -0
  86. data/templates/addons/dotenv/.env.development.erb +3 -0
  87. data/templates/addons/foreman/.foreman.erb +1 -0
  88. data/templates/addons/foreman/Procfile.dev.erb +7 -0
  89. data/templates/addons/foreman/Procfile.erb +4 -0
  90. data/templates/addons/generators/lib/generators/rails/navigation/USAGE +6 -0
  91. data/templates/addons/generators/lib/generators/rails/navigation/navigation_generator.rb +16 -0
  92. data/templates/addons/generators/lib/generators/rails/scaffold_controller_generator.rb +12 -0
  93. data/templates/addons/high_voltage/config/initializers/high_voltage.rb +6 -0
  94. data/templates/addons/irbrc/.irbrc.erb +13 -0
  95. data/templates/addons/lograge/config/initializers/lograge.rb +5 -0
  96. data/templates/addons/pundit/app/controllers/authorized_controller.rb.erb +10 -0
  97. data/templates/addons/pundit/app/policies/application_policy.rb +57 -0
  98. data/templates/addons/rspec/spec/rails_helper.rb +26 -0
  99. data/templates/addons/rspec/spec/spec_helper.rb +61 -0
  100. data/templates/addons/rubocop/.rubocop.yml.erb +37 -0
  101. data/templates/addons/scaffold/lib/templates/erb/scaffold/_form.html.erb +39 -0
  102. data/templates/addons/scaffold/lib/templates/erb/scaffold/edit.html.erb +7 -0
  103. data/templates/addons/scaffold/lib/templates/erb/scaffold/index.html.erb +34 -0
  104. data/templates/addons/scaffold/lib/templates/erb/scaffold/new.html.erb +7 -0
  105. data/templates/addons/scaffold/lib/templates/erb/scaffold/show.html.erb +18 -0
  106. data/templates/addons/services/app/services/application_service.rb +15 -0
  107. data/templates/app_x/controllers/authorized_controller.rb.erb +10 -0
  108. data/templates/app_x/controllers/errors_controller.rb.erb +24 -0
  109. data/templates/app_x/javascript/images/checkmark.svg +1 -0
  110. data/templates/app_x/javascript/images/logo.svg +1 -0
  111. data/templates/app_x/javascript/stylesheets/components.scss +206 -0
  112. data/templates/app_x/views/errors/internal_error.html.erb +14 -0
  113. data/templates/app_x/views/errors/not_found.html.erb +14 -0
  114. data/templates/app_x/views/errors/unacceptable.html.erb +14 -0
  115. data/templates/app_x/views/layouts/application.html.erb.tt +30 -0
  116. data/templates/app_x/views/pages/home.html.erb.tt +20 -0
  117. data/templates/app_x/views/shared/_flashes.html.erb.tt +12 -0
  118. data/templates/app_x/views/shared/_footer.html.erb.tt +21 -0
  119. data/templates/app_x/views/shared/_navbar.html.erb.tt +55 -0
  120. data/templates/app_x/workers/application_worker.rb +5 -0
  121. metadata +207 -3
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Rails 7 with Bootstrap CSS and custom CSS
4
+ # resources:
5
+ # https://www.youtube.com/watch?v=tYr8yn7yRKw
6
+ # https://youtu.be/phOUsR0dm5s?t=493
7
+ # https://www.youtube.com/watch?v=nxKDTtuKOo4
8
+
9
+ require 'pry'
10
+
11
+ self.local_template_path = File.join(File.dirname(__FILE__), 'rag_bootstrap')
12
+
13
+ gac 'base rails 7 image created'
14
+
15
+ add_controller('home', 'index', 'about')
16
+ route("root 'home#index'")
17
+
18
+ # # need a join template method
19
+ # index_content = join_templates(
20
+ # 'component-nav.html',
21
+ # 'component-hero.html',
22
+ # 'component-cards-fancy.html',
23
+ # 'component-cards-staff.html',
24
+ # 'component-cards-styled.html',
25
+ # 'component-modal.html',
26
+ # 'component-footer.html',
27
+ # )
28
+
29
+ # move the nav bar into
30
+ # 'app/views/shared/_navbar.html.erb'
31
+ # and add the nav bar to the layout
32
+ # 'app/views/layouts/application.html.erb'
33
+ # <%= render partial: 'shared/navbar' %>
34
+
35
+ # create_file 'app/views/home/index.html.erb', index_content, force: true
36
+
37
+ # gem 'sassc-rails'
38
+
39
+ after_bundle do
40
+ # add_css_customizations
41
+
42
+ # add_crud_people
43
+
44
+ # rails_command("db:migrate")
45
+ end
46
+
47
+ def add_css_customizations
48
+ # Update the manifest to include the stylesheets
49
+ append_to_file 'app/assets/config/manifest.js' , read_template('manifest.js')
50
+
51
+ # This is how you would add custom styling via @import in the application.bootstrap.css
52
+ append_to_file 'app/assets/stylesheets/application.bootstrap.scss' , "@import 'custom-bootstrap-import.scss';"
53
+ create_file 'app/assets/stylesheets/custom-bootstrap-import.scss' , read_template('custom-bootstrap-import.scss')
54
+
55
+ # This is how you would add custom styling using standard CSS
56
+ create_file 'app/assets/stylesheets/custom-using-css.css' , read_template('custom-using-css.css')
57
+
58
+ # This is how you would add custom styling using standard SAAS/SCSS
59
+ create_file 'app/assets/stylesheets/custom-using-scss.scss' , read_template('custom-using-scss.scss')
60
+
61
+ # This is custom CSS for the fancier components
62
+ create_file 'app/assets/stylesheets/custom-component.css' , join_templates('component-cards-fancy.css', 'component-cards-staff.css')
63
+
64
+ # Update the layout so that the stylesheets are included
65
+ insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb'),
66
+ before: %( <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>)
67
+ gsub_file 'app/views/layouts/application.html.erb', %( <%= yield %>), read_template('application-yield.html.erb')
68
+ end
69
+
70
+ def add_crud_people
71
+ # Need to get the bootstrap form styling working
72
+ # Follow the instructions at: https://youtu.be/phOUsR0dm5s?t=493
73
+ add_scaffold('people', 'first_name', 'last_name', 'age:integer', 'address:text')
74
+ end
data/exe/rag ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'pathname'
5
+ require 'pry'
6
+
7
+ source_path = File.expand_path("#{Pathname.new(__FILE__).dirname}/../lib")
8
+ $LOAD_PATH << source_path
9
+
10
+ require 'rails_app_generator'
11
+
12
+ if ARGV.empty?
13
+ puts 'Please provide a profile for the new application'
14
+ puts
15
+ puts 'See --help for more info'
16
+ exit 0
17
+ elsif %w[-v --version].include? ARGV[0]
18
+ puts RailsAppGenerator::VERSION
19
+ exit 0
20
+ end
21
+
22
+ profile_path = File.expand_path("#{Pathname.new(__FILE__).dirname}/../profiles")
23
+ profile_name = ARGV[0]
24
+ profile_name += '.json' unless profile_name.end_with?('.json')
25
+ profile_file = File.join(profile_path, profile_name)
26
+
27
+ if File.exist?(profile_file)
28
+ puts "Using profile #{profile_file}"
29
+
30
+ profile = JSON.parse(File.read(profile_file), symbolize_names: true)
31
+ args = profile[:args]
32
+ opts = profile[:opts]
33
+ rails_options = RailsAppGenerator::RailsOptions.new(opts)
34
+
35
+ instance = RailsAppGenerator::Starter.new(args)
36
+ FileUtils.rm_rf(instance.target_path)
37
+ instance.start(rails_options)
38
+ else
39
+ puts "Profile #{profile_file} not found"
40
+ exit 1
41
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # XXXX
5
+ class AddOn < Rails::Generators::Base
6
+ include Thor::Actions
7
+ include Rails::Generators::Actions
8
+ include Rails::Generators::AppName
9
+
10
+ attr_reader :dependencies, :context
11
+
12
+ def initialize(context)
13
+ super
14
+ @context = context
15
+ @dependencies = self.class.dependencies || []
16
+ end
17
+
18
+ def apply; end
19
+
20
+ # list any methods that you want access to, but not to be exposed as a thor command
21
+ no_commands do
22
+ def source_paths
23
+ [
24
+ format(context.addon_template_path, addon: self.class.addon_name),
25
+ context.rails_override_template_path,
26
+ context.rails_template_path
27
+ ]
28
+ end
29
+
30
+ def options
31
+ context.options
32
+ end
33
+
34
+ def uses?(addon_name = nil)
35
+ addon_name ||= self.class.addon_name
36
+
37
+ return false if options["skip_#{addon_name}".to_sym]
38
+ return true if context.default_addons.include?(addon_name)
39
+
40
+ klass = addon_name.nil? ? self.class : self.class.get(addon_name)
41
+ Dependencies.new(klass, context).satisfied?
42
+ end
43
+ end
44
+
45
+ class << self
46
+ def apply(context = Context.new({}))
47
+ instance = new(context)
48
+ return unless instance.uses?
49
+
50
+ instance.apply
51
+ end
52
+
53
+ def get(addon)
54
+ addon = addon.to_s.capitalize.camelize
55
+ "RailsAppGenerator::AddOns::#{addon}".constantize
56
+ end
57
+
58
+ def addon_name
59
+ name.demodulize.underscore.to_sym
60
+ end
61
+
62
+ def dependencies
63
+ @dependencies ||= []
64
+ end
65
+
66
+ protected
67
+
68
+ def depends_on(*addon)
69
+ @dependencies = addon.map(&:to_sym)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Annotate for ActiveRecord models to rails application
7
+ class Annotate < AddOn
8
+ depends_on :active_record
9
+
10
+ def apply
11
+ template('auto_annotate_models.rake', 'lib/tasks/auto_annotate_models.rake', force: true)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add GitHub Actions continuous integration
7
+ class ContinuousIntegration < AddOn
8
+ def apply
9
+ say 'continuous integration - Setup GitHub Actions'
10
+ template('github/workflows/build.yml.erb', '.github/workflows/build.yml')
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Devise authentication to rails application
7
+ class Devise < AddOn
8
+ depends_on :active_record
9
+
10
+ def apply
11
+ generate('devise:install', capture: true)
12
+ generate(:devise, 'User', 'name', 'admin:boolean', capture: true)
13
+
14
+ directory('app/views/devise', 'app/views/devise') if uses?(:views)
15
+
16
+ inject_into_file 'config/environments/development.rb', before: /^end/ do
17
+ <<-RUBY
18
+
19
+ # Enable devise mailer
20
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
21
+ RUBY
22
+ end
23
+
24
+ gsub_file 'config/initializers/devise.rb', /# config.pepper = .+/, " # config.pepper = 'pepper'"
25
+ gsub_file 'config/initializers/devise.rb', /# config.secret_key = .+/, " # config.secret_key = 'secret_key'"
26
+
27
+ db_changes
28
+ end
29
+
30
+ private
31
+
32
+ def db_changes
33
+ in_root do
34
+ migration = Dir.glob('db/migrate/*').max_by { |f| File.mtime(f) }
35
+ gsub_file migration, /:admin/, ':admin, default: false'
36
+ end
37
+ insert_into_file 'db/seeds.rb' do
38
+ <<~RUBY
39
+ # Create an initial admin user for development
40
+ User.find_or_create_by(email: "admin@admin.com") do |user|
41
+ user.name = 'Admin'
42
+ user.password = 'password'
43
+ user.admin = true
44
+ end
45
+ RUBY
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Docker to rails application
7
+ class Docker < AddOn
8
+ def apply
9
+ template 'Dockerfile.erb', 'Dockerfile'
10
+ template '.dockerignore.erb', '.dockerignore'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Docker Compose to rails application
7
+ class DockerCompose < AddOn
8
+ def apply
9
+ template 'docker-compose.yml.erb', 'docker-compose.yml'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add DotEnv to rails application
7
+ class Dotenv < AddOn
8
+ def apply
9
+ template '.env.development.erb', '.env.development'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add FactoryBot to rails application
7
+ class FactoryBot < AddOn
8
+ depends_on :active_record, :test
9
+
10
+ def apply
11
+ # TODO: Make this work for minitest
12
+ return unless uses?(:factory_bot)
13
+
14
+ empty_directory 'spec/factories'
15
+ template('spec/support/factory_bot.rb')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Foreman process management for applications with multiple components
7
+ class Foreman < AddOn
8
+ def apply
9
+ template '.foreman.erb', '.foreman'
10
+ template 'Procfile.erb', 'Procfile'
11
+ template 'Procfile.dev.erb', 'Procfile.dev'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Rails Generator configuration to rails application
7
+ class Generators < AddOn
8
+ def apply
9
+ directory('lib/generators/rails/navigation', 'lib/generators/rails/navigation') if uses?(:views)
10
+
11
+ template = 'lib/generators/rails/scaffold_controller_generator.rb'
12
+ template(template) if uses?(:scaffold)
13
+
14
+ generators = <<-RUBY
15
+ config.generators do |generate|
16
+ #{"require_relative '../lib/generators/rails/scaffold_controller_generator'" if uses?(:scaffold)}
17
+ generate.helper false
18
+ generate.javascripts false
19
+ generate.request_specs false
20
+ generate.routing_specs false
21
+ generate.stylesheets false
22
+ #{'generate.test_framework :rspec' if uses?(:rspec)}
23
+ generate.view_specs false
24
+ #{'generate.factory_bot true' if uses?(:factory_bot)}
25
+ end
26
+ RUBY
27
+ inject_into_file 'config/application.rb', generators, before: /^ {2}end\n/
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add High Voltage rails engine for static pages.
7
+ class HighVoltage < AddOn
8
+ depends_on :views
9
+
10
+ def apply
11
+ template('config/initializers/high_voltage.rb')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add InlineSvg support to rails application
7
+ class InlineSvg < AddOn
8
+ depends_on :views
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add IrbRc to rails application
7
+ class Irbrc < RailsAppGenerator::AddOn
8
+ def apply
9
+ template '.irbrc.erb', '.irbrc'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add LogRage - Tame Rails' multi-line logging into a single line per request
7
+ class Lograge < AddOn
8
+ def apply
9
+ template 'config/initializers/lograge.rb'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Pundit - Pundit provides a set of helpers which guide you in
7
+ # leveraging regular Ruby classes and object oriented design patterns
8
+ # to build a simple, robust and scalable authorization system.
9
+ class Pundit < AddOn
10
+ def apply
11
+ directory 'app/policies', 'app/policies'
12
+ template 'app/controllers/authorized_controller.rb.erb', 'app/controllers/authorized_controller.rb'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add RSpec unit testing support to rails application
7
+ class Rspec < AddOn
8
+ depends_on :test
9
+
10
+ def apply
11
+ create_file('.rspec', '--require spec_helper')
12
+ template('spec/rails_helper.rb')
13
+ template('spec/spec_helper.rb')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Rubocop to rails application
7
+ class Rubocop < AddOn
8
+ def apply
9
+ template '.rubocop.yml.erb', '.rubocop.yml'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Tailwind CSS support to rails application
7
+ class Scaffold < AddOn
8
+ depends_on :tailwind
9
+
10
+ def apply
11
+ directory 'lib/templates/erb/scaffold', 'lib/templates/erb/scaffold'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add DotEnv to rails application
7
+ class Services < AddOn
8
+ def apply
9
+ directory 'app/services', 'app/services'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Sidekiq to rails application
7
+ #
8
+ # Sidekiq is a job server that can be used to process jobs in the background.
9
+ # `Sidekiq` is a subclass of `AddOn` that adds a `apply` method that says "setup sidekiq" and
10
+ # copies the `app/workers` directory from the `templates` directory to the `app` directory
11
+ class Sidekiq < AddOn
12
+ def apply
13
+ say 'setup sidekiq'
14
+ directory('app/workers', 'app/workers')
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Stimulus components
7
+ class Stimulus < AddOn
8
+ depends_on :javascript
9
+
10
+ def apply
11
+ rails_command('stimulus:install')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Stimulus components
7
+ class StimulusComponents < AddOn
8
+ depends_on :stimulus
9
+
10
+ def apply
11
+ run('yarn add tailwindcss-stimulus-components')
12
+ inject_into_file('app/javascript/packs/application.js') do
13
+ <<~JS
14
+ import { Application } from "stimulus"
15
+ import { definitionsFromContext } from "stimulus/webpack-helpers"
16
+
17
+ const application = Application.start();
18
+ const context = require.context("controllers", true, /.js$/);
19
+ application.load(definitionsFromContext(context));
20
+
21
+ import { Dropdown, Modal, Tabs, Popover, Toggle, Slideover } from "tailwindcss-stimulus-components"
22
+ application.register('dropdown', Dropdown)
23
+ application.register('modal', Modal)
24
+ application.register('tabs', Tabs)
25
+ application.register('popover', Popover)
26
+ application.register('toggle', Toggle)
27
+ application.register('slideover', Slideover)
28
+ JS
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Tailwind CSS support to rails application
7
+ class Tailwind < AddOn
8
+ depends_on :javascript
9
+
10
+ def apply
11
+ rails_command('tailwindcss:install')
12
+ template('app/javascript/stylesheets/components.scss')
13
+ insert_into_file 'app/javascript/stylesheets/application.scss' do
14
+ <<~CSS
15
+
16
+ @import "components";
17
+ CSS
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add default rails views
7
+ class Views < AddOn
8
+ depends_on :tailwind
9
+
10
+ def apply
11
+ say 'Setting up custom landing page'
12
+ directory 'app/views/layouts', 'app/views/layouts', force: true
13
+ directory 'app/views/shared', 'app/views/shared'
14
+ directory 'app/views/pages', 'app/views/pages' if uses?(:high_voltage)
15
+ # Make sure we can access any images put into the images folder
16
+ inject_into_file('app/javascript/packs/application.js', "require.context('../images', true)")
17
+ directory 'app/javascript/images', 'app/javascript/images'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAppGenerator
4
+ # The application builder allows you to override elements of the application
5
+ # generator without being forced to reverse the operations of the default generator.
4
6
  class AppBuilder < Rails::AppBuilder
5
7
  # def bin
6
8
  # super
@@ -10,15 +12,15 @@ module RailsAppGenerator
10
12
  # def credentials
11
13
  # super
12
14
  # # This sets up credentials using a custom template for both development and production use
13
- # Schienenzeppelin::AddOns::Credentials.apply
15
+ # RailsAppGenerator::AddOns::Credentials.apply
14
16
  # end
15
17
 
16
- # def readme
17
- # template 'README.md.erb', 'README.md'
18
- # end
18
+ def readme
19
+ template 'README.md.erb', 'README.md'
20
+ end
19
21
 
20
22
  # def ruby_version
21
- # Schienenzeppelin::AddOns::RubyVersion.new(Context.new(options)).apply
23
+ # RailsAppGenerator::AddOns::RubyVersion.new(Context.new(options)).apply
22
24
  # end
23
25
 
24
26
  # def gemfile