rails_app_generator 0.2.22 → 0.2.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/after_templates/addons/devise/_.rb +43 -0
  4. data/after_templates/addons/devise/app/controllers/home_controller.rb +4 -0
  5. data/after_templates/addons/devise/app/controllers/posts_controller.rb +81 -0
  6. data/after_templates/addons/devise/app/models/post.rb +11 -0
  7. data/after_templates/addons/devise/app/models/user.rb +17 -0
  8. data/after_templates/addons/devise/app/views/home/index.html.erb +40 -0
  9. data/after_templates/addons/devise/app/views/layouts/_footer.html.erb +1 -0
  10. data/after_templates/addons/devise/app/views/layouts/_navbar.html.erb +10 -0
  11. data/after_templates/addons/devise/app/views/layouts/application.html.erb +38 -0
  12. data/after_templates/addons/devise/app/views/posts/_form.html.erb +27 -0
  13. data/after_templates/addons/devise/app/views/posts/_post.html.erb +14 -0
  14. data/after_templates/addons/devise/app/views/posts/index.html.erb +12 -0
  15. data/after_templates/addons/devise/app/views/posts/show.html.erb +8 -0
  16. data/after_templates/addons/devise/db/seeds.rb +11 -0
  17. data/after_templates/addons/devise_masquerade/_.rb +36 -0
  18. data/after_templates/addons/devise_masquerade/app/controllers/application_controller.rb +3 -0
  19. data/after_templates/addons/devise_masquerade/app/controllers/home_controller.rb +4 -0
  20. data/after_templates/addons/devise_masquerade/app/controllers/users/masquerades_controller.rb +10 -0
  21. data/after_templates/addons/devise_masquerade/app/models/user.rb +17 -0
  22. data/after_templates/addons/devise_masquerade/app/views/home/index.html.erb +66 -0
  23. data/after_templates/addons/devise_masquerade/app/views/layouts/_footer.html.erb +1 -0
  24. data/after_templates/addons/devise_masquerade/app/views/layouts/_navbar.html.erb +6 -0
  25. data/after_templates/addons/devise_masquerade/app/views/layouts/application.html.erb +57 -0
  26. data/after_templates/addons/devise_masquerade/db/seeds.rb +3 -0
  27. data/after_templates/addons/minimal_css/_.rb +62 -0
  28. data/after_templates/addons/minimal_css/app/controllers/home_controller.rb +4 -0
  29. data/after_templates/addons/minimal_css/app/views/home/index.html.erb +140 -0
  30. data/after_templates/addons/minimal_css/app/views/layouts/_footer.html.erb +1 -0
  31. data/after_templates/addons/minimal_css/app/views/layouts/_navbar.html.erb +3 -0
  32. data/after_templates/addons/minimal_css/app/views/layouts/application.html.erb +29 -0
  33. data/after_templates/addons/minimal_css/db/seeds.rb +5 -0
  34. data/after_templates/rag/devise/_.rb +14 -17
  35. data/after_templates/rag/devise/app/controllers/home_controller.rb +4 -0
  36. data/after_templates/rag/devise/{post → app/controllers}/posts_controller.rb +0 -0
  37. data/after_templates/rag/devise/{post → app/models}/post.rb +0 -0
  38. data/after_templates/rag/devise/app/views/home/index.html.erb +3 -0
  39. data/after_templates/rag/devise/app/views/layouts/_footer.html.erb +3 -0
  40. data/after_templates/rag/devise/app/views/layouts/_navbar.html.erb +8 -0
  41. data/after_templates/rag/devise/app/views/layouts/application.html.erb +24 -0
  42. data/after_templates/rag/devise/{post → app/views/post}/_post.html.erb +0 -0
  43. data/after_templates/rag/test/_.rb +64 -0
  44. data/after_templates/rag/test/app/controllers/home_controller.rb +4 -0
  45. data/after_templates/rag/test/app/views/home/index.html.erb +3 -0
  46. data/after_templates/rag/test/app/views/layouts/_footer.html.erb +1 -0
  47. data/after_templates/rag/test/app/views/layouts/_navbar.html.erb +5 -0
  48. data/after_templates/rag/test/app/views/layouts/application.html.erb +29 -0
  49. data/after_templates/rag/test/db/seeds.rb +7 -0
  50. data/after_templates/rag/testy/_.rb +64 -0
  51. data/after_templates/rag/testy/app/controllers/home_controller.rb +4 -0
  52. data/after_templates/rag/testy/app/views/home/index.html.erb +3 -0
  53. data/after_templates/rag/testy/app/views/layouts/_footer.html.erb +1 -0
  54. data/after_templates/rag/testy/app/views/layouts/_navbar.html.erb +5 -0
  55. data/after_templates/rag/testy/app/views/layouts/application.html.erb +29 -0
  56. data/after_templates/rag/testy/db/seeds.rb +7 -0
  57. data/docs/last_run/app_generator_class.json +25 -1
  58. data/docs/last_run/app_generator_data.json +10 -7
  59. data/docs/last_run/rails_options_class.json +25 -1
  60. data/docs/last_run/rails_options_data.json +12 -8
  61. data/lib/rails_app_generator/addon.rb +30 -2
  62. data/lib/rails_app_generator/addons/devise.rb +119 -0
  63. data/lib/rails_app_generator/addons/devise_masquerade.rb +23 -0
  64. data/lib/rails_app_generator/addons/minimal_css.rb +70 -0
  65. data/lib/rails_app_generator/app_generator.rb +11 -1
  66. data/lib/rails_app_generator/gem_query.rb +34 -0
  67. data/lib/rails_app_generator/rag_initializer.rb +4 -0
  68. data/lib/rails_app_generator/version.rb +1 -1
  69. data/lib/rails_app_generator.rb +1 -0
  70. data/package-lock.json +2 -2
  71. data/package.json +1 -1
  72. data/profiles/addons/devise.json +16 -0
  73. data/profiles/addons/devise_masquerade.json +17 -0
  74. data/profiles/addons/minimal_css.json +15 -0
  75. data/profiles/rag/testy.json +12 -0
  76. data/tasks/addon.thor +7 -3
  77. data/tasks/profile.thor +3 -3
  78. data/templates/Gemfile.erb +1 -0
  79. data/{after_templates/rag/devise/turbo_controller.rb → templates/addons/devise/app/controllers/turbo_devise_controller.rb} +4 -10
  80. data/templates/addons/devise/app/controllers/users/registrations_controller.rb +62 -0
  81. data/templates/addons/devise/app/views/devise/registrations/edit.html.erb +40 -54
  82. data/templates/addons/devise/app/views/devise/registrations/new.html.erb +32 -43
  83. data/templates/addons/devise/app/views/layouts/_alerts.html.erb +2 -0
  84. data/{after_templates/rag → templates/addons}/devise/config/initializers/devise_turbo.rb +1 -1
  85. data/templates/thor_task/profile/after_template.rb +1 -1
  86. data/templates/thor_task/profile/app/views/layouts/_footer.html.erb.tt +1 -3
  87. data/templates/thor_task/profile/app/views/layouts/_navbar.html.erb +5 -8
  88. data/templates/thor_task/profile/app/views/layouts/application.html.erb.tt +8 -2
  89. data/templates/thor_task/profile/db/seeds.rb +2 -11
  90. metadata +67 -18
  91. data/after_templates/rag/devise/application.html.erb +0 -20
  92. data/lib/rails_app_generator/addons/devise_old.rb +0 -61
  93. data/tasks/gem_info.rb +0 -47
  94. data/templates/addons/devise/app/views/devise/confirmations/new.html.erb +0 -24
  95. data/templates/addons/devise/app/views/devise/passwords/edit.html.erb +0 -34
  96. data/templates/addons/devise/app/views/devise/passwords/new.html.erb +0 -23
  97. data/templates/addons/devise/app/views/devise/sessions/new.html.erb +0 -33
  98. data/templates/addons/devise/app/views/devise/shared/_error_messages.html.erb +0 -15
  99. data/templates/addons/devise/app/views/devise/shared/_form_wrap.html.erb +0 -5
  100. data/templates/addons/devise/app/views/devise/shared/_links.html.erb +0 -25
  101. data/templates/addons/devise/app/views/devise/unlocks/new.html.erb +0 -22
