hot-glue 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea5d85ef61b4bdedf3b9b883596d6cb99ce8fe404dcf0d22d6fec74b9389f7fb
4
- data.tar.gz: 4d94d90506fd14642672b32e5437ba789e94618d6b91459a7c41b9475df272d8
3
+ metadata.gz: 2ddd0fff6e983cefb9f4705ecfa218553412a78d6b02e70f246427562b0991e4
4
+ data.tar.gz: 12971b62efd73dc85db9a48b7d9874f8ba9e81615f1f981af6d00cd2d58a57d7
5
5
  SHA512:
6
- metadata.gz: 7bb028acd27535bfaa5c53559418638eb7af6e45456d4e294e903ab1f3077ee14240056188b5f48677c491f9d4a265cc42add3e36d009552331ffa2cce42db43
7
- data.tar.gz: 1ae9c5018d520969710f68b85af0522485b5011bdaf39ac0056889a5c341046dc8d744a761426d2dd8bd6ca7969fefdc8e1560a0d481e6e78a8f592ab874e236
6
+ metadata.gz: 3f436af0a80f4228e2f17f290d9be67aa1ffc7e48379d92a6739889906bf1a148df922db4af8f5989567bc6306336541de7685dbf41a89de4d7c6caa26235d55
7
+ data.tar.gz: 566393c43f57c2ec3e5e09b2ddd1e3684f643f10fa76468e7343cac20ccd0a015bc6c71f417181cecc60c2e97d10dfecbf36b735c7e2db8dd25556dee5669db0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.0.2)
4
+ hot-glue (0.0.4)
5
5
  ffaker (~> 2.16)
6
6
  haml-rails (~> 2.0)
7
7
  kaminari (~> 1.2)
@@ -12,60 +12,60 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- actioncable (6.1.0)
16
- actionpack (= 6.1.0)
17
- activesupport (= 6.1.0)
15
+ actioncable (6.1.3)
16
+ actionpack (= 6.1.3)
17
+ activesupport (= 6.1.3)
18
18
  nio4r (~> 2.0)
19
19
  websocket-driver (>= 0.6.1)
20
- actionmailbox (6.1.0)
21
- actionpack (= 6.1.0)
22
- activejob (= 6.1.0)
23
- activerecord (= 6.1.0)
24
- activestorage (= 6.1.0)
25
- activesupport (= 6.1.0)
20
+ actionmailbox (6.1.3)
21
+ actionpack (= 6.1.3)
22
+ activejob (= 6.1.3)
23
+ activerecord (= 6.1.3)
24
+ activestorage (= 6.1.3)
25
+ activesupport (= 6.1.3)
26
26
  mail (>= 2.7.1)
27
- actionmailer (6.1.0)
28
- actionpack (= 6.1.0)
29
- actionview (= 6.1.0)
30
- activejob (= 6.1.0)
31
- activesupport (= 6.1.0)
27
+ actionmailer (6.1.3)
28
+ actionpack (= 6.1.3)
29
+ actionview (= 6.1.3)
30
+ activejob (= 6.1.3)
31
+ activesupport (= 6.1.3)
32
32
  mail (~> 2.5, >= 2.5.4)
33
33
  rails-dom-testing (~> 2.0)
34
- actionpack (6.1.0)
35
- actionview (= 6.1.0)
36
- activesupport (= 6.1.0)
34
+ actionpack (6.1.3)
35
+ actionview (= 6.1.3)
36
+ activesupport (= 6.1.3)
37
37
  rack (~> 2.0, >= 2.0.9)
38
38
  rack-test (>= 0.6.3)
39
39
  rails-dom-testing (~> 2.0)
40
40
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
41
- actiontext (6.1.0)
42
- actionpack (= 6.1.0)
43
- activerecord (= 6.1.0)
44
- activestorage (= 6.1.0)
45
- activesupport (= 6.1.0)
41
+ actiontext (6.1.3)
42
+ actionpack (= 6.1.3)
43
+ activerecord (= 6.1.3)
44
+ activestorage (= 6.1.3)
45
+ activesupport (= 6.1.3)
46
46
  nokogiri (>= 1.8.5)
47
- actionview (6.1.0)
48
- activesupport (= 6.1.0)
47
+ actionview (6.1.3)
48
+ activesupport (= 6.1.3)
49
49
  builder (~> 3.1)
50
50
  erubi (~> 1.4)
51
51
  rails-dom-testing (~> 2.0)
52
52
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
53
- activejob (6.1.0)
54
- activesupport (= 6.1.0)
53
+ activejob (6.1.3)
54
+ activesupport (= 6.1.3)
55
55
  globalid (>= 0.3.6)
