hot-glue 0.5.22 → 0.5.23.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +48 -0
- data/lib/generators/hot_glue/fields/enum_field.rb +33 -11
- data/lib/generators/hot_glue/fields/field.rb +2 -0
- data/lib/generators/hot_glue/markup_templates/erb.rb +4 -5
- data/lib/generators/hot_glue/scaffold_generator.rb +6 -0
- data/lib/generators/hot_glue/templates/controller.rb.erb +1 -1
- 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: bdb39b06854037640b63ad674ce2785fcdbb5ea7947b9bf62483b8bc81f24aed
|
4
|
+
data.tar.gz: d64d081e67e29d893849950568ba70bbdaccb057da5d2ade725ea26e74040664
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f09eb212dc5f40325cccb88273088e3fd8ab096fbccf42f4c99d4bb9fb8964efde375be68e9b927fadd5b077d846d8b208b149030b93cabe4348d76a0ad4758d
|
7
|
+
data.tar.gz: 2dc1598871b44d6199011e2b36e6ed8c88c4a2564c249e363130cda931dfb5cef5c4900dade36182ec68216da12ca52f51b941db02056c2ee6d9abb8e68bacf8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hot-glue (0.5.
|
4
|
+
hot-glue (0.5.23.1)
|
5
5
|
ffaker (~> 2.16)
|
6
6
|
kaminari (~> 1.2)
|
7
7
|
rails (> 5.1)
|
@@ -146,7 +146,7 @@ GEM
|
|
146
146
|
net-protocol
|
147
147
|
net-protocol (0.2.1)
|
148
148
|
timeout
|
149
|
-
net-smtp (0.
|
149
|
+
net-smtp (0.4.0)
|
150
150
|
net-protocol
|
151
151
|
nio4r (2.5.8)
|
152
152
|
nokogiri (1.13.9)
|
data/README.md
CHANGED
@@ -1404,6 +1404,54 @@ end
|
|
1404
1404
|
|
1405
1405
|
# VERSION HISTORY
|
1406
1406
|
|
1407
|
+
#### 2023-10-01 - v0.5.23
|
1408
|
+
|
1409
|
+
- You can now use the modify flag on enum type fields to display a partial with the same name of that enum type.
|
1410
|
+
|
1411
|
+
`--modify=status{partials}`
|
1412
|
+
|
1413
|
+
Here, `status` is an enum field on your table; you must use the exact string `partials` when using this feature.
|
1414
|
+
|
1415
|
+
You're telling Hot Glue to build scaffold that will display the `status` enum field as a partial.
|
1416
|
+
|
1417
|
+
It will look for a partial in the same build directory, whose name matches to the value of the enum. You will need to create a partial _for each enum option_ that you have defined.
|
1418
|
+
|
1419
|
+
Remember when defining enums Rails will patch methods on your objects with the name of the enum types, so you must avoid namespace collisions with existing Ruby or Rails methods that are common to all objects -- like, for example, `new`.
|
1420
|
+
|
1421
|
+
- Before this feature, enums always rendered like this on the show page:
|
1422
|
+
`<%= domain.status %>`
|
1423
|
+
(or, if you use custom labels:)
|
1424
|
+
`<%= Domain.status_labels(domain.status)`
|
1425
|
+
|
1426
|
+
- After, you if you use the `--modify` flag and modify the enum to 'partials', your show output will render:
|
1427
|
+
```
|
1428
|
+
<%= render partial: thing.status, locals: {thing: thing} %>
|
1429
|
+
```
|
1430
|
+
(In this example `Thing` is the name of the model being built.)
|
1431
|
+
|
1432
|
+
Your form will also render the partial, but after the collection_select used to create the drop-down.
|
1433
|
+
(This implementation has the draw-back that there is no immediate switch between the partials when changing the drop-down)
|
1434
|
+
|
1435
|
+
Assuming your Thing enum is defined like so:
|
1436
|
+
```
|
1437
|
+
enum :status {abc: 'abc', dfg: 'dfg', hgk: 'hgk'}
|
1438
|
+
```
|
1439
|
+
|
1440
|
+
You then would create three partials in the `things` directory. Make sure to create a partial for each defined enum, or else your app will crash when it tries to render a record with that enum.
|
1441
|
+
```
|
1442
|
+
_abc.html.erb
|
1443
|
+
_dfg.html.erb
|
1444
|
+
_hgk.html.erb
|
1445
|
+
```
|
1446
|
+
|
1447
|
+
If your enum is on the show-only list, then the drop-down does not appear (but the partial is rendered).
|
1448
|
+
|
1449
|
+
Proof-of-concept can be found here:
|
1450
|
+
https://github.com/hot-glue-for-rails/HGEnumWithPartials1
|
1451
|
+
|
1452
|
+
Remember to see the section marked 'A Note About Enums' for more about working with Rails 7 enums.
|
1453
|
+
|
1454
|
+
|
1407
1455
|
#### 2023-09-20- v0.5.22
|
1408
1456
|
- adds back magic button tap-away params in the controller
|
1409
1457
|
- changes creation of flash[:notice] in update method
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class EnumField < Field
|
2
2
|
def spec_setup_and_change_act(which_partial = nil)
|
3
3
|
# what is the enum name
|
4
|
-
" list_of_#{enum_type} = #{class_name}.defined_enums['#{
|
4
|
+
" list_of_#{enum_type} = #{class_name}.defined_enums['#{name}'].keys \n" +
|
5
5
|
" " + "new_#{name} = list_of_#{enum_type}[rand(list_of_#{enum_type}.length)].to_s \n" +
|
6
6
|
' find("select[name=\'' + singular + '[' + name + ']\'] option[value=\'#{new_' + name + '}\']").select_option'
|
7
7
|
end
|
@@ -32,13 +32,19 @@ class EnumField < Field
|
|
32
32
|
|
33
33
|
def form_field_output
|
34
34
|
enum_type = eval("#{class_name}.columns.select{|x| x.name == '#{name}'}[0].sql_type")
|
35
|
-
|
36
35
|
if eval("defined? #{class_name}.#{enum_type}_labels") == "method"
|
37
36
|
enum_definer = "#{class_name}.#{enum_type}_labels"
|
38
37
|
else
|
39
|
-
enum_definer = "#{class_name}.defined_enums['#{
|
38
|
+
enum_definer = "#{class_name}.defined_enums['#{name}']"
|
39
|
+
end
|
40
|
+
|
41
|
+
res = "<%= f.collection_select(:#{name}, enum_to_collection_select(#{enum_definer}), :key, :value, {selected: #{singular}.#{name} }, class: 'form-control') %>"
|
42
|
+
|
43
|
+
|
44
|
+
if modify && modify[:enum] == :partials
|
45
|
+
res << partial_render
|
40
46
|
end
|
41
|
-
|
47
|
+
res
|
42
48
|
end
|
43
49
|
|
44
50
|
def line_field_output
|
@@ -47,14 +53,30 @@ class EnumField < Field
|
|
47
53
|
if eval("defined? #{class_name}.#{enum_type}_labels") == "method"
|
48
54
|
enum_definer = "#{class_name}.#{enum_type}_labels"
|
49
55
|
else
|
50
|
-
enum_definer = "#{class_name}.defined_enums['#{
|
56
|
+
enum_definer = "#{class_name}.defined_enums['#{name}']"
|
51
57
|
end
|
52
|
-
|
58
|
+
|
59
|
+
res = "
|
53
60
|
<% if #{singular}.#{name}.nil? %>
|
54
|
-
<span class='alert-danger'>
|
55
|
-
<% else %>
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
<span class='alert-danger'>Missing #{name}</span>
|
62
|
+
<% else %>"
|
63
|
+
|
64
|
+
if modify && modify[:enum] == :partials
|
65
|
+
res << partial_render
|
66
|
+
else
|
67
|
+
res << "<%= #{enum_definer}[#{singular}.#{name}.to_sym] %>"
|
68
|
+
end
|
69
|
+
|
70
|
+
res << "<% end %>"
|
71
|
+
res
|
72
|
+
end
|
73
|
+
|
74
|
+
def partial_render
|
75
|
+
"<% if #{singular}.#{name} %><%= render partial: #{singular}.#{name}, locals: { #{singular}: #{singular} } %><% end %>"
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def form_show_only_output
|
80
|
+
viewable_output
|
59
81
|
end
|
60
82
|
end
|
@@ -119,6 +119,8 @@ class Field
|
|
119
119
|
"<%= number_to_currency(#{singular}.#{name}) %>"
|
120
120
|
elsif modify[:binary]
|
121
121
|
"<%= #{singular}.#{name} ? '#{modify[:binary][:truthy]}' : '#{modify[:binary][:falsy]}' %>"
|
122
|
+
elsif modify[:enum]
|
123
|
+
"<%= render partial: #{singular}.#{name}, locals: {#{singular}: #{singular}} %>"
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
@@ -97,18 +97,17 @@ module HotGlue
|
|
97
97
|
elsif update_show_only.include?(col) && !@pundit
|
98
98
|
"<% if action_name == 'edit' %>" + columns_map[col].form_show_only_output + "<% else %>" + columns_map[col].form_field_output + "<% end %>"
|
99
99
|
elsif update_show_only.include?(col) && @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
|
100
|
-
"<% if action_name == '
|
100
|
+
"<% if action_name == 'new' && policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
|
101
101
|
|
102
102
|
# show only on the update action overrides any pundit policy
|
103
103
|
elsif @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
|
104
104
|
"<% if policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
|
105
105
|
else
|
106
106
|
columns_map[col].form_field_output
|
107
|
-
|
108
|
-
|
107
|
+
end
|
109
108
|
add_spaces_each_line( "\n <span class='<%= \"alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{'style="display: inherit;"'} >\n" +
|
110
|
-
add_spaces_each_line( (form_labels_position == 'before' ? the_label : "") +
|
111
|
-
+ field_result +
|
109
|
+
add_spaces_each_line( (form_labels_position == 'before' ? the_label || "" : "") +
|
110
|
+
+ " <br />\n" + field_result +
|
112
111
|
(form_labels_position == 'after' ? the_label : "") , 4) +
|
113
112
|
"\n </span>\n <br />", 2)
|
114
113
|
|
@@ -206,6 +206,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
206
206
|
|
207
207
|
@modify = {}
|
208
208
|
if !options['modify'].empty?
|
209
|
+
|
209
210
|
modify_input = options['modify'].split(",")
|
210
211
|
modify_input.each do |setting|
|
211
212
|
setting =~ /(.*){(.*)}/
|
@@ -216,6 +217,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
216
217
|
elsif $2.include?("|")
|
217
218
|
binary = $2.split("|")
|
218
219
|
@modify[key.to_sym] = {binary: {truthy: binary[0], falsy: binary[1]}}
|
220
|
+
elsif $2 == "partial"
|
221
|
+
@modify[key.to_sym] = {enum: :partials}
|
222
|
+
|
223
|
+
else
|
224
|
+
raise "unknown modification direction #{$2}"
|
219
225
|
end
|
220
226
|
end
|
221
227
|
end
|
@@ -142,7 +142,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
142
142
|
end
|
143
143
|
|
144
144
|
<% end %><% if @build_update_action %> def update
|
145
|
-
flash[:notice] =
|
145
|
+
flash[:notice] = +''
|
146
146
|
flash[:alert] = nil
|
147
147
|
<% if @alt_lookups.filter{|key,d| ! @update_show_only.include?(key.to_sym) }.any? %><%= @alt_lookups.filter{|key,d| ! @update_show_only.include?(key.to_sym) }.collect{|key, data|
|
148
148
|
" #{data[:assoc].downcase} = #{data[:assoc]}.#{data[:with_create] ? "find_or_create_by" : "find_by"}(#{data[:lookup_as]}: #{ singular_name }_params[:__lookup_#{data[:lookup_as]}])\n"
|
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.5.
|
4
|
+
version: 0.5.23.1
|
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: 2023-
|
11
|
+
date: 2023-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|