rails_app_generator 0.1.8 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.builders/generators/project-plan.rb +4 -3
  3. data/CHANGELOG.md +22 -0
  4. data/Rakefile +2 -0
  5. data/after_templates/addons/rails_html_sanitizer/_.rb +15 -0
  6. data/after_templates/addons/rails_html_sanitizer/home/index.html.erb +3 -0
  7. data/after_templates/addons/rails_html_sanitizer_xxx/home/index.html.erb +31 -0
  8. data/after_templates/rag_devise/application.html.erb +20 -0
  9. data/after_templates/rag_devise/application_controller.rb +10 -0
  10. data/after_templates/rag_devise/config/initializers/devise_turbo.rb +30 -0
  11. data/after_templates/rag_devise/layouts/_alerts.html.erb +3 -0
  12. data/after_templates/rag_devise/layouts/_footer.html.erb +3 -0
  13. data/after_templates/rag_devise/layouts/_navbar.html.erb +14 -0
  14. data/after_templates/rag_devise/layouts/application.html.erb +24 -0
  15. data/after_templates/rag_devise/post/_post.html.erb +14 -0
  16. data/after_templates/rag_devise/post/post.rb +3 -0
  17. data/after_templates/rag_devise/post/posts_controller.rb +72 -0
  18. data/after_templates/rag_devise/seed_data.rb +8 -0
  19. data/after_templates/rag_devise/turbo_controller.rb +24 -0
  20. data/after_templates/rag_devise/user.rb +8 -0
  21. data/after_templates/rag_devise.rb +45 -0
  22. data/after_templates/rag_printspeak/application_controller.rb +22 -0
  23. data/after_templates/rag_printspeak/faq.html.erb +189 -0
  24. data/after_templates/rag_printspeak/layouts/_footer.html.erb +72 -0
  25. data/after_templates/rag_printspeak/layouts/_head.html.erb +17 -0
  26. data/after_templates/rag_printspeak/layouts/_navbar.html.erb +30 -0
  27. data/after_templates/rag_printspeak/layouts/application.html.erb +22 -0
  28. data/after_templates/rag_printspeak/page/_footer.html.erb +184 -0
  29. data/after_templates/rag_printspeak/page/architecture.html.erb +33 -0
  30. data/after_templates/rag_printspeak/page/blog.html.erb +44 -0
  31. data/after_templates/rag_printspeak/page/faq.html.erb +2 -0
  32. data/after_templates/rag_printspeak/page/home.html.erb +32 -0
  33. data/after_templates/rag_printspeak/page/page_controller.rb +27 -0
  34. data/after_templates/rag_printspeak/page/readme.html.erb +49 -0
  35. data/after_templates/rag_printspeak.rb +36 -0
  36. data/docs/project-plan/project.drawio +37 -40
  37. data/docs/project-plan/project_in_progress.svg +1 -1
  38. data/docs/project-plan/project_todo.svg +1 -1
  39. data/exe/rag +1 -1
  40. data/lib/rails_app_generator/addons/annotate.rb +3 -3
  41. data/lib/rails_app_generator/addons/devise.rb +17 -7
  42. data/lib/rails_app_generator/addons/rails_html_sanitizer.rb +14 -0
  43. data/lib/rails_app_generator/addons/xmen.rb +17 -0
  44. data/lib/rails_app_generator/app_generator.rb +169 -0
  45. data/lib/rails_app_generator/diff/processor.rb +13 -0
  46. data/lib/rails_app_generator/options/rails_options.rb +4 -0
  47. data/lib/rails_app_generator/version.rb +1 -1
  48. data/package-lock.json +2 -2
  49. data/package.json +1 -1
  50. data/profiles/addons/rails-html-sanitizer.json +12 -0
  51. data/profiles/addons/rails_html_sanitizer.json +12 -0
  52. data/profiles/rag-devise.json +12 -0
  53. data/profiles/rag-printspeak.json +11 -0
  54. data/tasks/addon.thor +57 -0
  55. data/tasks/gem_info.rb +47 -0
  56. data/tasks/profile.thor +114 -0
  57. data/templates/thor_task/addon/addon.tt +21 -0
  58. data/templates/thor_task/profile/after_template.rb.tt +15 -0
  59. data/templates/thor_task/profile/home/index.html.erb.tt +3 -0
  60. data/templates/thor_task/profile/profile.json.tt +12 -0
  61. metadata +60 -16
  62. data/templates/app_x/controllers/authorized_controller.rb.erb +0 -10
  63. data/templates/app_x/controllers/errors_controller.rb.erb +0 -24
  64. data/templates/app_x/javascript/images/checkmark.svg +0 -1
  65. data/templates/app_x/javascript/images/logo.svg +0 -1
  66. data/templates/app_x/javascript/stylesheets/components.scss +0 -206
  67. data/templates/app_x/views/errors/internal_error.html.erb +0 -14
  68. data/templates/app_x/views/errors/not_found.html.erb +0 -14
  69. data/templates/app_x/views/errors/unacceptable.html.erb +0 -14
  70. data/templates/app_x/views/layouts/application.html.erb.tt +0 -30
  71. data/templates/app_x/views/pages/home.html.erb.tt +0 -20
  72. data/templates/app_x/views/shared/_flashes.html.erb.tt +0 -12
  73. data/templates/app_x/views/shared/_footer.html.erb.tt +0 -21
  74. data/templates/app_x/views/shared/_navbar.html.erb.tt +0 -55
  75. data/templates/app_x/workers/application_worker.rb +0 -5