@@ -2,7 +2,7 @@
2
2
  "options": {
3
3
  "skip_namespace": false,
4
4
  "skip_collision_check": false,
5
- "ruby": "/Users/davidcruwys/.asdf/installs/ruby/3.1.1/bin/ruby",
5
+ "ruby": "/Users/davidcruwys/.asdf/installs/ruby/2.7.6/bin/ruby",
6
6
  "database": "sqlite3",
7
7
  "skip_git": true,
8
8
  "skip_keeps": false,
@@ -26,33 +26,36 @@
26
26
  "main": false,
27
27
  "no_rc": false,
28
28
  "api": false,
29
- "javascript": "importmap",
29
+ "javascript": "esbuild",
30
30
  "skip_bundle": false,
31
31
  "note": "",
32
32
  "test": "rspec",
33
33
  "add_acts_as_list": false,
34
- "add_administrate": true,
34
+ "add_administrate": false,
35
35
  "add_annotate": true,
36
36
  "add_avo": false,
37
37
  "add_bcrypt": false,
38
38
  "add_browser": false,
39
39
  "add_chartkick": false,
40
- "add_devise": false,
40
+ "add_devise": true,
41
+ "add_devise_masquerade": true,
41
42
  "add_dotenv": false,
42
- "add_faker": true,
43
+ "add_faker": false,
43
44
  "add_groupdate": false,
44
45
  "add_hexapdf": false,
45
46
  "add_httparty": false,
46
47
  "add_honeybadger": false,
47
48
  "add_lograge": false,
49
+ "add_minimal_css": true,
50
+ "minimal_css_library": "water.css",
48
51
  "add_mini_magick": false,
49
52
  "add_motor_admin": false,
50
53
  "add_public_suffix": false,
51
54
  "add_phony_rails": false,
52
55
  "add_rails_html_sanitizer": false,
53
56
  "add_redcarpet": false,
54
- "add_rubocop": true,
57
+ "add_rubocop": false,
55
58
  "add_twilio_ruby": false,
56
- "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/administrate/_.rb"
59
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/devise_masquerade/_.rb"
57
60
  }