56
- activemodel (6.1.0)
57
- activesupport (= 6.1.0)
58
- activerecord (6.1.0)
59
- activemodel (= 6.1.0)
60
- activesupport (= 6.1.0)
61
- activestorage (6.1.0)
62
- actionpack (= 6.1.0)
63
- activejob (= 6.1.0)
64
- activerecord (= 6.1.0)
65
- activesupport (= 6.1.0)
56
+ activemodel (6.1.3)
57
+ activesupport (= 6.1.3)
58
+ activerecord (6.1.3)
59
+ activemodel (= 6.1.3)
60
+ activesupport (= 6.1.3)
61
+ activestorage (6.1.3)
62
+ actionpack (= 6.1.3)
63
+ activejob (= 6.1.3)
64
+ activerecord (= 6.1.3)
65
+ activesupport (= 6.1.3)
66
66
  marcel (~> 0.3.1)
67
67
  mimemagic (~> 0.3.2)
68
- activesupport (6.1.0)
68
+ activesupport (6.1.3)
69
69
  concurrent-ruby (~> 1.0, >= 1.0.2)
70
70
  i18n (>= 1.6, < 2)
71
71
  minitest (>= 5.1)
@@ -76,7 +76,7 @@ GEM
76
76
  crass (1.0.6)
77
77
  erubi (1.10.0)
78
78
  erubis (2.7.0)
79
- ffaker (2.17.0)
79
+ ffaker (2.18.0)
80
80
  ffi (1.14.2)
81
81
  globalid (0.4.2)
82
82
  activesupport (>= 4.2.0)
@@ -118,59 +118,55 @@ GEM
118
118
  method_source (1.0.0)
119
119
  mimemagic (0.3.5)
120
120
  mini_mime (1.0.2)
121
- minitest (5.14.3)
122
- nio4r (2.5.4)
121
+ minitest (5.14.4)
122
+ nio4r (2.5.5)
123
123
  nokogiri (1.11.1-x86_64-darwin)
124
124
  racc (~> 1.4)
125
125
  racc (1.5.2)
126
126
  rack (2.2.3)
127
127
  rack-test (1.1.0)
128
128
  rack (>= 1.0, < 3)
129
- rails (6.1.0)
130
- actioncable (= 6.1.0)
131
- actionmailbox (= 6.1.0)
132
- actionmailer (= 6.1.0)
133
- actionpack (= 6.1.0)
134
- actiontext (= 6.1.0)
135
- actionview (= 6.1.0)
136
- activejob (= 6.1.0)
137
- activemodel (= 6.1.0)
138
- activerecord (= 6.1.0)
139
- activestorage (= 6.1.0)
140
- activesupport (= 6.1.0)
129
+ rails (6.1.3)
130
+ actioncable (= 6.1.3)
131
+ actionmailbox (= 6.1.3)
132
+ actionmailer (= 6.1.3)
133
+ actionpack (= 6.1.3)
134
+ actiontext (= 6.1.3)
135
+ actionview (= 6.1.3)
136
+ activejob (= 6.1.3)
137
+ activemodel (= 6.1.3)
138
+ activerecord (= 6.1.3)
139
+ activestorage (= 6.1.3)
140
+ activesupport (= 6.1.3)
141
141
  bundler (>= 1.15.0)
142
- railties (= 6.1.0)
142
+ railties (= 6.1.3)
143
143
  sprockets-rails (>= 2.0.0)
144
144
  rails-dom-testing (2.0.3)
145
145
  activesupport (>= 4.2.0)
146
146
  nokogiri (>= 1.6)
147
147
  rails-html-sanitizer (1.3.0)
148
148
  loofah (~> 2.3)
149
- railties (6.1.0)
150
- actionpack (= 6.1.0)
151
- activesupport (= 6.1.0)
149
+ railties (6.1.3)
150
+ actionpack (= 6.1.3)
151
+ activesupport (= 6.1.3)
152
152
  method_source
153
153
  rake (>= 0.8.7)
154
154
  thor (~> 1.0)
155
155
  rake (13.0.3)
156
- rb-fsevent (0.10.4)
157
- rb-inotify (0.10.1)
158
- ffi (~> 1.0)
159
- ruby_parser (3.15.0)
156
+ ruby_parser (3.15.1)
160
157
  sexp_processor (~> 4.9)