@@ -7,8 +7,152 @@ module RailsAppGenerator
7
7
  class AppGenerator < Rails::Generators::AppGenerator
8
8
  class_option :test , type: :string , default: 'rspec'
9
9
 
10
+ # acts_as_list 0.9.19 1.0.4 ~> 0.9 default
11
+ # arel 7.1.4 9.0.0
12
+ # bigdecimal 1.4.4 3.1.2 ~> 1.4 development, test
13
+ # binding_of_caller 0.8.0 1.0.0 ~> 0.8 default
14
+ # browser 2.7.1 5.3.1 ~> 2.3 default
15
+ # capistrano-bundler 1.6.0 2.1.0 ~> 1.2 development, test
16
+ # capybara 3.33.0 3.37.1 = 3.33.0 development, test
17
+ # chartkick 2.3.5 4.2.0 ~> 2.3 default
18
+ # childprocess 3.0.0 4.1.0
19
+ # clamby 1.6.6 1.6.8 = 1.6.6 default
20
+ # createsend 5.1.1 6.0.0 ~> 5.1 default
21
+ # database_cleaner 1.7.0 2.0.1 = 1.7.0 development, test
22
+ # factory_bot 5.2.0 6.2.1
23
+ # factory_bot_rails 5.2.0 6.2.0 = 5.2.0 development, test
24
+ # faker 1.9.6 2.22.0 ~> 1.7 default
25
+ # groupdate 4.3.0 6.1.0 ~> 4.1 default
26
+ # guard-bundler 2.2.1 3.0.0 = 2.2.1 development, test
27
+ # guard-rubocop 1.4.0 1.5.0 = 1.4.0 development, test
28
+ # hashie 3.6.0 5.0.0
29
+ # http-accept 1.7.0 2.1.1
30
+ # k_log 0.0.18 0.0.33 = 0.0.18 development, test
31
+ # net-ssh 6.1.0 7.0.1
32
+ # oauth2 1.4.10 2.0.6
33
+ # omniauth-oauth2 1.7.3 1.8.0
34
+ # paper_trail 10.3.1 12.3.0 ~> 10.3 default
35
+ # pg 0.21.0 1.4.2 ~> 0.20 default
36
+ # pg_search 2.3.0 2.3.6 ~> 2.0 default
37
+ # pry 0.13.1 0.14.1
38
+ # public_suffix 2.0.5 5.0.0 ~> 2.0 default
39
+ # pusher 1.4.3 2.0.2 ~> 1.3 default
40
+ # rack-mini-profiler 0.10.7 3.0.0 ~> 0.10 default
41
+ # rack-test 0.6.3 2.0.2
42
+ # rails 5.0.7.2 7.0.3.1 = 5.0.7.2 default
43
+ # railties 5.0.7.2 7.0.3.1
44
+ # ransack 1.8.10 3.2.1 ~> 1.8 default
45
+ # redis 3.3.5 4.7.1 ~> 3.3 default
46
+ # redis-store 1.6.0 1.9.1
47
+ # regexp_parser 1.8.2 2.5.0
48
+ # rspec 3.10.0 3.11.0
49
+ # rspec-core 3.10.1 3.11.0 = 3.10.1 development, test
50
+ # rspec-expectations 3.10.1 3.11.0 = 3.10.1 development, test
51
+ # rspec-mocks 3.10.2 3.11.1 = 3.10.2 development, test
52
+ # rspec-rails 4.1.2 5.1.2 = 4.1.2 development, test
53
+ # rspec-support 3.10.2 3.11.0 = 3.10.2 development, test
54
+ # rubyzip 1.3.0 2.3.2 ~> 1.3 default
55
+ # scenic 1.5.4 1.6.0 = 1.5.4 default
56
+ # scout_apm 4.1.2 5.2.0 ~> 4.1 default
57
+ # selenium-webdriver 3.142.7 4.3.0 = 3.142.7 development, test
58
+ # shoulda-matchers 4.0.1 5.1.0 = 4.0.1 development, test
59
+ # sidekiq 4.2.10 6.5.1 ~> 4.2 default
60
+ # sidekiq-pool 1.9.3 2.0.1 ~> 1.8 default
61
+ # sidekiq-unique-jobs 6.0.25 7.1.27 ~> 6.0 default
62
+ # spring 2.1.1 4.0.0 ~> 2.0 development, test
63
+ # sprockets 3.7.2 4.1.1 ~> 3.7 default
64
+ # sprockets-rails 3.2.2 3.4.2
65
+ # timecop 0.8.1 0.9.5 = 0.8.1 development, test
66
+ # tzinfo 1.2.10 2.0.5
67
+ # uglifier 3.2.0 4.2.0 ~> 3.2 default
68
+ # unicorn 5.8.0 6.1.0 ~> 5.3 default
69
+ # webmock 3.13.0 3.14.0 = 3.13.0 development, test
70
+ # websocket-driver 0.6.5 0.7.5
71
+
72
+ # gem "honeybadger", "4.6.0"
73
+ # gem "pg", "0.20.0"
74
+ # gem "redis", "3.3.3"
75
+ # gem "redis-namespace", "1.5.3"
76
+ # gem "redis-rails", "5.0.2"
77
+ # gem "devise", "4.7.1"
78
+ # gem "twilio-ruby", "5.23.0"
79
+ # gem "google-api-client", "0.9"
80
+ # gem "sinatra", "1.4.8", require: nil # used for the /sidekiq admin screen
81
+ # gem "sidekiq", "4.2.10"
82
+ # gem "sidekiq-unique-jobs", "6.0.25"
83
+ # gem "sidekiq-pool", "1.8.1"
84
+ # gem "faker", "1.7.3"
85
+ # gem "clearbit", "0.2.8"
86
+ # gem "groupdate", "4.1.2"
87
+ # gem "acts_as_commentable", "4.0.2"
88
+ # gem "acts_as_list", "0.9.5"
89
+ # gem "kaminari", "1.2.1"
90
+ # gem "chartkick", "4.1.2"
91
+ # gem "jbuilder", "2.6.3"
92
+ # gem "rest-client", "2.0.1"
93
+ # gem "json", "2.3.0"
94
+ # gem "httparty", "0.14.0"
95
+ # gem "mini_magick", "4.9.4"
96
+ # gem "skeptick", "0.2.1"
97
+ # gem "aws-sdk", "3.0.2"
98
+ # gem "phony_rails", "0.14.11"
99
+ # gem "pg_search", "2.0.1"
100
+ # gem "omniauth", "1.8.1", group: %i[development staging production worker]
101
+ # gem "omniauth-google-oauth2", "0.3.0"
102
+ # gem "redcarpet", "3.5.1"
103
+ # gem "binding_of_caller", "0.8.0"
104
+ # gem "bcrypt-ruby", "3.1.5"
105
+ # gem "rb-readline", "0.5.5"
106
+ # gem "has_secure_token", "1.0.0"
107
+ # gem "stackprof", "0.2.10"
108
+ # gem "createsend", "5.1.0"
109
+ # gem "rubyzip", "1.3.0"
110
+ # gem "chronic", "0.10.2"
111
+ # gem "unread", "0.9.0"
112
+ # gem "browser", "2.3.0"
113
+ # gem "public_suffix", "2.0.5"
114
+ # gem "sassc-rails", "2.1.0"
115
+ # gem "bootstrap-sass", "3.4.1"
116
+ # gem "sprockets", "3.7.2"
117
+ # gem "uglifier", "3.2.0"
118
+ # gem "jquery-rails", "4.1.1"
119
+ # gem "remotipart", "1.3.1"
120
+ # gem "rack-mini-profiler", "0.10.2", require: false
121
+ # gem "flamegraph", "0.9.5"
122
+ # gem "activerecord-import", "0.18.1"
123
+ # gem "parallel", "1.11.1"
124
+ # gem "ruby-progressbar", "1.8.1"
125
+ # gem "css_parser", "1.5.0"
126
+ # gem "guess", "0.1.1"
127
+ # gem "fastimage", "2.1.0"
128
+ # gem "thread", "0.2.2"
129
+ # gem "parse-cron", "0.1.4"
130
+ # gem "thread-parent", "1.0.4"
131
+ # gem "hexapdf", "0.5.0"
132
+ # gem "geocoder", "1.6.1"
133
+ # gem "sd_notify", "0.1.1"
134
+ # gem "attr_encrypted", "3.1.0"
135
+ # gem "clamby", "1.6.6"
136
+ # gem "scout_apm", "5.1.0"
137
+ # gem "pusher", "1.3.0"
138
+ # gem "phony", "2.18.18"
139
+ # gem "recaptcha", "5.7.0"
140
+ # gem "ransack", "1.8.10"
141
+ # gem "configatron", "4.5.1"
142
+ # gem "fuzzy-string-match", "1.0.1"
143
+ # gem "jwt", "1.5.6"
144
+ # gem "htmlentities", "4.3.4"
145
+ # gem "scenic", "1.5.4"
146
+ # gem "rack-cors", "1.0.6"
147
+ # gem "rails_same_site_cookie", "0.1.8"
148
+ # gem "paper_trail", "10.3.0"
149
+ # gem "net-sftp", "3.0.0"
150
+ # gem "prawn", "2.4.0"
151
+ # gem "prawn-table", "0.2.2"
152
+
10
153
  class_option :add_irbrc , type: :boolean, default: false