58
61
  }
@@ -48,6 +48,7 @@
48
48
  "add_browser",
49
49
  "add_chartkick",
50
50
  "add_devise",
51
+ "add_devise_masquerade",
51
52
  "add_dotenv",
52
53
  "add_faker",
53
54
  "add_groupdate",
@@ -55,6 +56,8 @@
55
56
  "add_httparty",
56
57
  "add_honeybadger",
57
58
  "add_lograge",
59
+ "add_minimal_css",
60
+ "minimal_css_library",
58
61
  "add_mini_magick",
59
62
  "add_motor_admin",
60
63
  "add_public_suffix",
@@ -111,7 +114,7 @@
111
114
  "name": "ruby",
112
115
  "description": "Path to the Ruby binary of your choice",
113
116
  "type": "string",
114
- "default": "/Users/davidcruwys/.asdf/installs/ruby/3.1.1/bin/ruby",
117
+ "default": "/Users/davidcruwys/.asdf/installs/ruby/2.7.6/bin/ruby",
115
118
  "required": false
116
119
  },
117
120
  {
@@ -401,6 +404,13 @@
401
404
  "default": false,
402
405
  "required": false
403
406
  },
407
+ {
408
+ "name": "add_devise_masquerade",
409
+ "description": "",
410
+ "type": "boolean",
411
+ "default": false,
412
+ "required": false
413
+ },
404
414
  {
405
415
  "name": "add_dotenv",
406
416
  "description": "",
@@ -450,6 +460,20 @@
450
460
  "default": false,
451
461
  "required": false
452
462
  },