161
- sass (3.7.4)
162
- sass-listen (~> 4.0.0)
163
- sass-listen (4.0.0)
164
- rb-fsevent (~> 0.9, >= 0.9.4)
165
- rb-inotify (~> 0.9, >= 0.9.7)
166
- sass-rails (5.1.0)
167
- railties (>= 5.2.0)
168
- sass (~> 3.1)
169
- sprockets (>= 2.8, < 4.0)
170
- sprockets-rails (>= 2.0, < 4.0)
171
- tilt (>= 1.1, < 3)
172
- sexp_processor (4.15.1)
173
- sprockets (3.7.2)
158
+ sass-rails (6.0.0)
159
+ sassc-rails (~> 2.1, >= 2.1.1)
160
+ sassc (2.4.0)
161
+ ffi (~> 1.9)
162
+ sassc-rails (2.1.2)
163
+ railties (>= 4.0.0)
164
+ sassc (>= 2.0)
165
+ sprockets (> 3.0)
166
+ sprockets-rails
167
+ tilt
168
+ sexp_processor (4.15.2)
169
+ sprockets (4.0.2)
174
170
  concurrent-ruby (~> 1.0)
175
171
  rack (> 1, < 3)
176
172
  sprockets-rails (3.2.2)
data/README.md CHANGED
@@ -39,16 +39,21 @@ rails generate hot_glue:scaffold Thing
39
39
 
40
40
  - The Turbo install has switched your action cable settings from 'async' to Redis, so be sure to start a redis server
41
41
 
42
- - Add hot_glue to your Gemfile & bundle install, then install it with `rails hot_glue:install`
42
+ - Add hot_glue to your Gemfile & bundle install, then install it with `rails generate hot_glue:install`
43
+
44
+ - Add to your `application.html.erb`
45
+ ```
46
+ <%= render partial: 'layouts/flash_notices' %>
47
+ ```
43
48
 
44
49
  - Install Bootstrap (optional)
45
50
 
46
- with Webpack:
51
+ Bootstrap with Webpack:
47
52
  - change `stylesheet_link_tag` to `stylesheet_pack_tag` in your application layout
48
53
  - `yarn add bootstrap`
49
- - create a new file at `app/javascript/css/site.scss` with this contents
54
+ - create a new file at `app/javascript/css/site.scss` with this content
50
55
  ```
51
- @import "~bootstrap/scss/bootstrap.scss
56
+ @import "~bootstrap/scss/bootstrap.scss";
52
57
  ```
53
58
 
54
59
  - add to `app/javascript/packs/application.js`
@@ -56,28 +61,30 @@ with Webpack:
56
61
  import 'css/site'
57
62
  ```
58
63
 
64
+ Bootstrap with Sprockets:
65
+ - use bootstrap-rails gem
59
66
 
60
67
 
61
68
  - Install Devise or implement your own authentication
62
69
 
63
70
 
64
71
 
65
- ## Options
72
+ ### First Argument
73
+ (no double slash)
66
74
 
67
- Note that the arguments are not preceded by dashes and are followed by equal sign and the input you are giving.
75
+ TitleCase class name of the thing you want to build a scaffoling for.
68
76
 
69
- Flags take two dashes (--) and do not take any value. Always pass options first, followed by the flags (or else your options won't work!)
70
77
 
71
- ### First Argument
78
+ ## Options With Arguments
72
79
 
73
- TitleCase class name of the thing you want to build a scaffoling for.
80
+ All options two dashes (--) and these take an `=` and a value
74
81
 
75
- ### `namespace=`
82
+ ### `--namespace=`
76
83
 
77
- pass `namespace=` as an option to denote a namespace to apply to the Rails path helpers
84
+ pass `--namespace=` as an option to denote a namespace to apply to the Rails path helpers
78
85
 
79
86
 
80
- `rails generate hot_glue:scaffold Thing namespace=dashboard`
87
+ `rails generate hot_glue:scaffold Thing --namespace=dashboard`
81
88
 
82
89
  This produces several views at `app/views/dashboard/things/` and a controller at`app/controllers/dashboard/things_controller.rb`
83
90
 
@@ -96,12 +103,12 @@ end
96
103
  ```
97
104
 
98
105
 
99
- ### `nest=`
106
+ ### `--nest=`
100
107
 
101
- pass `nest=` to denote a nested resources
108
+ pass `--nest=` to denote a nested resources
102
109
 
103
110
 
104
- `rails generate hot_glue:scaffold Line nest=invoice`
111
+ `rails generate hot_glue:scaffold Line --nest=invoice`
105
112
 
106
113
  In this example, it is presumed that the current user has_many :invoices, and that invoices have many :lines
107
114
 
@@ -120,7 +127,7 @@ In this example, it is presumed that the current user has_many :invoices, and th
120
127
 
121
128
 
122
129
  To generate scaffold:
123
- `rails generate hot_glue:scaffold Charge nest=invoice/line`
130
+ `rails generate hot_glue:scaffold Charge --nest=invoice/line`
124
131
 
125
132
  The order of the nest should match the nested resources you have in your own app. In particular, you auth root will be used as the starting point when loading the objects from the URL:
126
133
 
@@ -143,7 +150,7 @@ It works, but it isn't granular. As well, it isn't appropriate for a large app w
143
150
  Your customers can delete their own objects by default (may be a good idea or a bad idea for you). If you don't want that, you should strip out the delete actions off the controllers.
144
151
 
145
152
 
146
- ### `auth=`
153
+ ### `--auth=`
147
154
 
148
155
  By default, it will be assumed you have a `current_user` for your user authentication. This will be treated as the "authentication root" for the "poor man's auth" explained above.
149
156
 
@@ -157,7 +164,7 @@ If you use Devise, you probably already have a `current_user` method available i
157
164
 
158
165
  If you use a different object other than "User" for authentication, override using the `auth` option.
159
166
 
160
- `rails generate hot_glue:scaffold Thing auth=current_account`
167
+ `rails generate hot_glue:scaffold Thing --auth=current_account`
161
168
 
162
169
  You will note that in this example it is presumed that the Account object will have an association for `things`
163
170
 
@@ -168,7 +175,7 @@ If you supply nesting (see below), your nest chain will automatically begin with
168
175
 
169
176
 
170
177
 
171
- ### `auth_identifier=`
178
+ ### `--auth_identifier=`
172
179
 
173
180
  Your controller will call a method authenticate_ (AUTH IDENTIFIER) bang, like:
174
181
 
@@ -198,7 +205,7 @@ As well, the `after_sign_in_path_for(user)` here is a hook for Devise also that
198
205
  The default (do not pass `auth_identifier=`) will match the `auth` (So if you use 'account' as the auth, `authenticate_account!` will get invoked from your generated controller; the default is always 'user', so you can leave both auth and auth_identifier off if you want 'user')
199
206
 
200
207
 
201
- `rails generate hot_glue:scaffold Thing auth=current_account auth_identifier=login`
208
+ `rails generate hot_glue:scaffold Thing --auth=current_account --auth_identifier=login`
202
209
  In this example, the controller produced with:
203
210
  ```
204
211
  before_action :authenticate_login!
@@ -209,19 +216,19 @@ However, the object graph anchors would continue to start from current_account.
209
216
  ```
210
217
 
211
218
  Use empty string to **turn this method off**:
212
- `rails generate hot_glue:scaffold Thing auth=current_account auth_identifier=''`
219
+ `rails generate hot_glue:scaffold Thing --auth=current_account --auth_identifier=''`
213
220
 
214
221
  In this case a controller would be generated that would have NO before_action to authenticate the account, but it would still treat the current_account as the auth root for the purpose of loading the objects.
215
222
 
216
223
  Please note that this example would product non-functional code, so you would need to manually fix your controllers to make sure `current_account` is available to the controller.
217
224
 
218
225
 
219
- ### `plural=`
226
+ ### `--plural=`
220
227
 
221
228
  You don't need this if the pluralized version is just + "s" of the singular version. Only use for non-standard plurlizations, and be sure to pass it as TitleCase (as if you pluralized the model name)
222
229
 
223
230
 
224
- ### `exclude=`
231
+ ### `--exclude=`
225
232
  (separate field names by COMMA)
226
233
 