11
154
  class_option :add_foreman , type: :boolean, default: false
155
+ class_option :add_devise , type: :boolean, default: false
12
156
  class_option :add_dotenv , type: :boolean, default: false
13
157
  class_option :add_docker , type: :boolean, default: false
14
158
  class_option :add_docker_compose , type: :boolean, default: false
@@ -27,6 +171,9 @@ module RailsAppGenerator
27
171
  class_option :add_factory_bot , type: :boolean, default: false
28
172
  class_option :add_shoulda , type: :boolean, default: false
29
173
 
174
+ # NEW GEM ADDONS
175
+ class_option :add_rails_html_sanitizer , type: :boolean, default: false
176
+
30
177
  class << self
31
178
  # points to the original rails templates
32
179
  attr_writer :rails_template_path
@@ -157,6 +304,7 @@ module RailsAppGenerator
157
304
  puts 'finish template'
158
305
 
159
306
  add_if(:annotate)
307
+ add_if(:devise)
160
308
  add_if(:continuous_integration)
161
309
  add_if(:high_voltage)
162
310
  add_if(:generators)
@@ -175,21 +323,31 @@ module RailsAppGenerator
175
323
  no_commands do
176
324
  # Template command examples
177
325
  # gac 'base rails 7 image created'
326
+ # force_copy
178
327
  # add_controller('home', 'index')