463
+ {
464
+ "name": "add_minimal_css",
465
+ "description": "",
466
+ "type": "boolean",
467
+ "default": false,
468
+ "required": false
469
+ },
470
+ {
471
+ "name": "minimal_css_library",
472
+ "description": "Minimal CSS library to get you started. [options: water.css (default)]",
473
+ "type": "string",
474
+ "default": "water.css",
475
+ "required": false
476
+ },
453
477
  {
454
478
  "name": "add_mini_magick",
455
479
  "description": "",
@@ -6,8 +6,8 @@
6
6
  "pretend": false,
7
7
  "quiet": false,
8
8
  "skip": false,
9
- "ruby": "/Users/davidcruwys/.asdf/installs/ruby/3.1.1/bin/ruby",
10
- "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/administrate/_.rb",
9
+ "ruby": "/Users/davidcruwys/.asdf/installs/ruby/2.7.6/bin/ruby",
10
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/devise_masquerade/_.rb",
11
11
  "database": "sqlite3",
12
12
  "skip_git": true,
13
13
  "skip_keeps": false,
@@ -35,33 +35,37 @@
35
35
  "version": false,
36
36
  "api": false,
37
37
  "minimal": false,
38
- "javascript": "importmap",
38
+ "javascript": "esbuild",
39
39
  "css": "",
40
40
  "skip_bundle": false,
41
41
  "note": "",
42
42
  "test": "rspec",
43
43
  "add_acts_as_list": false,
44
- "add_administrate": true,
44
+ "add_administrate": false,
45
45
  "add_annotate": true,
46
46
  "add_avo": false,
47
47
  "add_bcrypt": false,
48
48
  "add_browser": false,
49
49
  "add_chartkick": false,
50
- "add_devise": false,
50
+ "add_devise": true,
51
+ "add_devise_masquerade": true,
51
52
  "add_dotenv": false,
52
- "add_faker": true,
53
+ "add_faker": false,
53
54
  "add_groupdate": false,
54
55
  "add_hexapdf": false,
55
56
  "add_httparty": false,
56
57
  "add_honeybadger": false,
57
58
  "add_lograge": false,
59
+ "add_minimal_css": true,
60
+ "minimal_css_library": "water.css",
58
61
  "add_mini_magick": false,
59
62
  "add_motor_admin": false,
60
63
  "add_public_suffix": false,
61
64
  "add_phony_rails": false,
62
65
  "add_rails_html_sanitizer": false,
63
66
  "add_redcarpet": false,
64
- "add_rubocop": true,
65
- "add_twilio_ruby": false
67
+ "add_rubocop": false,
68
+ "add_twilio_ruby": false,
69
+ "notes": "there is a name conflict if the rails application has the same name as the gem and so devise_masquerade has been renamed to devise_masquerade_sample"
66
70
  }
67
71
  }
@@ -35,6 +35,22 @@ module RailsAppGenerator
35
35
  context.options
36
36
  end
37
37
 
38
+ def add_flag?(option_name)
39
+ value = options["add_#{option_name}".to_sym]
40
+
41
+ return false if value.nil?
42
+
43
+ value == true
44
+ end
45
+
46
+ def active?(option_name)
47
+ add_flag?(option_name) # || !skip_flag?(option_name)
48
+ end
49
+
50
+ def option?(option_name)
51
+ !options[option_name.to_sym].nil?
52
+ end
53
+
38
54
  def uses?(addon_name = nil)
39
55
  addon_name ||= self.class.addon_name
40
56
 
@@ -94,16 +110,28 @@ module RailsAppGenerator
94
110
  @gem_entries ||= []
95
111
  end
96
112
 
97
- protected
98
-
99
113
  def depends_on(*addon)
100
114
  @dependencies = addon.map(&:to_sym)
101
115
  end
102
116
 
103
117
  def required_gem(gem_entry)
118
+ existing_gem = gem_entries.find { |gem| gem.name == gem_entry.name }
119
+
120
+ if existing_gem
121
+ return if Gem::Version.new(gem_entry.version) < Gem::Version.new(existing_gem.version)
122
+
123
+ existing_gem.version = gem_entry.version
124
+ existing_gem.comment = gem_entry.comment
125
+ return
126
+ end
127
+
104
128
  gem_entries << gem_entry
