hot-glue 0.6.18 → 0.6.20
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +334 -227
- data/lib/generators/hot_glue/fields/association_field.rb +1 -1
- data/lib/generators/hot_glue/fields/boolean_field.rb +6 -6
- data/lib/generators/hot_glue/fields/field.rb +5 -5
- data/lib/generators/hot_glue/layout/builder.rb +15 -6
- data/lib/generators/hot_glue/markup_templates/erb.rb +63 -15
- data/lib/generators/hot_glue/scaffold_generator.rb +46 -6
- data/lib/generators/hot_glue/templates/controller.rb.erb +28 -12
- data/lib/hotglue/version.rb +1 -1
- metadata +2 -2
@@ -23,9 +23,9 @@ class BooleanField < Field
|
|
23
23
|
|
24
24
|
def radio_button_display
|
25
25
|
" <%= f.radio_button(:#{name}, '0', checked: #{singular}.#{name} ? '' : 'checked', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
|
26
|
-
" <%= f.label(:#{name}, value: '#{modify_binary? && modify_as[
|
26
|
+
" <%= f.label(:#{name}, value: '#{modify_binary? && modify_as[:binary][:falsy] || 'No'}', for: '#{singular}_#{name}_0') %>\n" +
|
27
27
|
" <br /> <%= f.radio_button(:#{name}, '1', checked: #{singular}.#{name} ? 'checked' : '' , class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
|
28
|
-
" <%= f.label(:#{name}, value: '#{modify_binary? && modify_as[
|
28
|
+
" <%= f.label(:#{name}, value: '#{modify_binary? && modify_as[:binary][:truthy] || 'Yes'}', for: '#{singular}_#{name}_1') %>\n"
|
29
29
|
end
|
30
30
|
|
31
31
|
def checkbox_display
|
@@ -59,9 +59,9 @@ class BooleanField < Field
|
|
59
59
|
"<% if #{singular}.#{name}.nil? %>
|
60
60
|
<span class=''>MISSING</span>
|
61
61
|
<% elsif #{singular}.#{name} %>
|
62
|
-
#{modify_as[
|
62
|
+
#{modify_as[:binary][:truthy]}
|
63
63
|
<% else %>
|
64
|
-
#{modify_as[
|
64
|
+
#{modify_as[:binary][:falsy]}
|
65
65
|
<% end %>"
|
66
66
|
else
|
67
67
|
"<% if #{singular}.#{name}.nil? %>
|
@@ -75,11 +75,11 @@ class BooleanField < Field
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def truthy_value
|
78
|
-
modify_as[
|
78
|
+
modify_as[:binary][:truthy] || 'Yes'
|
79
79
|
end
|
80
80
|
|
81
81
|
def falsy_value
|
82
|
-
modify_as[
|
82
|
+
modify_as[:binary][:falsy] || 'No'
|
83
83
|
end
|
84
84
|
|
85
85
|
def label_class
|
@@ -6,7 +6,7 @@ class Field
|
|
6
6
|
:self_auth,
|
7
7
|
:singular_class, :singular, :sql_type, :ownership_field,
|
8
8
|
:update_show_only, :namespace, :pundit, :plural,
|
9
|
-
:stimmify, :
|
9
|
+
:stimmify, :hidden_create, :hidden_update, :attachment_data, :god
|
10
10
|
|
11
11
|
|
12
12
|
def initialize(
|
@@ -25,7 +25,7 @@ class Field
|
|
25
25
|
@form_placeholder_labels = scaffold.form_placeholder_labels
|
26
26
|
@ownership_field = scaffold.ownership_field
|
27
27
|
@form_labels_position = scaffold.form_labels_position
|
28
|
-
@modify_as = scaffold.modify_as
|
28
|
+
@modify_as = scaffold.modify_as[name.to_sym] # note whenever used as field, don't relookup the key
|
29
29
|
@display_as = scaffold.display_as
|
30
30
|
@pundit = scaffold.pundit
|
31
31
|
@plural = scaffold.plural
|
@@ -33,7 +33,8 @@ class Field
|
|
33
33
|
@default_boolean_display = scaffold.default_boolean_display
|
34
34
|
@namespace = scaffold.namespace_value
|
35
35
|
@stimmify = scaffold.stimmify
|
36
|
-
@
|
36
|
+
@hidden_create = scaffold.hidden_create
|
37
|
+
@hidden_update = scaffold.hidden_update
|
37
38
|
@attachment_data = scaffold.attachments[name.to_sym]
|
38
39
|
@god = scaffold.god
|
39
40
|
|
@@ -113,7 +114,7 @@ class Field
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def viewable_output
|
116
|
-
if modify_as
|
117
|
+
if modify_as
|
117
118
|
modified_display_output(show_only: true)
|
118
119
|
else
|
119
120
|
field_view_output
|
@@ -159,7 +160,6 @@ class Field
|
|
159
160
|
# end
|
160
161
|
# res = "<span class='badge <%= #{badge_code} %>'>" + res + "</span>"
|
161
162
|
# end
|
162
|
-
# byebug
|
163
163
|
res
|
164
164
|
end
|
165
165
|
|
@@ -127,15 +127,24 @@ module HotGlue
|
|
127
127
|
# if user_layout_columns.size > available_columns
|
128
128
|
# raise "Your include statement #{@include_setting } has #{user_layout_columns.size} columns, but I can only construct up to #{available_columns}"
|
129
129
|
# end
|
130
|
+
|
131
|
+
|
132
|
+
columns_to_work_with = (12 - @buttons_width)
|
133
|
+
|
134
|
+
if columns_to_work_with < user_layout_columns.size
|
135
|
+
raise "Your include statement #{@include_setting } has #{user_layout_columns.size} columns, but I can only construct up to #{columns_to_work_with}"
|
136
|
+
end
|
137
|
+
|
138
|
+
target_col_size = columns_to_work_with / user_layout_columns.size
|
139
|
+
extra_columns = columns_to_work_with % user_layout_columns.size
|
140
|
+
|
141
|
+
|
130
142
|
user_layout_columns.each_with_index do |column,i|
|
131
143
|
layout_object[:columns][:container][i] = column.split(",").collect(&:to_sym)
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
default_col_width += 1
|
136
|
-
extra_columns -= 1
|
144
|
+
layout_object[:columns][:bootstrap_column_width][i] = target_col_size
|
145
|
+
if i < extra_columns
|
146
|
+
layout_object[:columns][:bootstrap_column_width][i] += 1
|
137
147
|
end
|
138
|
-
layout_object[:columns][:bootstrap_column_width][i] = default_col_width
|
139
148
|
end
|
140
149
|
|
141
150
|
if user_layout_columns.size < layout_object[:columns][:container].size
|
@@ -11,7 +11,8 @@ module HotGlue
|
|
11
11
|
:attachments, :show_only, :columns_map, :pundit, :related_sets,
|
12
12
|
:search, :search_fields, :search_query_fields, :search_position,
|
13
13
|
:form_path, :layout_object, :search_clear_button, :search_autosearch,
|
14
|
-
:stimmify, :stimmify_camel, :
|
14
|
+
:stimmify, :stimmify_camel, :hidden_create, :hidden_update, :invisible_create,
|
15
|
+
:invisible_update, :plural
|
15
16
|
|
16
17
|
|
17
18
|
def initialize(singular:, singular_class: ,
|
@@ -23,7 +24,8 @@ module HotGlue
|
|
23
24
|
update_show_only:, attachments: , columns_map:, pundit:, related_sets:,
|
24
25
|
search:, search_fields:, search_query_fields: , search_position:,
|
25
26
|
search_clear_button:, search_autosearch:, layout_object:,
|
26
|
-
form_path: , stimmify: , stimmify_camel:,
|
27
|
+
form_path: , stimmify: , stimmify_camel:, hidden_create:, hidden_update: ,
|
28
|
+
invisible_create:, invisible_update: , plural: )
|
27
29
|
|
28
30
|
|
29
31
|
@form_path = form_path
|
@@ -34,7 +36,11 @@ module HotGlue
|
|
34
36
|
@layout_object = layout_object
|
35
37
|
@stimmify = stimmify
|
36
38
|
@stimmify_camel = stimmify_camel
|
37
|
-
@
|
39
|
+
@hidden_create = hidden_create
|
40
|
+
@hidden_update = hidden_update
|
41
|
+
@invisible_create = invisible_create
|
42
|
+
@invisible_update = invisible_update
|
43
|
+
@plural = plural
|
38
44
|
|
39
45
|
@singular = singular
|
40
46
|
@singular_class = singular_class
|
@@ -75,7 +81,7 @@ module HotGlue
|
|
75
81
|
(big_edit ? ", \"turbo\": false" : "") +
|
76
82
|
"}} do |f| %>" +
|
77
83
|
"<%= f.hidden_field :__#{button_name}, value: \"__#{button_name}\" %>" +
|
78
|
-
"<%= f.submit '#{button_name.titleize}'.html_safe, disabled: (#{singular}.respond_to?(:#{button_name}
|
84
|
+
"<%= f.submit '#{button_name.titleize}'.html_safe, disabled: (#{singular}.respond_to?(:#{button_name}_able?) && ! #{singular}.#{button_name}_able? ), class: '#{singular}-button #{@layout_strategy.button_applied_classes} #{@layout_strategy.magic_button_classes}' %>" +
|
79
85
|
"<% end %>"
|
80
86
|
}.join("\n")
|
81
87
|
end
|
@@ -88,7 +94,18 @@ module HotGlue
|
|
88
94
|
|
89
95
|
size = layout_object[:columns][:bootstrap_column_width][i]
|
90
96
|
"<div class='#{layout_strategy.column_classes_for_column_headings(size)} hg-heading-row heading--#{singular}--#{column.join("-")}' " + col_style + ">" +
|
91
|
-
column.map(&:to_s).map{|col_name|
|
97
|
+
column.map(&:to_s).map{|col_name|
|
98
|
+
the_output = "#{col_name.humanize}"
|
99
|
+
if invisible_update.include?(col_name.to_sym)
|
100
|
+
if_statements = []
|
101
|
+
if_statements << "false" if invisible_update.include?(col_name.to_sym)
|
102
|
+
# if_statements << "@action == 'new'" if invisible_create.include?(col_name.to_sym)
|
103
|
+
the_output = "<% if ( " + if_statements.join(" || ") + " || policy(#{@plural}).#{col_name}_able? ) %>" +
|
104
|
+
+ the_output + "<% end %>"
|
105
|
+
|
106
|
+
end
|
107
|
+
the_output
|
108
|
+
}.join("<br />") + "</div>"
|
92
109
|
}.join("\n")
|
93
110
|
return result
|
94
111
|
end
|
@@ -160,7 +177,6 @@ module HotGlue
|
|
160
177
|
"<% if @action == 'edit' %>" + columns_map[col].form_show_only_output + "<% else %>" + columns_map[col].form_field_output + "<% end %>"
|
161
178
|
elsif update_show_only.include?(col) && @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
|
162
179
|
"<% if @action == 'new' && policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
|
163
|
-
|
164
180
|
# show only on the update action overrides any pundit policy
|
165
181
|
elsif @pundit && eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym)
|
166
182
|
"<% if policy(@#{singular}).#{col}_able? %>" + columns_map[col].form_field_output + "<% else %>" + columns_map[col].form_show_only_output + "<% end %>"
|
@@ -178,17 +194,35 @@ module HotGlue
|
|
178
194
|
data_attr = " data-#{@stimmify}-target='#{col_target}Wrapper'"
|
179
195
|
end
|
180
196
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
197
|
+
|
198
|
+
the_output = add_spaces_each_line( "\n <span #{@tinymce_stimulus_controller}class='<%= \"alert alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{data_attr} >\n" +
|
199
|
+
add_spaces_each_line( (form_labels_position == 'before' ? (the_label || "") + "<br />\n" : "") +
|
200
|
+
+ field_result +
|
201
|
+
(form_labels_position == 'after' ? ( columns_map[col].newline_after_field? ? "<br />\n" : "") + (the_label || "") : "") , 4) +
|
202
|
+
"\n </span>\n ", 2)
|
203
|
+
|
204
|
+
|
205
|
+
if hidden_create.include?(col.to_sym) || hidden_update.include?(col.to_sym)
|
206
|
+
if_statements = []
|
207
|
+
if_statements << "@action == 'edit'" if hidden_update.include?(col.to_sym)
|
208
|
+
if_statements << "@action == 'new'" if hidden_create.include?(col.to_sym)
|
209
|
+
|
210
|
+
the_output = "<% if " + if_statements.join(" || ") + " %>" +
|
211
|
+
columns_map[col].hidden_output + "<% else %>" + the_output + "<% end %>"
|
189
212
|
end
|
190
213
|
|
214
|
+
if invisible_create.include?(col) || invisible_update.include?(col)
|
215
|
+
if_statements = []
|
216
|
+
if_statements << "@action == 'edit'" if invisible_update.include?(col.to_sym)
|
217
|
+
if_statements << "@action == 'new'" if invisible_create.include?(col.to_sym)
|
191
218
|
|
219
|
+
the_output = "<% if !(" + if_statements.join(" || ") + ") || policy(@#{singular}).#{col}_able? %>" +
|
220
|
+
+ the_output + "<% end %>"
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
the_output
|
192
226
|
}.join("") + "\n </div>"
|
193
227
|
}.join("\n")
|
194
228
|
return result
|
@@ -233,7 +267,21 @@ module HotGlue
|
|
233
267
|
|
234
268
|
label = "<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
|
235
269
|
|
236
|
-
"#{inline_list_labels == 'before' ? label + "<br/>" : ''}#{field_output}#{inline_list_labels == 'after' ? "<br/>" + label : ''}"
|
270
|
+
the_output = "#{inline_list_labels == 'before' ? label + "<br/>" : ''}#{field_output}#{inline_list_labels == 'after' ? "<br/>" + label : ''}"
|
271
|
+
if invisible_create.include?(col) || invisible_update.include?(col)
|
272
|
+
if_statements = []
|
273
|
+
if invisible_update.include?(col.to_sym) && invisible_create.include?(col.to_sym)
|
274
|
+
# elsif invisible_create.include?(col.to_sym)
|
275
|
+
# if_statements << "!(@action == 'new')"
|
276
|
+
else
|
277
|
+
if_statements << "@action == 'edit'"
|
278
|
+
end
|
279
|
+
|
280
|
+
if_statements << " policy(#{singular}).#{col}_able?"
|
281
|
+
the_output = "<% if " + if_statements.join(" || ") + " %>" +
|
282
|
+
+ the_output + "<% end %>"
|
283
|
+
end
|
284
|
+
the_output
|
237
285
|
}.join( "<br />") + "</div>"
|
238
286
|
}.join("\n")
|
239
287
|
return result
|
@@ -29,7 +29,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
29
29
|
:form_labels_position, :no_nav_menu, :pundit,
|
30
30
|
:self_auth, :namespace_value, :record_scope, :related_sets,
|
31
31
|
:search_clear_button, :search_autosearch, :include_object_names,
|
32
|
-
:stimmify, :stimmify_camel, :
|
32
|
+
:stimmify, :stimmify_camel, :hidden_create, :hidden_update,
|
33
|
+
:invisible_create, :invisible_update
|
33
34
|
# important: using an attr_accessor called :namespace indirectly causes a conflict with Rails class_name method
|
34
35
|
# so we use namespace_value instead
|
35
36
|
|
@@ -58,6 +59,12 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
58
59
|
class_option :show_only, type: :string, default: ""
|
59
60
|
class_option :update_show_only, type: :string, default: ""
|
60
61
|
class_option :hidden, type: :string, default: ""
|
62
|
+
class_option :hidden_create, type: :string, default: ""
|
63
|
+
class_option :hidden_update, type: :string, default: ""
|
64
|
+
class_option :invisible, type: :string, default: ""
|
65
|
+
class_option :invisible_create, type: :string, default: ""
|
66
|
+
class_option :invisible_update, type: :string, default: ""
|
67
|
+
|
61
68
|
class_option :ujs_syntax, type: :boolean, default: nil
|
62
69
|
class_option :downnest, type: :string, default: nil
|
63
70
|
class_option :magic_buttons, type: :string, default: nil
|
@@ -231,11 +238,29 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
231
238
|
puts "show only field #{@show_only}}"
|
232
239
|
end
|
233
240
|
|
234
|
-
@
|
235
|
-
|
236
|
-
|
241
|
+
@hidden_all = options['hidden'].split(",").collect(&:to_sym)
|
242
|
+
@hidden_create = options['hidden_create'].split(",").collect(&:to_sym)
|
243
|
+
@hidden_update = options['hidden_update'].split(",").collect(&:to_sym)
|
244
|
+
@hidden_update.concat(@hidden_all) if @hidden_all.any?
|
245
|
+
@hidden_create.concat(@hidden_all) if @hidden_all.any?
|
246
|
+
@hidden_create.uniq!
|
247
|
+
@hidden_update.uniq!
|
248
|
+
|
249
|
+
if @hidden_create.any? || @hidden_update.any? || @hidden_all.any?
|
250
|
+
puts "hidden update fields #{@hidden_update}}"
|
251
|
+
puts "hidden create fields #{@hidden_create}}"
|
237
252
|
end
|
238
253
|
|
254
|
+
|
255
|
+
@invisible_all = options['invisible'].split(",").collect(&:to_sym)
|
256
|
+
@invisible_create = options['invisible_create'].split(",").collect(&:to_sym)
|
257
|
+
@invisible_update = options['invisible_update'].split(",").collect(&:to_sym)
|
258
|
+
@invisible_update.concat(@invisible_all) if @invisible_all.any?
|
259
|
+
@invisible_update.uniq!
|
260
|
+
@invisible_create.concat(@invisible_all) if @invisible_all.any?
|
261
|
+
@invisible_create.uniq!
|
262
|
+
|
263
|
+
|
239
264
|
@modify_as = {}
|
240
265
|
if !options['modify'].empty?
|
241
266
|
modify_input = options['modify'].split(",")
|
@@ -302,6 +327,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
302
327
|
@new_button_label = options['new_button_label'] || (eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? "New " + eval("#{class_name}.class_variable_get(:@@table_label_singular)") : "New " + singular.gsub("_", " ").titleize)
|
303
328
|
@new_form_heading = options['new_form_heading'] || "New #{@label}"
|
304
329
|
|
330
|
+
# @table_display_name_singular = (eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? eval("#{class_name}.class_variable_get(:@@table_label_singular)") : singular.gsub("_", " ").titleize)
|
331
|
+
@table_display_name_plural = (eval("#{class_name}.class_variable_defined?(:@@table_label_plural)") ? eval("#{class_name}.class_variable_get(:@@table_label_plural)") : plural.gsub("_", " ").titleize)
|
332
|
+
|
305
333
|
setup_hawk_keys
|
306
334
|
@form_placeholder_labels = options['form_placeholder_labels'] # true or false
|
307
335
|
@inline_list_labels = options['inline_list_labels'] || get_default_from_config(key: :inline_list_labels) || 'omit' # 'before','after','omit'
|
@@ -358,11 +386,19 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
358
386
|
|
359
387
|
@no_nav_menu = options['no_nav_menu']
|
360
388
|
|
389
|
+
if get_default_from_config(key: :pundit_default)
|
390
|
+
raise "please note the config setting `pundit_default` has been renamed `pundit`. please update your hot_glue.yml file"
|
391
|
+
end
|
392
|
+
|
361
393
|
if @pundit.nil?
|
362
|
-
@pundit = get_default_from_config(key: :
|
394
|
+
@pundit = get_default_from_config(key: :pundit)
|
363
395
|
end
|
364
396
|
|
365
397
|
|
398
|
+
if (@invisible_create + @invisible_update).any? && !@pundit
|
399
|
+
raise "you specified invisible fields without using Pundit. please remove the invisible fields or use --pundit"
|
400
|
+
end
|
401
|
+
|
366
402
|
if options['include'].include?(":") && @smart_layout
|
367
403
|
raise HotGlue::Error, "You specified both --smart-layout and also specified grouping mode (there is a : character in your field include list); you must remove the colon(s) from your --include tag or remove the --smart-layout option"
|
368
404
|
end
|
@@ -653,6 +689,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
653
689
|
update_show_only: @update_show_only,
|
654
690
|
singular_class: singular_class,
|
655
691
|
singular: singular,
|
692
|
+
plural: @plural,
|
656
693
|
hawk_keys: @hawk_keys,
|
657
694
|
ownership_field: @ownership_field,
|
658
695
|
form_labels_position: @form_labels_position,
|
@@ -670,7 +707,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
670
707
|
form_path: form_path_new_helper,
|
671
708
|
stimmify: @stimmify,
|
672
709
|
stimmify_camel: @stimmify_camel,
|
673
|
-
|
710
|
+
hidden_create: @hidden_create,
|
711
|
+
hidden_update: @hidden_update,
|
712
|
+
invisible_create: @invisible_create,
|
713
|
+
invisible_update: @invisible_update,
|
674
714
|
)
|
675
715
|
elsif @markup == "slim"
|
676
716
|
raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
|
@@ -98,8 +98,8 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
98
98
|
<% if @pundit && !@pundit_policy_override %>
|
99
99
|
authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
|
100
100
|
skip_authorization
|
101
|
-
raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.new?<% end
|
102
|
-
@action = 'new'
|
101
|
+
raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.new?<% end %>
|
102
|
+
@action = 'new' <% if @pundit %>
|
103
103
|
rescue Pundit::NotAuthorizedError
|
104
104
|
flash[:alert] = 'You are not authorized to perform this action.'
|
105
105
|
load_all_<%= plural %>
|
@@ -135,7 +135,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
135
135
|
instance_last_item: true,
|
136
136
|
put_form: true).gsub("(#{singular}", "(@#{singular}") %><% end %>
|
137
137
|
else
|
138
|
-
flash[:alert] = "Oops, your <%=
|
138
|
+
flash[:alert] = "Oops, your <%= @label %> could not be created. #{@hawk_alarm}"
|
139
139
|
@action = 'new'
|
140
140
|
<% unless @display_edit_after_create %>render :create, status: :unprocessable_entity<% else %>render :new , status: :unprocessable_entity<% end %>
|
141
141
|
end<% if @pundit %>
|
@@ -186,8 +186,13 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
186
186
|
flash[:alert] = nil
|
187
187
|
<% @magic_buttons.each do |button| %>
|
188
188
|
if <%= singular_name %>_params[:__<%= button %>]
|
189
|
-
|
190
|
-
|
189
|
+
|
190
|
+
if res = @<%= singular_name %>.<%= button %>!
|
191
|
+
flash[:notice] << "<% singular %> <%= button.titlecase %>"
|
192
|
+
flash[:notice] << " #{res}" if res.is_a?(String)
|
193
|
+
else
|
194
|
+
flash[:alert] = " <%= button.titlecase %> failed."
|
195
|
+
end
|
191
196
|
end
|
192
197
|
<% end %>
|
193
198
|
|
@@ -233,7 +238,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
233
238
|
redirect_to <%= path_helper_plural(false) %>
|
234
239
|
<% end %>
|
235
240
|
else
|
236
|
-
flash[:alert] = "<%=
|
241
|
+
flash[:alert] = "<%= @label %> could not be saved. #{@hawk_alarm}"
|
237
242
|
<%= @alt_lookups.collect{ |k,v|
|
238
243
|
assoc = k.gsub("_id","")
|
239
244
|
"@#{singular }.#{k} = #{class_name}.find(@#{singular }.id).person.id if @#{singular }.errors.include?(:#{assoc})"
|
@@ -254,10 +259,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
254
259
|
skip_authorization
|
255
260
|
raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.destroy?<% end %>
|
256
261
|
begin
|
257
|
-
@<%=singular_name%>.destroy
|
258
|
-
flash[:notice] = '<%=
|
259
|
-
rescue
|
260
|
-
flash[:alert] = '<%=
|
262
|
+
@<%=singular_name%>.destroy!
|
263
|
+
flash[:notice] = '<%= @label %> successfully deleted'
|
264
|
+
rescue ActiveRecord::RecordNotDestroyed => e
|
265
|
+
flash[:alert] = '<%= @label %> could not be deleted'
|
261
266
|
end
|
262
267
|
<%= post_action_parental_updates.join("\n ") %>
|
263
268
|
load_all_<%= plural %><% if @pundit %>
|
@@ -279,12 +284,23 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
279
284
|
end<% end %><% end %>
|
280
285
|
|
281
286
|
def <%=singular_name%>_params
|
282
|
-
|
287
|
+
fields = <%= ((fields_filtered_for_strong_params - @show_only) + @magic_buttons.collect{|x| "__#{x}"}).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "#{rs[:association_ids_method]}: []"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
|
288
|
+
params.require(:<%= testing_name %>).permit(fields)
|
283
289
|
end<% if @update_show_only %>
|
284
290
|
|
285
291
|
<% unless @no_edit %>
|
286
292
|
def update_<%=singular_name%>_params
|
287
|
-
|
293
|
+
fields = <%= ((fields_filtered_for_strong_params - @update_show_only) + @magic_buttons.collect{|x| "__#{x}"}).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "#{rs[:association_ids_method]}: []"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
|
294
|
+
<%= (fields_filtered_for_strong_params - @update_show_only).collect{|col|
|
295
|
+
# TODO : fields not on show only also not invisible should be checked here
|
296
|
+
# for _able? methods and added only when able
|
297
|
+
if (@invisible_create.include?(col) || eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym))
|
298
|
+
"fields.delete :#{col} if !policy(@#{singular}).#{col}_able?"
|
299
|
+
else
|
300
|
+
nil
|
301
|
+
end
|
302
|
+
}.compact.join("\n ") %>
|
303
|
+
params.require(:<%= testing_name %>).permit(fields)
|
288
304
|
end<% end %>
|
289
305
|
<% end %>
|
290
306
|
|
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.6.
|
4
|
+
version: 0.6.20
|
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: 2025-
|
11
|
+
date: 2025-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|