227
234
  By default, all fields are included unless they are on the exclude list. (The default for the exclude list is `id`, `created_at`, and `updated_at` so you don't need to exclude those-- they are added.)
@@ -230,11 +237,11 @@ If you specify an exclude list, those fields + id, created_at, and updated_at wi
230
237
 
231
238
 
232
239
 
233
- ### `--god`
240
+ ### `--god` or `--gd`
234
241
 
235
- Use this flag to create controllers with no root authentication. You can still use an auth_identifier, which can be useful for a meta-leval authentication to the controoler.
242
+ Use this flag to create controllers with no root authentication. You can still use an auth_identifier, which can be useful for a meta-leval authentication to the controller.
236
243
 
237
- For example, FOR ADMIN CONTROLLERS ONLY, supply a auth_identifier and use `--god` flag
244
+ For example, FOR ADMIN CONTROLLERS ONLY, supply a auth_identifier and use `--god` flag.
238
245
 
239
246
  In God mode, the objects are loaded directly from the base class (these controllers have full access)
240
247
  ```
@@ -244,7 +251,8 @@ end
244
251
 
245
252
  ```
246
253
 
247
-
254
+ ## FLAGS (Options with no values)
255
+ These options (flags) also uses `--` syntax but do not take any values. Everything is assumed (default) to be false unless specified.
248
256
 
249
257
  ### `--specs-only`
250
258
 
@@ -261,9 +269,21 @@ Produces all the files except the spec file.
261
269
  Omits pagination. (All list views have pagination by default.)
262
270
 
263
271
 
272
+ ### `--no-create`
273
+
274
+ Omits create action.
275
+
276
+ ### `--no-delete`
277
+
278
+ Omits delete action.
279
+
280
+
264
281
 
265
282
 
266
283
  # VERSION HISTORY
284
+
285
+ #### 2021-03-01 - v0.0.4 - Validation magic; refactors the options to the correct Rails::Generators syntax
286
+
267
287
  #### 2021-02-27 - v0.0.3 - several fixes for namespaces; adds pagination; adds exclude list to fields
268
288
 
269
289
  #### 2021-02-25 - v0.0.2 - bootstrapy
@@ -38,148 +38,133 @@ module HotGlue
38
38
  include GeneratorHelper
39
39
 
40
40
 
41
+ class_option :singular, type: :string, default: nil
42
+ class_option :plural, type: :string, default: nil
43
+ class_option :singular_class, type: :string, default: nil
44
+ class_option :nest, type: :string, default: ""
45
+ class_option :namespace, type: :string, default: nil
46
+ class_option :auth, type: :string, default: nil
47
+ class_option :auth_identifier, type: :string, default: nil
48
+ class_option :exclude, type: :string, default: ""
49
+ class_option :god, type: :boolean, default: false
50
+ class_option :spacs_only, type: :boolean, default: false
51
+ class_option :no_specs, type: :boolean, default: false
52
+ class_option :no_delete, type: :boolean, default: false
53
+ class_option :no_create, type: :boolean, default: false
54
+ class_option :no_paginate, type: :boolean, default: false
55
+
41
56
  def initialize(*meta_args) #:nodoc:
42
- super
57
+ super
43
58
 
44
- begin
45
- object = eval(class_name)
46
- rescue StandardError => e
47
- puts "*** Oops: It looks like there is no object for #{class_name}. Please define the object + database table first."
48
- exit
49
- end
59
+ begin
60
+ object = eval(class_name)
61
+ rescue StandardError => e
62
+ puts "*** Oops: It looks like there is no object for #{class_name}. Please define the object + database table first."
63
+ exit
64
+ end
65
+ args = meta_args[0]
66
+ @singular = args.first.tableize.singularize # should be in form hello_world
50
67
 
51
68
 
69
+ @plural = options['plural'] || @singular + "s" # supply to override; leave blank to use default
70
+ @auth = options['auth'] || "current_user"
71
+ @auth_identifier = options['auth'] || (!@auth.nil? && @auth.gsub("current_", "")) || nil
52
72
 
53
- args = meta_args[0]
54
- @singular = args[0].tableize.singularize # should be in form hello_world
55
73
 
74
+ @nest = options['auth'] || nil
75
+ @namespace = options['namespace'] || nil
56
76
 
57
- @plural = @singular + "s" # supply to override; leave blank to use default
58
- @singular_class = @singular.titleize.gsub(" ", "")
59
- @nest = nil
60
- @namespace = nil
61
- @nested_args = []
77
+ @singular_class = @singular.titleize.gsub(" ", "")
62
78
 
63
- @auth = "current_user"
64
- @auth_identifier = nil
65
- @exclude_fields = []
79
+ @exclude_fields = []
66
80
 
67
- args[1..-1].each do |a|
68
- var_name, var_value = a.split("=")
69
- case (var_name)
70
81
 
71
- when "plural"
72
- @plural = var_value
73
- when "nest"
74
- @nest = var_value
75
- when "namespace"
76
- @namespace = var_value
77
- when "auth"
78
- @auth = var_value
79
- when "auth_identifier"
80
- @auth_identifier = var_value || ""
81
- when "exclude"
82
- @exclude_fields += var_value.split(",").collect(&:to_sym)
83
- end
84
- end
85
82
 
86
- auth_assoc = @auth.gsub("current_","")
83
+ @exclude_fields += options['exclude'].split(",").collect(&:to_sym)
87
84
 
88
- @no_delete = false
89
- @no_create = false
85
+ auth_assoc = @auth.gsub("current_","")
90
86
 
91
- flags = meta_args[1]
92
- flags.each do |f|
93
- case (f)
94
- when "--god"
95
- @auth = nil
96
- when "--specs-only"
97
- @specs_only = true
98
- when "--no-specs"
99
- @no_specs = true
100
- when "--no-delete"
101
- @no_delete = true
102
- when "--no-create"
103
- @no_create = true
104
- when "--no-paginate"
105
- @no_paginate = true
106
- end
107
- end
108
87
 
109
- if @specs_only && @no_specs
110
- puts "*** Oops: You seem to have specified both the --specs-only flag and --no-specs flags. this doesn't make any sense, so I am aborting. sorry."
111
- exit
112
- end
88
+ @god = options['god'] || options['gd'] || false
89
+ @specs_only = options['specs-only'] || false
90
+ @no_specs = options['no-specs'] || false
91
+ @no_delete = options['no-delete'] || false
92
+ @no_create = options['no-create'] || false
93
+ @no_paginate = options['no-paginate'] || false
113
94
 
95
+ if @specs_only && @no_specs
96
+ puts "*** Oops: You seem to have specified both the --specs-only flag and --no-specs flags. this doesn't make any sense, so I am aborting. sorry."
97
+ exit
98
+ end
114
99
 
115
- # only used for the before_action
116
- if @auth_identifier.nil? && !@auth.nil?
117
- @auth_identifier = @auth.gsub("current_", "")
118
- end
100
+ if @god
101
+ @auth = nil
102
+ end
119
103
 
120
- # when in self auth, the object is the same as the authenticated object
121
- if @auth && auth_identifier == @singular
122
- @self_auth = true
123
- end
124
104
 
125
- if !@nest.nil?
126
- @nested_args = @nest.split("/")
127
- @nested_args_plural = {}
128
- @nested_args.each do |a|
129
- @nested_args_plural[a] = a + "s"
105
+ # when in self auth, the object is the same as the authenticated object
106
+ if @auth && auth_identifier == @singular
107
+ @self_auth = true
130
108
  end
131
- end
132
109
 
133
- # the @object_owner will always be object that will 'own' the object
134
- # for new and create
135
110
 
136
- if @auth && ! @self_auth && @nested_args.none?
137
- @object_owner_sym = @auth.gsub("current_", "").to_sym
138
- @object_owner_eval = @auth
139
- else
140
-
141
- if @nested_args.any?
142
- @object_owner_sym = @nested_args.last.to_sym
143
- @object_owner_eval = "@#{@nested_args.last}"
144
- else
145
- @object_owner_sym = ""
146
- @object_owner_eval = ""
111
+ @nested_args = []
112
+ if !@nest.nil?
113
+ @nested_args = @nest.split("/")
114
+ @nested_args_plural = {}
115
+ @nested_args.each do |a|
116
+ @nested_args_plural[a] = a + "s"
117
+ end
147
118
  end
148
- end
149
119
 
120
+ # the @object_owner will always be object that will 'own' the object
121
+ # for new and create
150
122
 
151
-
152
- # create the columns
153
- if !@object_owner_sym.empty?
154
- auth_assoc_field = auth_assoc + "_id"
155
- assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
156
- if assoc
157
- ownership_field = assoc.name.to_s + "_id"
123
+ if @auth && ! @self_auth && @nested_args.none?
124
+ @object_owner_sym = @auth.gsub("current_", "").to_sym
125
+ @object_owner_eval = @auth
158
126
  else
159
- if @auth
160
- puts "*** Oops: It looks like is no association from current_#{@object_owner_sym} to a class called #{singular_class}. If your user is called something else, pass with flag auth=current_X where X is the model for your users as lowercase. Also, be sure to implement current_X as a method on your controller. (If you really don't want to implement a current_X on your controller and want me to check some other method for your current user, see the section in the docs for auth_identifier.) To make a controller that can read all records, specify with --god."
127
+
128
+ if @nested_args.any?
129
+ @object_owner_sym = @nested_args.last.to_sym
130
+ @object_owner_eval = "@#{@nested_args.last}"
161
131
  else
162
- puts "*** Oops: god mode could not find the association(?). something is wrong."
132
+ @object_owner_sym = ""
133
+ @object_owner_eval = ""
163
134
  end
164
- exit
165
135
  end
166
- end
167
136
 
168
- @exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
169
- :reset_password_token,
170
- :reset_password_sent_at, :remember_created_at,
171
- :confirmation_token, :confirmed_at,
172
- :confirmation_sent_at, :unconfirmed_email
137
+ # create the columns
138
+ if !@object_owner_sym.empty?
139
+ auth_assoc_field = auth_assoc + "_id"
140
+ assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
141
+ if assoc
142
+ ownership_field = assoc.name.to_s + "_id"
143
+ else
144
+ if @auth
145
+ puts "*** Oops: It looks like is no association from current_#{@object_owner_sym} to a class called #{singular_class}. If your user is called something else, pass with flag auth=current_X where X is the model for your users as lowercase. Also, be sure to implement current_X as a method on your controller. (If you really don't want to implement a current_X on your controller and want me to check some other method for your current user, see the section in the docs for auth_identifier.) To make a controller that can read all records, specify with --god."
146
+ else
147
+ puts "*** Oops: god mode could not find the association(?). something is wrong."
148
+ end
149
+ exit
150
+ end
151
+ end
173
152
 
174
- @exclude_fields += auth_assoc_field.to_sym if !auth_assoc_field.nil?
175
- @exclude_fields += ownership_field.to_sym if !ownership_field.nil?
153
+ @exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
154
+ :reset_password_token,
155
+ :reset_password_sent_at, :remember_created_at,
156
+ :confirmation_token, :confirmed_at,
157
+ :confirmation_sent_at, :unconfirmed_email
176
158
 
177
- begin
178
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
179
- rescue StandardError => e
180
- puts "Ooops... #{e} it looks like is no object for #{class_name}. Please create the database table with fields first. "
181
- exit
182
- end
159
+ @exclude_fields.push(auth_assoc_field.to_sym) if !auth_assoc_field.nil?
160
+ @exclude_fields.push(ownership_field.to_sym) if !ownership_field.nil?
161
+
162
+ begin
163
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
164
+ rescue StandardError => e
165
+ puts "Ooops... #{e} it looks like is no object for #{class_name}. Please create the database table with fields first. "
166
+ exit
167
+ end
183
168
 
184
169
 
185
170
 
@@ -431,7 +416,7 @@ module HotGlue
431
416
  end
432
417
 
433
418
  def haml_views
434
- res = %w(index edit new _form _line _list _new_button _show)
419
+ res = %w(index edit new _form _new_form _line _list _new_button _show _errors)
435
420
 
436
421
  res
437
422
  end
@@ -587,8 +572,11 @@ module HotGlue
587
572
  display_column = "display_name"
588
573
  elsif assoc_class.column_names.include?("email")
589
574
  display_column = "email"
575
+ elsif assoc_class.column_names.include?("number")
576
+ display_column = "number"
577
+
590
578
  else
591
- puts "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
579
+ puts "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, 5) email, or 6) number directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
592
580
  end
593
581
 
594
582
  "#{col_identifer}
@@ -658,6 +646,28 @@ module HotGlue
658
646
  end
659
647
 
660
648
 
649
+
650
+ def display_class
651
+ me = eval(singular_class)
652
+ @display_class ||=
653
+ if me.column_names.include?("name")
654
+ "name"
655
+ elsif me.column_names.include?("to_label")
656
+ "to_label"
657
+ elsif me.column_names.include?("full_name")
658
+ "full_name"
659
+ elsif me.column_names.include?("display_name")
660
+ "display_name"
661
+ elsif me.column_names.include?("email")
662
+ "email"
663
+ elsif me.column_names.include?("number")
664
+ display_column = "number"
665
+
666
+ else
667
+ raise "*** Oops: Can't find any column to use as the display label on #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, 5) email, or 6) number directly on your #{singular_class} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
668
+ end
669
+ end
670
+
661
671
  def destroy_action
662
672
  return false if @self_auth
663
673
  return !@no_delete
@@ -1,5 +1,6 @@
1
- - if resource.errors.any?
2
- #error_explanation
3
- - resource.errors.full_messages.each do |message|
4
- %div.alert.alert-danger
5
- = message
1
+ = turbo_frame_tag "errors" do
2
+ - if resource.errors.any?
3
+ #error_explanation
4
+ - resource.errors.full_messages.each do |message|
5
+ %div.alert.alert-danger
6
+ = message
@@ -1,7 +1,8 @@
1
- - unless notice.nil?
2
- %div.alert.alert-notice.alert-dismissible
3
- = notice
1
+ = turbo_frame_tag "flash_notices" do
2
+ - unless notice.nil?
3
+ %div.alert.alert-notice.alert-dismissible
4
+ = notice
4
5
 
5
- - unless alert.nil?
6
- %div.alert.alert-danger.alert-dismissible
7
- = alert
6
+ - unless alert.nil?
7
+ %div.alert.alert-danger.alert-dismissible
8
+ = alert
@@ -0,0 +1,10 @@
1
+ = turbo_frame_tag "<%= singular %>-new" do
2
+ %h3
3
+ New <%= singular.titlecase %>
4
+
5
+ = form_with model: <%= singular %>, url: <%= path_helper_plural %>(<%= nested_objects_arity %>), method: "post" do |f|
6
+ = render partial: "<%=namespace_with_slash%><%= @plural %>/form", locals: {<%= singular %>: <%= singular %>, f: f}
7
+
8
+ .row
9
+ .col-md-12
10
+ = f.submit "Save", class: "btn btn-primary pull-right"
@@ -1,5 +1,5 @@
1
1
  class <%= controller_class_name %> < <%= controller_descends_from %>
2
- <% unless @auth_identifier == '' || @auth.nil? %>before_action :authenticate_<%= auth_identifier %>!<% end %>
2
+ <% unless @auth_identifier == '' || @auth.nil? %>before_action :authenticate_<%= @auth_identifier %>!<% end %>
3
3
  <% if any_nested? %> <% @nested_args.each do |arg| %>
4
4
  before_action :load_<%= arg %><% end %> <% end %>
5
5
  before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
@@ -46,20 +46,23 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
46
46
  format.html
47
47
  end
48
48
  end
49
-
50
49
  def create
51
50
  modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !@object_owner_sym.empty? %>.merge!(<%= @object_owner_sym %>: <%= @object_owner_eval %> )<% end %> <%= @auth ? ', ' + @auth : '' %>)