105
129
  end
106
130
 
131
+ def reset_gem_entries
132
+ @gem_entries = []
133
+ end
134
+
107
135
  def gem
108
136
  Rails::Generators::AppBase::GemfileEntry
109
137
  end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add Devise to rails application
7
+ class Devise < RailsAppGenerator::Addon
8
+ depends_on :active_record
9
+
10
+ required_gem gem.version('devise', '4.8.1', 'Flexible authentication solution for Rails with Warden')
11
+
12
+ def apply
13
+ generate('devise:install', capture: true)
14
+ generate(:devise, 'User', 'name', 'role:integer', capture: true)
15
+
16
+ update_migration
17
+
18
+ add_trackable if option?(:devise_has_trackable)
19
+ add_confirmable if option?(:devise_has_confirmable)
20
+ add_lockable if option?(:devise_has_lockable)
21
+
22
+ add_turbo_support
23
+
24
+ generate('devise:views', capture: true)
25
+ generate('devise:controllers', 'users', capture: true)
26
+
27
+ update_routes_with_devise_controllers
28
+
29
+ copy_file('app/controllers/users/registrations_controller.rb', 'app/controllers/users/registrations_controller.rb', force: true)
30
+
31
+ enable_devise_mailer
32
+
33
+ directory('app/views', force: true)
34
+ end
35
+
36
+ def before_bundle
37
+ prepend_to_file 'db/seeds.rb', seed, force: true
38
+ end
39
+
40
+ private
41
+
42
+ def update_migration
43
+ in_root do
44
+ migration = Dir.glob('db/migrate/*').max_by { |f| File.mtime(f) }
45
+ gsub_file migration, /:role/, ':role, default: 0'
46
+ end
47
+ end
48
+
49
+ def enable_devise_mailer
50
+ inject_into_file 'config/environments/development.rb', <<-RUBY, after: %(config.action_mailer.raise_delivery_errors = false)
51
+
52
+ # Enable devise mailer
53
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
54
+ RUBY
55
+ end
56
+
57
+ def update_routes_with_devise_controllers
58
+ in_root do
59
+ controller_config = [
60
+ 'sessions: "users/sessions"',
61
+ 'registrations: "users/registrations"'
62
+ ]
63
+ controller_config << 'masquerades: "users/masquerades"' if active?(:devise_masquerade)
64
+
65
+ devise_for_replacement = "devise_for :users, controllers: { #{controller_config.join(', ')} }"
66
+
67
+ gsub_file 'config/routes.rb', /devise_for :users/, devise_for_replacement
68
+ end
69
+ end
70
+
71
+ def add_trackable
72
+ # TODO: remove these comments in generated file
73
+
74
+ ## Trackable
75
+ # t.integer :sign_in_count, default: 0, null: false
76
+ # t.datetime :current_sign_in_at
77
+ # t.datetime :last_sign_in_at
78
+ # t.string :current_sign_in_ip
79
+ # t.string :last_sign_in_ip
80
+ end
81
+
82
+ def add_confirmable
83
+ # TODO: remove these comments in generated file
84
+
85
+ ## Confirmable
86
+ # t.string :confirmation_token
87
+ # t.datetime :confirmed_at
88
+ # t.datetime :confirmation_sent_at
89
+ # t.string :unconfirmed_email # Only if using reconfirmable
90
+ end
91
+
92
+ def add_lockable
93
+ # TODO: remove these comments in generated file
94
+
95
+ ## Lockable
96
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
97
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
98
+ # t.datetime :locked_at
99
+ end
100
+
101
+ def add_turbo_support
102
+ copy_file('app/controllers/turbo_devise_controller.rb', 'app/controllers/turbo_devise_controller.rb')
103
+ copy_file('config/initializers/devise_turbo.rb', 'config/initializers/devise_turbo.rb')
104
+ end
105
+
106
+ def seed
107
+ <<~RUBY
108
+ # Create an initial admin user for development
109
+ User.find_or_create_by(email: "admin@admin.com") do |user|
110
+ user.name = 'Admin'
111
+ user.password = 'password'
112
+ user.role = :admin
113
+ end
114
+
115
+ RUBY
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add DeviseMasquerade to rails application
7
+ class DeviseMasquerade < RailsAppGenerator::Addon
8
+ depends_on :devise
9
+
10
+ required_gem gem.version('devise_masquerade', '1.3.12', 'Devise extension that enables login as another user functionality')
11
+
12
+ def apply
13
+ # NOTE: update_routes_with_devise_controllers is being handled in devise.rb addon
14
+ end
15
+
16
+ # def update_routes_with_devise_controllers
17
+ # in_root do
18
+ # gsub_file 'config/routes.rb', /registrations: "users\/registrations"/, 'registrations: "users/registrations", masquerades: "users/masquerades"'
19
+ # end
20
+ # end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAppGenerator
4
+ # Custom add-ons for RailsAppGenerator
5
+ module AddOns
6
+ # Add MinimalCss to rails application
7
+ class MinimalCss < RailsAppGenerator::Addon
8
+ LIBRARIES = {
9
+ water: {
10
+ source: 'https://watercss.kognise.dev',
11
+ content: '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">'
12
+ },
13
+ picnic: {
14
+ source: 'https://picnicss.com',
15
+ content: '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/picnic">'
16
+ },
17
+ chota: {
18
+ source: 'https://jenil.github.io/chota/',
19
+ content: '<link rel="stylesheet" href="https://unpkg.com/chota@latest">'
20
+ }
21
+ }.freeze
22
+
23
+ # https://purecss.io/
24
+ # https://bulma.io/
25
+ # https://get.foundation/
26
+ # https://www.blazeui.com/
27
+ # https://getbase.org/
28
+ # https://cirrus-ui.netlify.app/
29
+ # https://vanillaframework.io/
30
+ # https://www.patternfly.org/v4/
31
+ # https://tachyons.io/
32
+ # https://nostalgic-css.github.io/NES.css/
33
+ # https://selekkt.dk/skelet/v3/
34
+ # https://picturepan2.github.io/spectre/
35
+ # https://kylelogue.github.io/mustard-ui/
36
+ # https://www.bonsaicss.com/
37
+ # https://ajusa.github.io/lit/
38
+ # https://www.cutestrap.com/
39
+ # https://kbrsh.github.io/wing/
40
+ # https://devinhunt.github.io/typebase.css/
41
+ # http://getskeleton.com/
42
+ # https://semantic-ui.com/
43
+ # https://getuikit.com/
44
+
45
+ # ANIMATION
46
+ # https://animate.style/
47
+ # https://www.csswand.dev/
48
+ # http://animation.kaustubhmenon.com/
49
+ # https://www.minimamente.com/project/magic/
50
+
51
+ def apply; end
52
+
53
+ def after_bundle
54
+ library_key = (options[:minimal_css_library] || 'water').to_sym
55
+
56
+ insert_into_file 'app/views/layouts/application.html.erb', head(library_key), before: %r{^\s+</head>}, force: true
57
+ end
58
+
59
+ private
60
+
61
+ def head(library_key)
62
+ library = LIBRARIES[library_key] || LIBRARIES[:water]
63
+
64
+ content = library[:content]
65
+
66
+ " #{content}\n"
67
+ end
68
+ end
69
+ end
70
+ end
@@ -175,7 +175,8 @@ module RailsAppGenerator
175
175
  add_if(:browser) # tested
