hot-glue 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -4
- data/lib/generators/hot_glue/scaffold_generator.rb +46 -30
- data/lib/hotglue/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae1088aa0a809a10fb6332fa7ca062e1af6aa39a1c8541dabdf4d8451c5ba04d
|
4
|
+
data.tar.gz: a3ff6d5d8a171e1d1d361df692f6255f855720609e692c21573d6311fbeb41e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f65f042a47123cb7a7f69222ddf6618ca085f8cb38bf372179f3bb3da6e47fb07cb383ecba4e0c22642d775db004c0ab111fc99667f575fde62869f7d4c4efba
|
7
|
+
data.tar.gz: e6c36f5bb8a516ee2e74250000174eede61f39c38c46fb74ac963cfa958ac2c5ba2bd3323832b1359ef452e532b7e01b24e04ff68bb67b28df781ccf04e958a4
|
data/README.md
CHANGED
@@ -35,11 +35,15 @@ rails generate hot_glue:scaffold Thing
|
|
35
35
|
|
36
36
|
## TO INSTALL
|
37
37
|
|
38
|
-
- Add Turbo-Rails to your Gemfile & bundle install
|
38
|
+
- Add Turbo-Rails to your Gemfile & bundle install
|
39
|
+
|
40
|
+
- Then install it with `rails turbo:install`
|
39
41
|
|
40
42
|
- The Turbo install has switched your action cable settings from 'async' to Redis, so be sure to start a redis server
|
41
43
|
|
42
|
-
- Add hot_glue to your Gemfile & bundle install
|
44
|
+
- Add `hot_glue` to your Gemfile & `bundle install`
|
45
|
+
|
46
|
+
- Then install it with `rails generate hot_glue:install`
|
43
47
|
|
44
48
|
- Add to your `application.html.erb`
|
45
49
|
```
|
@@ -67,6 +71,7 @@ Bootstrap with Sprockets:
|
|
67
71
|
|
68
72
|
- Install Devise or implement your own authentication
|
69
73
|
|
74
|
+
- Also recommended: font-awesome-sass
|
70
75
|
|
71
76
|
|
72
77
|
### First Argument
|
@@ -225,7 +230,7 @@ Please note that this example would product non-functional code, so you would ne
|
|
225
230
|
|
226
231
|
### `--plural=`
|
227
232
|
|
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
|
233
|
+
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 which is non-standard for Rails)
|
229
234
|
|
230
235
|
|
231
236
|
### `--exclude=`
|
@@ -249,13 +254,22 @@ You may not specify both include and exclude. If you specify an include list, it
|
|
249
254
|
`rails generate hot_glue:scaffold Account --include=first_name,last_name,company_name,created_at,kyc_verified_at`
|
250
255
|
|
251
256
|
|
257
|
+
### `--show-only=`
|
258
|
+
(separate field names by COMMA)
|
259
|
+
|
260
|
+
Any fields only the 'show-only' list will appear as non-editable on the generate form. (visible only)
|
261
|
+
|
262
|
+
IMPORTANT: By default, all fields that begin with an underscore (`_`) are automatically show-only.
|
263
|
+
|
264
|
+
I would recommend this for fields you want globally non-editable by users in your app. For example, a counter cache or other field set only by a backend mechanism.
|
265
|
+
|
252
266
|
### `--god` or `--gd`
|
253
267
|
|
254
268
|
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.
|
255
269
|
|
256
270
|
For example, FOR ADMIN CONTROLLERS ONLY, supply a auth_identifier and use `--god` flag.
|
257
271
|
|
258
|
-
In
|
272
|
+
In Gd mode, the objects are loaded directly from the base class (these controllers have full access)
|
259
273
|
```
|
260
274
|
def load_thing
|
261
275
|
@thing = Thing.find(params[:id])
|
@@ -295,8 +309,12 @@ If you do not want inline editing of your list items but instead to fall back to
|
|
295
309
|
|
296
310
|
|
297
311
|
|
312
|
+
|
313
|
+
|
298
314
|
# VERSION HISTORY
|
299
315
|
|
316
|
+
#### 2021-03-21 - v0.0.8 - show only flag; more specific spec coverage in generator spec
|
317
|
+
|
300
318
|
#### 2021-03-20 - v0.0.7 - adds lots of spec coverage; cleans up generated cruft code on each run; adds no-delete, no-create; a working --big-edit with basic data-turbo false to disable inline editing
|
301
319
|
|
302
320
|
#### 2021-03-06 - v0.0.6 - internal specs test the error catches and cover basic code generation (dummy testing only)
|
@@ -61,6 +61,7 @@ module HotGlue
|
|
61
61
|
class_option :no_create, type: :boolean, default: false
|
62
62
|
class_option :no_paginate, type: :boolean, default: false
|
63
63
|
class_option :big_edit, type: :boolean, default: false
|
64
|
+
class_option :show_only, type: :string, default: ""
|
64
65
|
|
65
66
|
def initialize(*meta_args) #:nodoc:
|
66
67
|
super
|
@@ -88,10 +89,17 @@ module HotGlue
|
|
88
89
|
@exclude_fields = []
|
89
90
|
@exclude_fields += options['exclude'].split(",").collect(&:to_sym)
|
90
91
|
|
91
|
-
if options['include']
|
92
|
+
if !options['include'].empty?
|
92
93
|
@include_fields = []
|
93
94
|
@include_fields += options['include'].split(",").collect(&:to_sym)
|
94
95
|
end
|
96
|
+
|
97
|
+
|
98
|
+
@show_only = []
|
99
|
+
if !options['show_only'].empty?
|
100
|
+
@show_only += options['show_only'].split(",").collect(&:to_sym)
|
101
|
+
end
|
102
|
+
|
95
103
|
auth_assoc = @auth.gsub("current_","")
|
96
104
|
|
97
105
|
@god = options['god'] || options['gd'] || false
|
@@ -155,7 +163,6 @@ module HotGlue
|
|
155
163
|
end
|
156
164
|
end
|
157
165
|
|
158
|
-
|
159
166
|
if !@include_fields
|
160
167
|
@exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
|
161
168
|
:reset_password_token,
|
@@ -174,9 +181,11 @@ module HotGlue
|
|
174
181
|
|
175
182
|
end
|
176
183
|
|
177
|
-
|
178
|
-
|
179
184
|
@columns.each do |col|
|
185
|
+
if col.to_s.starts_with?("_")
|
186
|
+
@show_only << col
|
187
|
+
end
|
188
|
+
|
180
189
|
if object.columns_hash[col.to_s].type == :integer
|
181
190
|
if col.to_s.ends_with?("_id")
|
182
191
|
# guess the association name label
|
@@ -199,15 +208,15 @@ module HotGlue
|
|
199
208
|
end
|
200
209
|
|
201
210
|
assoc_class = eval(assoc.class_name)
|
202
|
-
if assoc_class.
|
211
|
+
if assoc_class.respond_to?(:name)
|
203
212
|
# display_column = "name"
|
204
|
-
elsif assoc_class.
|
213
|
+
elsif assoc_class.respond_to?(:to_label)
|
205
214
|
# display_column = "to_label"
|
206
|
-
elsif assoc_class.
|
215
|
+
elsif assoc_class.respond_to?(:full_name)
|
207
216
|
# display_column = "full_name"
|
208
|
-
elsif assoc_class.
|
217
|
+
elsif assoc_class.respond_to?(:display_name)
|
209
218
|
# display_column = "display_name"
|
210
|
-
elsif assoc_class.
|
219
|
+
elsif assoc_class.respond_to?(:email)
|
211
220
|
# display_column = "email"
|
212
221
|
else
|
213
222
|
exit_message= "*** 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)"
|
@@ -504,6 +513,16 @@ module HotGlue
|
|
504
513
|
col_spaces_prepend = " "
|
505
514
|
|
506
515
|
res = @columns.map { |col|
|
516
|
+
|
517
|
+
if @show_only.include?(col)
|
518
|
+
|
519
|
+
"#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
520
|
+
= @#{singular}.#{col.to_s}
|
521
|
+
%label.form-text
|
522
|
+
#{col.to_s.humanize}\n"
|
523
|
+
else
|
524
|
+
|
525
|
+
|
507
526
|
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
508
527
|
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
509
528
|
sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
|
@@ -512,28 +531,25 @@ module HotGlue
|
|
512
531
|
when :integer
|
513
532
|
# look for a belongs_to on this object
|
514
533
|
if col.to_s.ends_with?("_id")
|
515
|
-
|
516
|
-
#
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
# exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
522
|
-
# exit
|
523
|
-
# end
|
534
|
+
assoc_name = col.to_s.gsub("_id","")
|
535
|
+
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
536
|
+
if assoc.nil?
|
537
|
+
exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
538
|
+
exit
|
539
|
+
end
|
524
540
|
|
525
541
|
|
526
542
|
assoc_class = eval(assoc.class_name)
|
527
543
|
|
528
|
-
if assoc_class.
|
544
|
+
if assoc_class.respond_to?("name")
|
529
545
|
display_column = "name"
|
530
|
-
elsif assoc_class.
|
546
|
+
elsif assoc_class.respond_to?("to_label")
|
531
547
|
display_column = "to_label"
|
532
|
-
elsif assoc_class.
|
548
|
+
elsif assoc_class.respond_to?("full_name")
|
533
549
|
display_column = "full_name"
|
534
|
-
elsif assoc_class.
|
550
|
+
elsif assoc_class.respond_to?("display_name")
|
535
551
|
display_column = "display_name"
|
536
|
-
elsif assoc_class.
|
552
|
+
elsif assoc_class.respond_to?("email")
|
537
553
|
display_column = "email"
|
538
554
|
else
|
539
555
|
raise("this should have been caught by the checker in the initializer")
|
@@ -591,7 +607,7 @@ module HotGlue
|
|
591
607
|
#{col_spaces_prepend}= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1')
|
592
608
|
"
|
593
609
|
end
|
594
|
-
|
610
|
+
end
|
595
611
|
}.join("\n")
|
596
612
|
return res
|
597
613
|
end
|
@@ -624,17 +640,17 @@ module HotGlue
|
|
624
640
|
|
625
641
|
assoc_class = eval(assoc.class_name)
|
626
642
|
|
627
|
-
if assoc_class.
|
643
|
+
if assoc_class.respond_to?("name")
|
628
644
|
display_column = "name"
|
629
|
-
elsif assoc_class.
|
645
|
+
elsif assoc_class.respond_to?("to_label")
|
630
646
|
display_column = "to_label"
|
631
|
-
elsif assoc_class.
|
647
|
+
elsif assoc_class.respond_to?("full_name")
|
632
648
|
display_column = "full_name"
|
633
|
-
elsif assoc_class.
|
649
|
+
elsif assoc_class.respond_to?("display_name")
|
634
650
|
display_column = "display_name"
|
635
|
-
elsif assoc_class.
|
651
|
+
elsif assoc_class.respond_to?("email")
|
636
652
|
display_column = "email"
|
637
|
-
elsif assoc_class.
|
653
|
+
elsif assoc_class.respond_to?("number")
|
638
654
|
display_column = "number"
|
639
655
|
|
640
656
|
else
|
data/lib/hotglue/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.8
|
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-03-
|
11
|
+
date: 2021-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|