52
51
  @<%=singular_name %> = <%=class_name %>.create(modified_params)
53
52
 
54
53
  if @<%= singular_name %>.save
55
-
54
+ flash[:notice] = "Successfully created #{@<%= singular %>.<%= display_class %>}"
55
+ load_all_<%= plural %>
56
+ respond_to do |format|
57
+ format.turbo_stream
58
+ format.html { redirect_to <%= plural %>_path }
59
+ end
56
60
  else
57
61
  flash[:alert] = "Oops, your <%= singular_name %> could not be created."
58
- end
59
- load_all_<%= plural %>
60
- respond_to do |format|
61
- format.turbo_stream
62
- format.html { redirect_to <%= plural %>_path }
62
+ respond_to do |format|
63
+ format.turbo_stream
64
+ format.html
65
+ end
63
66
  end
64
67
  end<% end %>
65
68
 
@@ -1,5 +1,14 @@
1
- = turbo_stream.replace "<%= plural %>-list" do
2
- = render partial: "list", locals: {<%= plural %>: @<%= plural %>}
1
+ - if @<%= singular %>.errors.none?
2
+ = turbo_stream.replace "<%= plural %>-list" do
3
+ = render partial: "list", locals: {<%= plural %>: @<%= plural %>}
3
4
 
4
5
  = turbo_stream.replace "<%= singular %>-new" do