176
176
  add_if(:chartkick) # tested
177
177
  add_if(:continuous_integration) # TODO: needs work
178
- add_if(:devise) # TODO: needs testing
178
+ add_if(:devise) # tested
179
+ add_if(:devise_masquerade) # tested
179
180
  # docker_compose
180
181
  # docker
181
182
  add_if(:dotenv) # tested
@@ -188,6 +189,7 @@ module RailsAppGenerator
188
189
  add_if(:high_voltage) # TODO: needs testing
189
190
  add_if(:honeybadger) # tested
190
191
  add_if(:lograge) # tested
192
+ add_if(:minimal_css) # tested (this is NOT a GEM)
191
193
  add_if(:mini_magick) # tested
192
194
  add_if(:motor_magick) # tested
193
195
  add_if(:public_suffix) # tested
@@ -210,6 +212,10 @@ module RailsAppGenerator
210
212
 
211
213
  # Fire any callbacks defined on addons either before running the custom template
212
214
  def apply_rails_template
215
+ # currently running prepare_environment in the template
216
+ # this is doing a bundle install
217
+ # unfortunately this bundle install happens before the normal bundle install, but for now
218
+ # I have to do it until I figure out the why I need the prepare_environment method anyway.
213
219
  addon_instances.select { |addon| addon.respond_to?(:before_template) }.each(&:before_template)