179
328
  # add_scaffold('people', 'first_name', 'last_name', 'age:integer', 'address:text')
180
329
  # route("root 'home#index'")
181
330
  # css_install('tailwind')
182
331
  # rails_command('db:migrate')
332
+ # db_migrate
183
333
  # bundle_add('hotwire-rails')
184
334
  # rails_command('hotwire:install')
185
335
  # run('bin/importmap pin sortablejs')
186
336
  # run('npm install daisyui')
187
337
  # create_file 'app/assets/stylesheets/custom-bootstrap-import.scss' , read_template('custom-bootstrap-import.scss')
188
338
  # append_to_file 'app/assets/config/manifest.js' , read_template('manifest.js')
339
+ # insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb')
189
340
  # insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb'),
341
+ # before: %( <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>)
342
+
190
343
  # gsub_file 'app/views/layouts/application.html.erb', %(container mx-auto mt-28 px-5 flex), 'container mx-auto px-5'
191
344
  # template 'home.css', 'app/assets/stylesheets/home.css'
192
345
 
346
+ # OLD style will be removed soon
347
+ def local_template_base(xxx)
348
+ File.join(File.dirname(xxx), File.basename(xxx, '.*'))
349
+ end
350
+
193
351
  # force_copy? # defaults to false
194
352
  # force_copy(true) # set to true