5
- = render partial: "new_button"
6
+ - if @<%= singular %>.errors.none?
7
+ = render partial: "new_button"
8
+ - else
9
+ = render partial: "new_form", locals: {<%= singular %>: @<%= singular %>}
10
+
11
+ = turbo_stream.replace "flash_notices" do
12
+ = render partial: "layouts/flash_notices"
13
+ - if @<%= singular %>.errors.any?
14
+ = render partial: "errors", locals: {resource: @<%= singular %>}
@@ -1,10 +1 @@
1
- = turbo_frame_tag "<%= singular %>-new" do
2
- %h3
3
- New <%= singular.titlecase %>
4
-
5
- = form_with model: @invoice, url: <%= path_helper_plural %>(<%= nested_objects_arity %>), method: "post" do |f|
6
- = render partial: "<%=namespace_with_slash%><%= @plural %>/form", locals: {<%= singular %>: @<%= singular %>, f: f}
7
-
8
- .row
9
- .col-md-12
10
- = f.submit "Save", class: "btn btn-primary pull-right"
1
+ = render partial: "new_form", locals: {<%=singular%>: @<%=singular%>}
@@ -1,3 +1,3 @@
1
1
  module HotGlue
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot-glue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-27 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -119,6 +119,7 @@ files:
119
119
  - lib/generators/hot_glue/templates/_line.haml
120
120
  - lib/generators/hot_glue/templates/_list.haml
121
121
  - lib/generators/hot_glue/templates/_new_button.haml
122
+ - lib/generators/hot_glue/templates/_new_form.haml
122
123
  - lib/generators/hot_glue/templates/_show.haml
123
124
  - lib/generators/hot_glue/templates/base_controller.rb
124
125
  - lib/generators/hot_glue/templates/controller.rb
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  - !ruby/object:Gem::Version
172
173
  version: '0'
173
174
  requirements: []
174
- rubygems_version: 3.0.8
175
+ rubygems_version: 3.2.11
175
176
  signing_key:
176
177
  specification_version: 4
177
178
  summary: A gem build scaffolding.