214
220
  super
215
221
  end
@@ -432,6 +438,10 @@ module RailsAppGenerator
432
438
  add_flag?(option_name) # || !skip_flag?(option_name)
433
439
  end
434
440
 
441
+ def option?(option_name)
442
+ !options[option_name.to_sym].nil?
443
+ end
444
+
435
445
  def uses?(addon)
436
446
  return false unless active?(addon)
437
447
 
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Retrieve GemInfo from RubyGems.org
4
+ module RailsAppGenerator
5
+ # GemQuery queries RubyGems for GemEntry.
6
+ class GemQuery
7
+ class << self
8
+ def get(name)
9
+ gem_info = query_ruby_gems(name)
10
+
11
+ return gem_info if gem_info
12
+
13
+ return query_ruby_gems(name.gsub('_', '-')) if name.include?('_')
14
+ return query_ruby_gems(name.gsub('-', '_')) if name.include?('-')
15
+
16
+ abort "Cannot find GEM (#{name}) on RubyGems.org"
17
+ end
18
+
19
+ private
20
+
21
+ def query_ruby_gems(name)
22
+ link = "https://rubygems.org/api/v1/gems/#{name.downcase}.json"
23
+ info = Net::HTTP.get(URI.parse(link))
24
+ json = JSON.parse(info)
25
+
26
+ Rails::Generators::AppBase::GemfileEntry.new(json['name'], json['version'], json['description'])
27
+ rescue SocketError
28
+ abort 'Internet connection cannot be established to RubyGems.org'
29
+ rescue JSON::ParserError
30
+ nil
31
+ end
32
+ end
33
+ end
34
+ end
@@ -99,6 +99,7 @@ KConfig.configure do |config|
99
99
  # rag.add_option :add_scaffold , type: :boolean, default: false
100
100
  # rag.add_option :add_factory_bot , type: :boolean, default: false
101
101
  # rag.add_option :add_shoulda , type: :boolean, default: false
102
+ # letter_opener
102
103
 
103
104
  # NEW GEM ADDONS
104
105
  rag.add_option :add_acts_as_list , type: :boolean, default: false
@@ -110,6 +111,7 @@ KConfig.configure do |config|
110
111
  rag.add_option :add_chartkick , type: :boolean, default: false
111
112
  # continuous_integration
112
113
  rag.add_option :add_devise , type: :boolean, default: false
114
+ rag.add_option :add_devise_masquerade , type: :boolean, default: false
113
115
  # docker_compose
114
116
  # docker
115
117
  rag.add_option :add_dotenv , type: :boolean, default: false
@@ -122,6 +124,8 @@ KConfig.configure do |config|
122
124
  # high_voltage
123
125
  rag.add_option :add_honeybadger , type: :boolean, default: false
124
126
  rag.add_option :add_lograge , type: :boolean, default: false
127
+ rag.add_option :add_minimal_css , type: :boolean, default: false
128
+ rag.add_option :minimal_css_library , type: :string, default: 'water.css', description: "Minimal CSS library to get you started. [options: water.css (default)]"
125
129
  rag.add_option :add_mini_magick , type: :boolean, default: false
126
130
  rag.add_option :add_motor_admin , type: :boolean, default: false