195
353
  # force_copy(false) # set to false
@@ -226,6 +384,10 @@ module RailsAppGenerator
226
384
  rails_command('db:migrate')
227
385
  end
228
386
 
387
+ def db_seed
388
+ rails_command('db:seed')
389
+ end
390
+
229
391
  def add_stimulus(name, *args)
230
392
  generate(:stimulus, name, *args)
231
393
  end
@@ -256,6 +418,13 @@ module RailsAppGenerator
256
418
  super(source, destination, **args)
257
419
  end
258
420
 
421
+ def template(source, *args, &block)
422
+ config = args.last.is_a?(Hash) ? args.pop : {}
423
+ config[:force] = true if force_copy?
424
+ args << config
425
+ super(source, *args, &block)
426
+ end
427
+
259
428
  def read_template(template_file)
260
429
  path = find_in_source_paths(template_file)
261
430
 
@@ -7,6 +7,19 @@ module RailsAppGenerator
7
7
  attr_reader :lhs_path
8
8
  attr_reader :rhs_path
9
9
 
10
+ # Consider the Thor Diff Method below
11
+ # see: gems/thor-1.2.1/lib/thor/shell/basic.rb
12
+
13
+ # def show_diff(destination, content) #:nodoc:
14
+ # diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"
15
+ # require "tempfile"
16
+ # Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
17
+ # temp.write content
18
+ # temp.rewind
19
+ # system %(#{diff_cmd} "#{destination}" "#{temp.path}")
20
+ # end
21
+ # end
22
+
10
23
  DEFAULT_EXCLUSION = lambda do |_file, relative_file|
11
24
  relative_file.start_with?('tmp') ||
12
25
  relative_file.start_with?('node_modules') ||
@@ -39,6 +39,7 @@ module RailsAppGenerator
39
39
 
40
40
  register_option :add_irbrc , type: :boolean, default: false
41
41
  register_option :add_foreman , type: :boolean, default: false
42
+ register_option :add_devise , type: :boolean, default: false
42
43
  register_option :add_dotenv , type: :boolean, default: false
43
44
  register_option :add_docker , type: :boolean, default: false
44
45
  register_option :add_docker_compose , type: :boolean, default: false
@@ -57,6 +58,9 @@ module RailsAppGenerator
57
58
  register_option :add_factory_bot , type: :boolean, default: false
