hot-glue 0.6.19 → 0.6.21
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 +336 -223
- data/app/helpers/hot_glue/controller_helper.rb +24 -9
- data/lib/generators/hot_glue/fields/field.rb +6 -3
- data/lib/generators/hot_glue/fields/time_field.rb +1 -1
- 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 +59 -14
- data/lib/generators/hot_glue/templates/controller.rb.erb +25 -11
- data/lib/hotglue/version.rb +1 -1
- metadata +2 -2
@@ -74,20 +74,31 @@ module HotGlue
|
|
74
74
|
(Time.now.utc.month == 11 && Time.now.utc.day < (7 - Time.now.utc.wday))
|
75
75
|
end
|
76
76
|
|
77
|
-
def modify_date_inputs_on_params(modified_params, current_user_object = nil, field_list =
|
78
|
-
|
77
|
+
def modify_date_inputs_on_params(modified_params, current_user_object = nil, field_list = {})
|
78
|
+
|
79
|
+
use_timezone = if current_user_object.try(:timezone)
|
80
|
+
(ActiveSupport::TimeZone[current_user_object.timezone])
|
81
|
+
else
|
82
|
+
Time.zone
|
83
|
+
end
|
84
|
+
|
85
|
+
|
79
86
|
uses_dst = (current_user_object.try(:locale_uses_dst)) || false
|
80
87
|
|
81
88
|
modified_params = modified_params.tap do |params|
|
82
89
|
params.keys.each{|k|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
include_me = field_list.include?(k.to_sym)
|
90
|
+
if field_list.is_a?(Hash)
|
91
|
+
include_me = field_list[k.to_sym].present?
|
92
|
+
elsif field_list.is_a?(Array)
|
93
|
+
field_list.include?(k.to_sym)
|
88
94
|
end
|
95
|
+
|
96
|
+
parsables = {datetime: "%Y-%m-%d %H:%M %z",
|
97
|
+
time: "%H:%M %z"}
|
98
|
+
|
89
99
|
if include_me && params[k].present?
|
90
100
|
if use_timezone
|
101
|
+
|
91
102
|
parse_date = "#{params[k].gsub("T", " ")} #{use_timezone.formatted_offset}"
|
92
103
|
# note: as according to https://stackoverflow.com/questions/20111413/html5-datetime-local-control-how-to-hide-seconds
|
93
104
|
# there is no way to set the seconds to 00 in the datetime-local input field
|
@@ -96,8 +107,12 @@ module HotGlue
|
|
96
107
|
# if they already exist in your database, you should zero them out
|
97
108
|
# or apply .change(sec: 0) when displaying them as output in the form
|
98
109
|
# this will prevent seconds from being added by the browser
|
99
|
-
|
100
|
-
|
110
|
+
if field_list.is_a?(Array)
|
111
|
+
parsed_time = Time.strptime(parse_date, "%Y-%m-%d %H:%M %z")
|
112
|
+
else
|
113
|
+
parsed_time = Time.strptime(parse_date, parsables[field_list[k.to_sym]])
|
114
|
+
end
|
115
|
+
# parsed_time = parsed_time.to_time - 60.minutes if uses_dst && is_dst_now?
|
101
116
|
params[k] = parsed_time
|
102
117
|
end
|
103
118
|
end
|
@@ -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(
|
@@ -33,11 +33,13 @@ 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
|
|
40
41
|
|
42
|
+
|
41
43
|
# TODO: remove knowledge of subclasses from Field
|
42
44
|
unless self.class == AttachmentField || self.class == RelatedSetField
|
43
45
|
@sql_type = eval("#{class_name}.columns_hash['#{name}']").sql_type
|
@@ -193,7 +195,8 @@ class Field
|
|
193
195
|
end
|
194
196
|
|
195
197
|
def modify_binary?
|
196
|
-
|
198
|
+
return false if !modify_as
|
199
|
+
modify_as[:binary]
|
197
200
|
end
|
198
201
|
|
199
202
|
def display_boolean_as
|
@@ -10,7 +10,7 @@ class TimeField < Field
|
|
10
10
|
|
11
11
|
def line_field_output
|
12
12
|
"<% unless #{singular}.#{name}.nil? %>
|
13
|
-
<%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%l:%M %p ') %>
|
13
|
+
<%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%l:%M %p %Z') %>
|
14
14
|
<% else %>
|
15
15
|
<span class=''>MISSING</span>
|
16
16
|
<% end %>"
|
@@ -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
|
@@ -99,6 +106,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
99
106
|
class_option :code_after_create, default: nil
|
100
107
|
class_option :code_before_update, default: nil
|
101
108
|
class_option :code_after_update, default: nil
|
109
|
+
class_option :code_after_new, default: nil
|
102
110
|
class_option :record_scope, default: nil
|
103
111
|
class_option :no_nav_menu, type: :boolean, default: false # suppress writing to _nav template
|
104
112
|
class_option :include_object_names, type: :boolean, default: false
|
@@ -231,11 +239,29 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
231
239
|
puts "show only field #{@show_only}}"
|
232
240
|
end
|
233
241
|
|
234
|
-
@
|
235
|
-
|
236
|
-
|
242
|
+
@hidden_all = options['hidden'].split(",").collect(&:to_sym)
|
243
|
+
@hidden_create = options['hidden_create'].split(",").collect(&:to_sym)
|
244
|
+
@hidden_update = options['hidden_update'].split(",").collect(&:to_sym)
|
245
|
+
@hidden_update.concat(@hidden_all) if @hidden_all.any?
|
246
|
+
@hidden_create.concat(@hidden_all) if @hidden_all.any?
|
247
|
+
@hidden_create.uniq!
|
248
|
+
@hidden_update.uniq!
|
249
|
+
|
250
|
+
if @hidden_create.any? || @hidden_update.any? || @hidden_all.any?
|
251
|
+
puts "hidden update fields #{@hidden_update}}"
|
252
|
+
puts "hidden create fields #{@hidden_create}}"
|
237
253
|
end
|
238
254
|
|
255
|
+
|
256
|
+
@invisible_all = options['invisible'].split(",").collect(&:to_sym)
|
257
|
+
@invisible_create = options['invisible_create'].split(",").collect(&:to_sym)
|
258
|
+
@invisible_update = options['invisible_update'].split(",").collect(&:to_sym)
|
259
|
+
@invisible_update.concat(@invisible_all) if @invisible_all.any?
|
260
|
+
@invisible_update.uniq!
|
261
|
+
@invisible_create.concat(@invisible_all) if @invisible_all.any?
|
262
|
+
@invisible_create.uniq!
|
263
|
+
|
264
|
+
|
239
265
|
@modify_as = {}
|
240
266
|
if !options['modify'].empty?
|
241
267
|
modify_input = options['modify'].split(",")
|
@@ -302,6 +328,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
302
328
|
@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
329
|
@new_form_heading = options['new_form_heading'] || "New #{@label}"
|
304
330
|
|
331
|
+
# @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)
|
332
|
+
@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)
|
333
|
+
|
305
334
|
setup_hawk_keys
|
306
335
|
@form_placeholder_labels = options['form_placeholder_labels'] # true or false
|
307
336
|
@inline_list_labels = options['inline_list_labels'] || get_default_from_config(key: :inline_list_labels) || 'omit' # 'before','after','omit'
|
@@ -358,11 +387,19 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
358
387
|
|
359
388
|
@no_nav_menu = options['no_nav_menu']
|
360
389
|
|
390
|
+
if get_default_from_config(key: :pundit_default)
|
391
|
+
raise "please note the config setting `pundit_default` has been renamed `pundit`. please update your hot_glue.yml file"
|
392
|
+
end
|
393
|
+
|
361
394
|
if @pundit.nil?
|
362
|
-
@pundit = get_default_from_config(key: :
|
395
|
+
@pundit = get_default_from_config(key: :pundit)
|
363
396
|
end
|
364
397
|
|
365
398
|
|
399
|
+
if (@invisible_create + @invisible_update).any? && !@pundit
|
400
|
+
raise "you specified invisible fields without using Pundit. please remove the invisible fields or use --pundit"
|
401
|
+
end
|
402
|
+
|
366
403
|
if options['include'].include?(":") && @smart_layout
|
367
404
|
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
405
|
end
|
@@ -495,6 +532,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
495
532
|
@code_after_create = options['code_after_create']
|
496
533
|
@code_before_update = options['code_before_update']
|
497
534
|
@code_after_update = options['code_after_update']
|
535
|
+
@code_after_new = options['code_after_new']
|
498
536
|
|
499
537
|
buttons_width = ((!@no_edit && 1) || 0) + ((!@no_delete && 1) || 0) + @magic_buttons.count
|
500
538
|
|
@@ -653,6 +691,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
653
691
|
update_show_only: @update_show_only,
|
654
692
|
singular_class: singular_class,
|
655
693
|
singular: singular,
|
694
|
+
plural: @plural,
|
656
695
|
hawk_keys: @hawk_keys,
|
657
696
|
ownership_field: @ownership_field,
|
658
697
|
form_labels_position: @form_labels_position,
|
@@ -670,7 +709,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
670
709
|
form_path: form_path_new_helper,
|
671
710
|
stimmify: @stimmify,
|
672
711
|
stimmify_camel: @stimmify_camel,
|
673
|
-
|
712
|
+
hidden_create: @hidden_create,
|
713
|
+
hidden_update: @hidden_update,
|
714
|
+
invisible_create: @invisible_create,
|
715
|
+
invisible_update: @invisible_update,
|
674
716
|
)
|
675
717
|
elsif @markup == "slim"
|
676
718
|
raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
|
@@ -927,10 +969,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
927
969
|
#{@factory_creation}
|
928
970
|
"
|
929
971
|
res << "\n " + "@#{singular} = factory.#{singular}" unless res.include?("@#{singular} = factory.#{singular}")
|
930
|
-
res << "\n
|
931
|
-
rescue ActiveRecord::RecordInvalid
|
972
|
+
res << "\n rescue ActiveRecord::RecordInvalid
|
932
973
|
@#{singular} = factory.#{singular}
|
933
|
-
flash[:alert] = \"Oops, your #{singular} could not be created. #{@hawk_alarm}\"
|
934
974
|
@action = 'new'
|
935
975
|
end"
|
936
976
|
res
|
@@ -1134,13 +1174,17 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1134
1174
|
end
|
1135
1175
|
|
1136
1176
|
def datetime_fields_list
|
1137
|
-
@columns.
|
1138
|
-
|
1139
|
-
|
1177
|
+
@columns.each_with_object({}) do |col, hash|
|
1178
|
+
column = @the_object.columns_hash[col.to_s]
|
1179
|
+
if column && [:datetime, :time].include?(column.type)
|
1180
|
+
hash[col.to_sym] = column.type
|
1140
1181
|
end
|
1141
1182
|
end
|
1142
1183
|
end
|
1143
1184
|
|
1185
|
+
|
1186
|
+
|
1187
|
+
|
1144
1188
|
def form_path_new_helper
|
1145
1189
|
HotGlue.optionalized_ternary(namespace: @namespace,
|
1146
1190
|
target: @controller_build_folder,
|
@@ -1280,12 +1324,13 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1280
1324
|
# to know who the current user under this design
|
1281
1325
|
# for timeinput = user_centered , we need to know who the current user is
|
1282
1326
|
# so we can set the time zone to the user's time zone
|
1283
|
-
|
1327
|
+
|
1284
1328
|
if options['auth']
|
1285
1329
|
options['auth']
|
1286
1330
|
elsif @god
|
1287
|
-
# do we use current_user here
|
1288
1331
|
"nil"
|
1332
|
+
else
|
1333
|
+
@auth
|
1289
1334
|
end
|
1290
1335
|
end
|
1291
1336
|
|
@@ -95,11 +95,13 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
95
95
|
@<%= singular_name %> = <%= class_name %>.new<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>(<%= @object_owner_sym %>: <%= @object_owner_eval %>)<% end %><% elsif @object_owner_optional && any_nested? %>
|
96
96
|
@<%= singular_name %> = <%= class_name %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}))<% else %>
|
97
97
|
@<%= singular_name %> = <%= class_name %>.new(<% if any_nested? %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% end %>
|
98
|
+
<%= @code_after_new ? @code_after_new.gsub(";","\n") + "\n" : "" %>
|
99
|
+
|
98
100
|
<% if @pundit && !@pundit_policy_override %>
|
99
101
|
authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
|
100
102
|
skip_authorization
|
101
|
-
raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.new?<% end
|
102
|
-
@action = 'new'
|
103
|
+
raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.new?<% end %>
|
104
|
+
@action = 'new' <% if @pundit %>
|
103
105
|
rescue Pundit::NotAuthorizedError
|
104
106
|
flash[:alert] = 'You are not authorized to perform this action.'
|
105
107
|
load_all_<%= plural %>
|
@@ -135,7 +137,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
135
137
|
instance_last_item: true,
|
136
138
|
put_form: true).gsub("(#{singular}", "(@#{singular}") %><% end %>
|
137
139
|
else
|
138
|
-
flash[:alert] = "Oops, your <%=
|
140
|
+
flash[:alert] = "Oops, your <%= @label %> could not be created. #{@hawk_alarm}"
|
139
141
|
@action = 'new'
|
140
142
|
<% unless @display_edit_after_create %>render :create, status: :unprocessable_entity<% else %>render :new , status: :unprocessable_entity<% end %>
|
141
143
|
end<% if @pundit %>
|
@@ -216,19 +218,20 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
216
218
|
<% end %>
|
217
219
|
<% if @hawk_keys.any? %> modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
|
218
220
|
<%= controller_attachment_orig_filename_pickup_syntax %>
|
221
|
+
@<%= singular_name %>.assign_attributes(modified_params)
|
219
222
|
<% if @pundit && !@pundit_policy_override %>
|
220
223
|
authorize @<%= singular_name %>
|
221
224
|
<%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
|
222
225
|
|
223
|
-
if @<%= singular_name %>.
|
226
|
+
if @<%= singular_name %>.save
|
224
227
|
|
225
228
|
<% elsif @pundit && @pundit_policy_override %>
|
226
229
|
skip_authorization
|
227
230
|
raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.update?
|
228
|
-
if @<%= singular_name %>.
|
231
|
+
if @<%= singular_name %>.save
|
229
232
|
<% else %>
|
230
233
|
<%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
|
231
|
-
if @<%= singular_name %>.
|
234
|
+
if @<%= singular_name %>.save<% end %>
|
232
235
|
<%= post_action_parental_updates.compact.join("\n ") %>
|
233
236
|
<%= @code_after_update ? "\n " + @code_after_update.gsub(";", "\n") : "" %>
|
234
237
|
<% if @display_list_after_update %> load_all_<%= plural %><% end %>
|
@@ -238,7 +241,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
238
241
|
redirect_to <%= path_helper_plural(false) %>
|
239
242
|
<% end %>
|
240
243
|
else
|
241
|
-
flash[:alert] = "<%=
|
244
|
+
flash[:alert] = "<%= @label %> could not be saved. #{@hawk_alarm}"
|
242
245
|
<%= @alt_lookups.collect{ |k,v|
|
243
246
|
assoc = k.gsub("_id","")
|
244
247
|
"@#{singular }.#{k} = #{class_name}.find(@#{singular }.id).person.id if @#{singular }.errors.include?(:#{assoc})"
|
@@ -260,9 +263,9 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
260
263
|
raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.destroy?<% end %>
|
261
264
|
begin
|
262
265
|
@<%=singular_name%>.destroy!
|
263
|
-
flash[:notice] = '<%=
|
266
|
+
flash[:notice] = '<%= @label %> successfully deleted'
|
264
267
|
rescue ActiveRecord::RecordNotDestroyed => e
|
265
|
-
flash[:alert] = '<%=
|
268
|
+
flash[:alert] = '<%= @label %> could not be deleted'
|
266
269
|
end
|
267
270
|
<%= post_action_parental_updates.join("\n ") %>
|
268
271
|
load_all_<%= plural %><% if @pundit %>
|
@@ -284,12 +287,23 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
284
287
|
end<% end %><% end %>
|
285
288
|
|
286
289
|
def <%=singular_name%>_params
|
287
|
-
|
290
|
+
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? %>
|
291
|
+
params.require(:<%= testing_name %>).permit(fields)
|
288
292
|
end<% if @update_show_only %>
|
289
293
|
|
290
294
|
<% unless @no_edit %>
|
291
295
|
def update_<%=singular_name%>_params
|
292
|
-
|
296
|
+
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? %>
|
297
|
+
<%= (fields_filtered_for_strong_params - @update_show_only).collect{|col|
|
298
|
+
# TODO : fields not on show only also not invisible should be checked here
|
299
|
+
# for _able? methods and added only when able
|
300
|
+
if (@invisible_create.include?(col) || eval("defined? #{singular_class}Policy") && eval("#{singular_class}Policy").instance_methods.include?("#{col}_able?".to_sym))
|
301
|
+
"fields.delete :#{col} if !policy(@#{singular}).#{col}_able?"
|
302
|
+
else
|
303
|
+
nil
|
304
|
+
end
|
305
|
+
}.compact.join("\n ") %>
|
306
|
+
params.require(:<%= testing_name %>).permit(fields)
|
293
307
|
end<% end %>
|
294
308
|
<% end %>
|
295
309
|
|
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.21
|
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-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|