127
131
  rag.add_option :add_public_suffix , type: :boolean, default: false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAppGenerator
4
- VERSION = '0.2.22'
4
+ VERSION = '0.2.25'
5
5
  end
@@ -28,6 +28,7 @@ require 'rails_app_generator/options/options_builder'
28
28
  require 'rails_app_generator/options/rails_options'
29
29
  require 'rails_app_generator/context'
30
30
  require 'rails_app_generator/dependencies'
31
+ require 'rails_app_generator/gem_query'
31
32
  require 'rails_app_generator/addon'
32
33
  require 'rails_app_generator/addon_util'
33
34
  require 'rails_app_generator/formatted_gem_entry'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "rails_app_generator",
3
- "version": "0.2.22",
3
+ "version": "0.2.25",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "rails_app_generator",
9
- "version": "0.2.22",
9
+ "version": "0.2.25",
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.2.22",
3
+ "version": "0.2.25",
4
4
  "description": "Create new Rails Application with custom opinions",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
@@ -0,0 +1,16 @@
1
+ {
2
+ "args": {
3
+ "app_path": "devise",
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/devise/_.rb",
10
+ "notes": "javascript: esbuild is used for the demonstration of this addon so that the destroy_user_session_path can be used as a link using turbo_method: :delete",
11
+ "javascript": "esbuild",
12
+ "add_annotate": true,
13
+ "add_devise": true,
14
+ "add_faker": true
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "args": {
3
+ "app_path": "r7_devise_masquerade",
4
+ "destination_root": "/Users/davidcruwys/dev/kgems/rails_app_generator/a/addons"
5
+ },
6
+ "opts": {
7
+ "notes": "there is a name conflict if the rails application has the same name as the gem and so devise_masquerade has been renamed to devise_masquerade_sample",
8
+ "skip_git": true,
9
+ "skip_test": true,
10
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/devise_masquerade/_.rb",
11
+ "javascript": "esbuild",
12
+ "add_annotate": true,
13
+ "add_devise": true,
14
+ "add_devise_masquerade": true,
15
+ "add_minimal_css": true
16
+ }
17
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "args": {
3
+ "app_path": "minimal_css",
4
+ "destination_root": "/Users/davidcruwys/dev/kgems/rails_app_generator/a/addons"
5
+ },
6
+ "opts": {
7
+ "skip_git": true,
8
+ "skip_test": true,
9
+ "note": "minimal_css_library is optional and will default to water if not specified.",
10
+ "template": "/Users/davidcruwys/dev/kgems/rails_app_generator/after_templates/addons/minimal_css/_.rb",
11
+ "add_faker": true,
12
+ "add_minimal_css": true,
13
+ "minimal_css_library": "water"
14
+ }
15
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "args": {
3
+ "app_path": "testy",
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/testy/_.rb",
10
+ "javascript": "esbuild"
11
+ }
12
+ }
data/tasks/addon.thor CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  require 'net/http'
6
6
  require 'json'
7
- require_relative 'gem_info'
7
+ require 'pry'
8
+ require 'cmdlet'
9
+ require 'rails_app_generator'
8
10
 
9
11
  # Thor task to create a new Addon for Rails App Generator
10
12
  class Addon < Thor
@@ -46,9 +48,11 @@ class Addon < Thor
46
48
  end
47
49
 
48
50
  def build_required_gem_code
51
+ return nil unless options[:gem]
52
+
49
53
  info = gem_info
50
54
 
51
- " required_gem gem.version('#{info.name}', '#{info.version}', '#{info.description}')"
55
+ " required_gem gem.version('#{info.name}', '#{info.version}', '#{info.comment}')"
52
56
  end
53
57
 
54
58
  # example: 'https://rubygems.org/api/v1/gems/draper.json'
@@ -57,7 +61,7 @@ class Addon < Thor
57
61
 
58
62
  gem_name = options[:gem] == 'gem' ? name : options[:gem]
59
63
 
60
- ::GemInfo.get(gem_name)
64
+ RailsAppGenerator::GemQuery.get(gem_name)
61
65
  end
62
66
 
63
67
  def build_data