58
59
  register_option :add_shoulda , type: :boolean, default: false
59
60
 
61
+ # NEW GEM ADDONS
62
+ register_option :add_rails_html_sanitizer , type: :boolean, default: false
63
+
60
64
  # if options[:minimal]
61
65
  # self.options = options.merge(
62
66
  # skip_action_cable: true,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAppGenerator
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.11'
5
5
  end
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "rails_app_generator",
3
- "version": "0.1.8",
3
+ "version": "0.1.11",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "rails_app_generator",
9
- "version": "0.1.8",
9
+ "version": "0.1.11",
10
10
  "dependencies": {
11
11
  "daisyui": "^2.20.0"
12
12
  },
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rails_app_generator",
3
- "version": "0.1.8",
3
+ "version": "0.1.11",
4
4
  "description": "Create new Rails Application with custom opinions",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
@@ -0,0 +1,12 @@
1
+ {
2
+ "args": {
3
+ "app_path": "rails_html_sanitizer",
4
+ "destination_root": "/Users/davidcruwys/dev/kgems/rails_app_generator/a/addons"
5
+ },
6
+ "opts": {
7
+ "skip_git": true,
8
+ "skip_test": true,
9
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/rails_html_sanitizer/_.rb",
10
+ "add_rails_html_sanitizer": true
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "args": {
3
+ "app_path": "rails_html_sanitizer",
4
+ "destination_root": "/Users/davidcruwys/dev/kgems/rails_app_generator/a/addons"
5
+ },
6
+ "opts": {
7
+ "skip_git": true,
8
+ "skip_test": true,
9
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/rails_html_sanitizer/_.rb",
10
+ "add_rails_html_sanitizer": true
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "args": {
3
+ "app_path": "devise",
4
+ "destination_root": "/Users/davidcruwys/dev/kgems/rails_app_generator/a/rag"
5
+ },
6
+ "opts": {
7
+ "skip_git": true,
8
+ "skip_test": true,
9
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/rag_devise.rb",
10
+ "add_devise": true
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "args": {
3
+ "app_path": "p7",
4
+ "destination_root": "/Users/davidcruwys/dev/printspeak"
5
+ },
6
+ "opts": {
7
+ "skip_test": true,
8
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/rag_printspeak.rb",
9
+ "javascript": "esbuild"
10
+ }
11
+ }
data/tasks/addon.thor ADDED
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://codecrate.com/2014/01/replace-rake-with-thor.html
4
+
5
+ require 'net/http'
6
+ require 'json'
7
+ require_relative 'gem_info'
8
+
9
+ # Thor task to create a new AddOn for Rails App Generator
10
+ class AddOn < Thor
11
+ include Thor::Actions
12
+
13
+ source_root(File.expand_path('../templates/thor_task', File.dirname(__FILE__)))
14
+
15
+ GemInfo = Struct.new(:name, :version, :description, keyword_init: true)
16
+
17
+ attr_accessor :name
18
+ attr_accessor :addon_config_code
19
+
20
+ # method_option :from, :required => true
21
+ desc 'new', 'Create a new Addon for Rails App Generator'
22
+ method_option :gem , type: :string, default: nil, desc: 'Add required_gem helper to the AddOn. Gem name is looked up to find version and description'
23
+ method_option :force, type: :boolean, default: false, desc: 'Overwrite existing files'
24
+ method_option :depends_on, type: :string, desc: 'This AddOn depends on another AddOn/Gem. active_record is a common dependency'
25
+ def new(name)
26
+ self.name = name
27
+
28
+ code = [build_depends_on_code, build_required_gem_code].compact
29
+ code << '' if code.any?
30
+ self.addon_config_code = code.join("\n")
31
+
32
+ template('addon/addon', "lib/rails_app_generator/addons/#{name}.rb", force: options[:force])
33
+ end
34
+
35
+ no_commands do
36
+ def build_depends_on_code
37
+ return nil unless options[:depends_on]
38
+
39
+ " depends_on :#{options[:depends_on]}"
40
+ end
41
+
42
+ def build_required_gem_code
43
+ info = gem_info
44
+
45
+ " required_gem gem.version('#{info.name}', '#{info.version}', '#{info.description}')"
46
+ end
47
+
48
+ # example: 'https://rubygems.org/api/v1/gems/draper.json'
49
+ def gem_info
50
+ return nil unless options[:gem]
51
+
52
+ gem_name = options[:gem] == 'gem' ? name : options[:gem]
53
+
54
+ ::GemInfo.get(gem_name)
55
+ end
56
+ end
57
+ end
data/tasks/gem_info.rb ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Retrieve GemInfo from RubyGems.org
4
+ class GemInfo
5
+ attr_reader :name
6
+ attr_reader :version
7
+ attr_reader :description
8
+
9
+ def initialize(name, version, description)
10
+ @name = name
11
+ @version = version
12
+ @description = description
13
+ end
14
+
15
+ def debug
16
+ puts "name: #{name}"
17
+ puts "version: #{version}"
18
+ puts "description: #{description}"
19
+ end
20
+
21
+ class << self
22
+ def get(name)
23
+ gem_info = query_ruby_gems(name)
24
+
25
+ return gem_info if gem_info
26
+
27
+ return query_ruby_gems(name.gsub('_', '-')) if name.include?('_')
28
+ return query_ruby_gems(name.gsub('-', '_')) if name.include?('-')
29
+
30
+ abort "Cannot find GEM (#{name}) on RubyGems.org"
31
+ end
32
+
33
+ private
34
+
35
+ def query_ruby_gems(name)
36
+ link = "https://rubygems.org/api/v1/gems/#{name.downcase}.json"
37
+ info = Net::HTTP.get(URI.parse(link))
38
+ json = JSON.parse(info)
39
+
40
+ new(json['name'], json['version'], json['info'])
41
+ rescue SocketError
42
+ abort 'Internet connection cannot be established to RubyGems.org'
43
+ rescue JSON::ParserError
44
+ nil
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://codecrate.com/2014/01/replace-rake-with-thor.html
4
+
5
+ require 'pry'
6
+ require_relative 'gem_info'
7
+ require 'cmdlet'
8
+
9
+ # Thor task to create a new Profile for Rails App Generator
10
+ class Profile < Thor
11
+ include Thor::Actions
12
+
13
+ source_root(File.expand_path('../templates/thor_task', File.dirname(__FILE__)))
14
+
15
+ Data = Struct.new(
16
+ :name,
17
+ :name_dash,
18
+ :name_snake,
19
+ :name_human,
20
+ :description,
21
+ :destination_root,
22
+ :template_file,
23
+ keyword_init: true
24
+ )
25
+
26
+ attr_accessor :data
27
+
28
+ desc 'new', 'Create a new Profile for testing Rails App Generator settings'
29
+ method_option :variant, type: :string, default: 'default', desc: 'Profile variant to create, valid values are (nil, addons)'
30
+ method_option :gem, type: :string, default: nil, desc: 'Gem name is looked up to find version and description'
31
+ method_option :force, type: :boolean, default: false, desc: 'Overwrite existing files'
32
+ # rubocop:disable Metrics/AbcSize
33
+ def new(name)
34
+ @data = build_data(name)
35
+
36
+ say "Creating profile #{name}"
37
+ puts "Variant: #{options[:variant]}"
38
+
39
+ template('profile/profile.json', profile_path("#{data.name_dash}.json"), force: options[:force])
40
+ template('profile/after_template.rb', after_template_path('_.rb'), force: options[:force])
41
+ template('profile/home/index.html.erb', after_template_path('home/index.html.erb'), force: options[:force])
42
+ end
43
+ # rubocop:enable Metrics/AbcSize
44
+
45
+ # rubocop:disable Metrics/BlockLength
46
+ no_commands do
47
+ def human(value)
48
+ Cmdlet::Case::Human.new.call(value)
49
+ end
50
+
51
+ def dash(value)
52
+ Cmdlet::Case::Dash.new.call(value)
53
+ end
54
+
55
+ def snake(value)
56
+ Cmdlet::Case::Snake.new.call(value)
57
+ end
58
+
59
+ def profile_path(file)
60
+ path = 'profiles'
61
+ path = File.join(path, options[:variant]) if options[:variant]
62
+ File.join(path, file)
63
+ end
64
+
65
+ def after_template_path(file)
66
+ path = 'after_templates'
67
+ path = File.join(path, options[:variant]) if options[:variant]
68
+ path = File.join(path, data.name_snake)
69
+ File.join(path, file)
70
+ end
71
+
72
+ def build_data(name)
73
+ gi = gem_info(name)
74
+
75
+ name_dash = dash(name)
76
+ name_snake = snake(name)
77
+ description = gi ? gi.description : 'Description goes here'
78
+
79
+ Data.new(
80
+ name: name,
81
+ name_dash: name_dash,
82
+ name_snake: name_snake,
83
+ name_human: human(name_dash),
84
+ description: description,
85
+ destination_root: build_destination_root,
86
+ template_file: build_template_file(name_snake)
87
+ )
88
+ end
89
+
90
+ def build_template_file(name_snake)
91
+ path = '~/dev/kgems/rails_app_generator/after_templates/'
92
+ path = File.join(path, options[:variant]) if options[:variant]
93
+ path = File.join(path, "#{name_snake}/_.rb")
94
+ File.expand_path(path)
95
+ end
96
+
97
+ def build_destination_root
98
+ # Do not use destination_root as the method name because it already exists on Thor::Actions
99
+ path = '~/dev/kgems/rails_app_generator/a/'
100
+ path = File.join(path, options[:variant]) if options[:variant]
101
+ File.expand_path(path)
102
+ end
103
+
104
+ # example: 'https://rubygems.org/api/v1/gems/draper.json'
105
+ def gem_info(name)
106
+ return nil unless options[:gem]
107
+
108
+ gem_name = options[:gem] == 'gem' ? name : options[:gem]
109
+
110
+ GemInfo.get(gem_name)
111
+ end
112
+ end
113
+ # rubocop:enable Metrics/BlockLength
114
+ 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 <%= Thor::Util.camel_case(name) %> to rails application
7
+ class <%= Thor::Util.camel_case(name) %> < AddOn
8
+ <%= addon_config_code %>
9
+ def apply
10
+ # say 'Setting up <%= Thor::Util.camel_case(name)%>'
11
+ # template('<%= Thor::Util.snake_case(name)%>_template.rb', 'target/<%= Thor::Util.snake_case(name)%>.rb', force: true)
12
+ # template('app/javascript/stylesheets/components.scss')
13
+ # create_file('target/<%= Thor::Util.snake_case(name)%>.rb', 'put your content here')
14
+ # directory 'app/template', 'app/target', force: true
15
+ # empty_directory 'app/target'
16
+ # inject_into_file('app/application.js', "some content")
17
+ # rails_command('tailwindcss:install')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # <%= data.description %>
4
+ require 'pry'
5
+
6
+ self.local_template_path = File.dirname(__FILE__)
7
+
8
+ gac 'base rails 7 image created'
9
+
10
+ add_controller('home', 'index')
11
+ route("root 'home#index'")
12
+
13
+ force_copy
14
+
15
+ copy_file 'home/index.html.erb', 'app/views/home/index.html.erb'
@@ -0,0 +1,3 @@
1
+ <h1><%= data.name_human %></h1>
2
+
3
+ <h2><%= data.description %></h2>
@@ -0,0 +1,12 @@
1
+ {
2
+ "args": {
3
+ "app_path": "<%= data.name_snake %>",
4
+ "destination_root": "<%= data.destination_root %>"
5
+ },
6
+ "opts": {
7
+ "skip_git": true,
8
+ "skip_test": true,
9
+ "template": "<%= data.template_file %>",
10
+ "add_<%= data.name_snake %>": true
11
+ }
12
+ }