hot-glue 0.5.15 → 0.5.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/Gemfile.lock +4 -4
- data/README.md +91 -4
- data/lib/generators/hot_glue/field_factory.rb +2 -1
- data/lib/generators/hot_glue/fields/association_field.rb +1 -1
- data/lib/generators/hot_glue/fields/attachment_field.rb +1 -1
- data/lib/generators/hot_glue/fields/boolean_field.rb +15 -6
- data/lib/generators/hot_glue/fields/date_time_field.rb +19 -3
- data/lib/generators/hot_glue/fields/field.rb +61 -17
- data/lib/generators/hot_glue/fields/float_field.rb +6 -4
- data/lib/generators/hot_glue/fields/uuid_field.rb +1 -1
- data/lib/generators/hot_glue/layout/builder.rb +4 -2
- data/lib/generators/hot_glue/nav_template_generator.rb +22 -0
- data/lib/generators/hot_glue/scaffold_generator.rb +160 -148
- data/lib/generators/hot_glue/templates/controller.rb.erb +2 -2
- data/lib/generators/hot_glue/templates/erb/_edit.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_nav.html.erb +3 -0
- data/lib/generators/hot_glue/templates/system_spec.rb.erb +1 -1
- data/lib/hotglue/version.rb +1 -1
- metadata +4 -2
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'rails/generators/erb/scaffold/scaffold_generator'
|
3
2
|
require_relative './default_config_loader'
|
4
3
|
require 'ffaker'
|
@@ -12,23 +11,15 @@ require_relative './layout_strategy/bootstrap'
|
|
12
11
|
require_relative './layout_strategy/hot_glue'
|
13
12
|
require_relative './layout_strategy/tailwind'
|
14
13
|
|
15
|
-
|
16
|
-
|
17
14
|
class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
18
15
|
include DefaultConfigLoader
|
19
16
|
hook_for :form_builder, :as => :scaffold
|
20
17
|
|
21
18
|
source_root File.expand_path('templates', __dir__)
|
22
|
-
attr_accessor :alt_lookups, :attachments, :auth,
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:button_icons,
|
27
|
-
:hawk_keys, :layout_object,
|
28
|
-
:nest_with,
|
29
|
-
:path, :plural,
|
30
|
-
:sample_file_path, :singular, :singular_class, :smart_layout,
|
31
|
-
:stacked_downnesting, :update_show_only, :ownership_field,
|
19
|
+
attr_accessor :alt_lookups, :attachments, :auth, :big_edit, :button_icons, :bootstrap_column_width, :columns,
|
20
|
+
:downnest_children, :downnest_object, :hawk_keys, :layout_object, :modify,
|
21
|
+
:nest_with, :path, :plural, :sample_file_path, :show_only_data, :singular,
|
22
|
+
:singular_class, :smart_layout, :stacked_downnesting, :update_show_only, :ownership_field,
|
32
23
|
:layout_strategy, :form_placeholder_labels, :form_labels_position
|
33
24
|
|
34
25
|
class_option :singular, type: :string, default: nil
|
@@ -77,7 +68,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
77
68
|
|
78
69
|
# determines if the labels show up BEFORE or AFTER on the NEW/EDIT (form)
|
79
70
|
class_option :form_labels_position, type: :string, default: 'after' # choices are before, after, omit
|
80
|
-
class_option :form_placeholder_labels, type: :boolean,
|
71
|
+
class_option :form_placeholder_labels, type: :boolean, default: false # puts the field names into the placeholder labels
|
81
72
|
|
82
73
|
# determines if labels appear within the rows of the VIEWABLE list (does NOT affect the list heading)
|
83
74
|
class_option :inline_list_labels, default: 'omit' # choices are before, after, omit
|
@@ -85,8 +76,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
85
76
|
class_option :alt_foreign_key_lookup, default: '' #
|
86
77
|
class_option :attachments, default: ''
|
87
78
|
class_option :stacked_downnesting, default: false
|
88
|
-
class_option :bootstrap_column_width, default: nil #must be nil to detect if user has not passed
|
79
|
+
class_option :bootstrap_column_width, default: nil # must be nil to detect if user has not passed
|
89
80
|
class_option :button_icons, default: nil
|
81
|
+
class_option :modify, default: {}
|
90
82
|
|
91
83
|
def initialize(*meta_args)
|
92
84
|
super
|
@@ -102,17 +94,16 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
102
94
|
@meta_args = meta_args
|
103
95
|
|
104
96
|
if options['specs_only'] && options['no_specs']
|
105
|
-
raise(HotGlue::Error,
|
97
|
+
raise(HotGlue::Error, "*** 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. Aborting.")
|
106
98
|
end
|
107
99
|
|
108
100
|
if !options['exclude'].empty? && !options['include'].empty?
|
109
|
-
exit_message =
|
101
|
+
exit_message = "*** Oops: You seem to have specified both --include and --exclude. Please use one or the other. Aborting."
|
110
102
|
puts exit_message
|
111
103
|
|
112
104
|
raise(HotGlue::Error, exit_message)
|
113
105
|
end
|
114
106
|
|
115
|
-
|
116
107
|
if @stimulus_syntax.nil?
|
117
108
|
@stimulus_syntax = true
|
118
109
|
end
|
@@ -122,7 +113,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
122
113
|
raise(HotGlue::Error, message)
|
123
114
|
end
|
124
115
|
|
125
|
-
@markup =
|
116
|
+
@markup = get_default_from_config(key: :markup)
|
126
117
|
@sample_file_path = get_default_from_config(key: :sample_file_path)
|
127
118
|
@bootstrap_column_width ||= get_default_from_config(key: :bootstrap_column_width) || 2
|
128
119
|
|
@@ -157,13 +148,13 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
157
148
|
|
158
149
|
@plural = options['plural'] || @singular.pluralize # respects what you set in inflections.rb, to override, use plural option
|
159
150
|
@namespace = options['namespace'] || nil
|
160
|
-
use_controller_name =
|
161
|
-
@controller_build_name = ((
|
151
|
+
use_controller_name = plural.titleize.gsub(" ", "")
|
152
|
+
@controller_build_name = ((@namespace.titleize.gsub(" ", "") + "::" if @namespace) || "") + use_controller_name + "Controller"
|
162
153
|
@controller_build_folder = use_controller_name.underscore
|
163
154
|
@controller_build_folder_singular = singular
|
164
155
|
|
165
156
|
@auth = options['auth'] || "current_user"
|
166
|
-
@auth_identifier = options['auth_identifier'] || (
|
157
|
+
@auth_identifier = options['auth_identifier'] || (!@god && @auth.gsub("current_", "")) || nil
|
167
158
|
|
168
159
|
if options['nest']
|
169
160
|
raise HotGlue::Error, "STOP: the flag --nest has been replaced with --nested; please re-run using the --nested flag"
|
@@ -180,20 +171,48 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
180
171
|
@include_fields = []
|
181
172
|
|
182
173
|
# semicolon to denote layout columns; commas separate fields
|
183
|
-
@include_fields += options['include'].split(":").collect{|x|x.split(",")}.flatten.collect(&:to_sym)
|
174
|
+
@include_fields += options['include'].split(":").collect { |x| x.split(",") }.flatten.collect(&:to_sym)
|
184
175
|
end
|
185
176
|
|
186
|
-
@
|
187
|
-
if !options['show_only'].empty?
|
188
|
-
|
177
|
+
# @show_only_data = {}
|
178
|
+
# if !options['show_only'].empty?
|
179
|
+
# show_only_input = options['show_only'].split(",")
|
180
|
+
# show_only_input.each do |setting|
|
181
|
+
# if setting.include?("[")
|
182
|
+
# setting =~ /(.*)\[(.*)\]/
|
183
|
+
# key, lookup_as = $1, $2
|
184
|
+
# @show_only_data[key.to_sym] = {cast: $2 }
|
185
|
+
# else
|
186
|
+
# @show_only_data[setting.to_sym] = {cast: nil}
|
187
|
+
# end
|
188
|
+
# end
|
189
|
+
# end
|
190
|
+
|
191
|
+
@show_only = options['show_only'].split(",").collect(&:to_sym)
|
192
|
+
if @show_only.any?
|
193
|
+
puts "show only field #{@show_only}}"
|
189
194
|
end
|
190
195
|
|
196
|
+
@modify = {}
|
197
|
+
if !options['modify'].empty?
|
198
|
+
modify_input = options['modify'].split(",")
|
199
|
+
modify_input.each do |setting|
|
200
|
+
setting =~ /(.*){(.*)}/
|
201
|
+
key, lookup_as = $1, $2
|
202
|
+
|
203
|
+
if ["$"].include?($2)
|
204
|
+
@modify[key.to_sym] = {cast: $2}
|
205
|
+
elsif $2.include?("|")
|
206
|
+
binary = $2.split("|")
|
207
|
+
@modify[key.to_sym] = {binary: {truthy: binary[0], falsy: binary[1]}}
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
191
211
|
@update_show_only = []
|
192
212
|
if !options['update_show_only'].empty?
|
193
213
|
@update_show_only += options['update_show_only'].split(",").collect(&:to_sym)
|
194
214
|
end
|
195
215
|
|
196
|
-
|
197
216
|
# syntax should be xyz_id{xyz_email},abc_id{abc_email}
|
198
217
|
# instead of a drop-down for the foreign entity, a text field will be presented
|
199
218
|
# You must ALSO use a factory that contains a parameter of the same name as the 'value' (for example, `xyz_email`)
|
@@ -203,48 +222,40 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
203
222
|
@alt_foreign_key_lookup = alt_lookups_entry.each do |setting|
|
204
223
|
setting =~ /(.*){(.*)}/
|
205
224
|
key, lookup_as = $1, $2
|
206
|
-
assoc = eval("#{class_name}.reflect_on_association(:#{key.to_s.gsub("_id","")}).class_name")
|
225
|
+
assoc = eval("#{class_name}.reflect_on_association(:#{key.to_s.gsub("_id", "")}).class_name")
|
207
226
|
|
208
|
-
data = {lookup_as: lookup_as.gsub("+",""),
|
209
|
-
|
210
|
-
|
227
|
+
data = { lookup_as: lookup_as.gsub("+", ""),
|
228
|
+
assoc: assoc,
|
229
|
+
with_create: lookup_as.include?("+") }
|
211
230
|
@alt_lookups[key] = data
|
212
231
|
end
|
213
232
|
|
214
233
|
puts "------ ALT LOOKUPS for #{@alt_lookups}"
|
215
234
|
|
216
|
-
@update_alt_lookups = @alt_lookups.collect{|key, value|
|
235
|
+
@update_alt_lookups = @alt_lookups.collect { |key, value|
|
217
236
|
@update_show_only.include?(key) ?
|
218
|
-
{
|
219
|
-
: nil}.compact
|
237
|
+
{ key: value }
|
238
|
+
: nil }.compact
|
220
239
|
|
221
|
-
@label = options['label'] || (
|
222
|
-
@list_label_heading =
|
240
|
+
@label = options['label'] || (eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? eval("#{class_name}.class_variable_get(:@@table_label_singular)") : singular.gsub("_", " ").titleize)
|
241
|
+
@list_label_heading = options['list_label_heading'] || (eval("#{class_name}.class_variable_defined?(:@@table_label_plural)") ? eval("#{class_name}.class_variable_get(:@@table_label_plural)") : plural.gsub("_", " ").upcase)
|
223
242
|
|
224
|
-
@new_button_label = options['new_button_label'] || (
|
243
|
+
@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)
|
225
244
|
@new_form_heading = options['new_form_heading'] || "New #{@label}"
|
226
245
|
|
227
|
-
|
228
|
-
|
229
246
|
setup_hawk_keys
|
230
247
|
@form_placeholder_labels = options['form_placeholder_labels'] # true or false
|
231
|
-
@inline_list_labels = options['inline_list_labels']
|
232
|
-
|
248
|
+
@inline_list_labels = options['inline_list_labels'] || 'omit' # 'before','after','omit'
|
233
249
|
|
234
250
|
@form_labels_position = options['form_labels_position']
|
235
|
-
if !['before','after','omit'].include?(@form_labels_position)
|
251
|
+
if !['before', 'after', 'omit'].include?(@form_labels_position)
|
236
252
|
raise HotGlue::Error, "You passed '#{@form_labels_position}' as the setting for --form-labels-position but the only allowed options are before, after (default), and omit"
|
237
253
|
end
|
238
254
|
|
239
|
-
if !['before','after','omit'].include?(@inline_list_labels)
|
255
|
+
if !['before', 'after', 'omit'].include?(@inline_list_labels)
|
240
256
|
raise HotGlue::Error, "You passed '#{@inline_list_labels}' as the setting for --inline-list-labels but the only allowed options are before, after, and omit (default)"
|
241
257
|
end
|
242
258
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
259
|
@god = options['god'] || options['gd'] || false
|
249
260
|
@specs_only = options['specs_only'] || false
|
250
261
|
|
@@ -261,9 +272,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
261
272
|
@no_list_heading = options['no_list_heading'] || false
|
262
273
|
@stacked_downnesting = options['stacked_downnesting']
|
263
274
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
275
|
@display_list_after_update = options['display_list_after_update'] || false
|
268
276
|
@smart_layout = options['smart_layout']
|
269
277
|
|
@@ -277,7 +285,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
277
285
|
@downnest_children = [] # TODO: defactor @downnest_children in favor of downnest_object
|
278
286
|
@downnest_object = {}
|
279
287
|
if @downnest
|
280
|
-
@downnest_children = @downnest.split(",").map{|child| child.gsub("+","")}
|
288
|
+
@downnest_children = @downnest.split(",").map { |child| child.gsub("+", "") }
|
281
289
|
@downnest_object = HotGlue.construct_downnest_object(@downnest)
|
282
290
|
end
|
283
291
|
|
@@ -300,7 +308,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
300
308
|
@magic_buttons = options['magic_buttons'].split(',')
|
301
309
|
end
|
302
310
|
|
303
|
-
|
304
311
|
@small_buttons = options['small_buttons'] || false
|
305
312
|
|
306
313
|
@build_update_action = !@no_edit || !@magic_buttons.empty?
|
@@ -311,7 +318,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
311
318
|
@ujs_syntax = !defined?(Turbo::Engine)
|
312
319
|
end
|
313
320
|
|
314
|
-
|
315
321
|
# NEST CHAIN
|
316
322
|
# new syntax
|
317
323
|
# @nested_set = [
|
@@ -322,10 +328,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
322
328
|
# }]
|
323
329
|
@nested_set = []
|
324
330
|
|
325
|
-
if
|
331
|
+
if !@nested.nil?
|
326
332
|
@nested_set = @nested.split("/").collect { |arg|
|
327
333
|
is_optional = arg.start_with?("~")
|
328
|
-
arg.gsub!("~","")
|
334
|
+
arg.gsub!("~", "")
|
329
335
|
{
|
330
336
|
singular: arg,
|
331
337
|
plural: arg.pluralize,
|
@@ -343,8 +349,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
343
349
|
@object_owner_optional = false
|
344
350
|
@object_owner_name = @auth.gsub("current_", "").to_s
|
345
351
|
|
346
|
-
|
347
|
-
elsif @auth && ! @self_auth && @nested_set.none? && !@auth.include?(".")
|
352
|
+
elsif @auth && !@self_auth && @nested_set.none? && !@auth.include?(".")
|
348
353
|
@object_owner_sym = @auth.gsub("current_", "").to_sym
|
349
354
|
@object_owner_eval = @auth
|
350
355
|
@object_owner_optional = false
|
@@ -365,12 +370,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
365
370
|
end
|
366
371
|
end
|
367
372
|
|
368
|
-
|
369
373
|
@factory_creation = options['factory_creation'].gsub(";", "\n")
|
370
374
|
identify_object_owner
|
371
375
|
setup_fields
|
372
376
|
|
373
|
-
if
|
377
|
+
if (@columns - @show_only - (@ownership_field ? [@ownership_field.to_sym] : [])).empty?
|
374
378
|
@no_field_form = true
|
375
379
|
end
|
376
380
|
|
@@ -380,7 +384,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
380
384
|
@associations = []
|
381
385
|
@columns_map = {}
|
382
386
|
@columns.each do |col|
|
383
|
-
if !(@the_object.columns_hash.keys.include?(col.to_s) ||
|
387
|
+
if !(@the_object.columns_hash.keys.include?(col.to_s) || @attachments.keys.include?(col))
|
384
388
|
raise "couldn't find #{col} in either field list or attachments list"
|
385
389
|
end
|
386
390
|
|
@@ -389,7 +393,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
389
393
|
end
|
390
394
|
|
391
395
|
if @the_object.columns_hash.keys.include?(col.to_s)
|
392
|
-
type =
|
396
|
+
type = @the_object.columns_hash[col.to_s].type
|
393
397
|
elsif @attachments.keys.include?(col)
|
394
398
|
type = :attachment
|
395
399
|
end
|
@@ -404,7 +408,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
404
408
|
end
|
405
409
|
|
406
410
|
# create the template object
|
407
|
-
if
|
411
|
+
if @markup == "erb"
|
408
412
|
@template_builder = HotGlue::ErbTemplate.new(
|
409
413
|
layout_strategy: @layout_strategy,
|
410
414
|
magic_buttons: @magic_buttons,
|
@@ -422,26 +426,22 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
422
426
|
attachments: @attachments,
|
423
427
|
columns_map: @columns_map
|
424
428
|
)
|
425
|
-
elsif
|
426
|
-
raise(HotGlue::Error,
|
427
|
-
elsif
|
428
|
-
raise(HotGlue::Error,
|
429
|
+
elsif @markup == "slim"
|
430
|
+
raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
|
431
|
+
elsif @markup == "haml"
|
432
|
+
raise(HotGlue::Error, "HAML IS NOT IMPLEMENTED")
|
429
433
|
end
|
430
434
|
|
431
435
|
builder = HotGlue::Layout::Builder.new(generator: self,
|
432
|
-
|
433
|
-
|
436
|
+
include_setting: options['include'],
|
437
|
+
buttons_width: buttons_width)
|
434
438
|
@layout_object = builder.construct
|
435
439
|
|
436
|
-
|
437
|
-
|
438
440
|
@menu_file_exists = true if @nested_set.none? && File.exist?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
|
439
441
|
|
440
442
|
@turbo_streams = !!options['with_turbo_streams']
|
441
443
|
end
|
442
444
|
|
443
|
-
|
444
|
-
|
445
445
|
def setup_hawk_keys
|
446
446
|
@hawk_keys = {}
|
447
447
|
|
@@ -458,9 +458,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
458
458
|
end
|
459
459
|
|
460
460
|
hawk_scope = key.gsub("_id", "").pluralize
|
461
|
-
optional = eval(singular_class + ".reflect_on_association(:#{key.gsub('_id','')})").options[:optional]
|
461
|
+
optional = eval(singular_class + ".reflect_on_association(:#{key.gsub('_id', '')})").options[:optional]
|
462
462
|
|
463
|
-
@hawk_keys[key.to_sym] = {bind_to: [hawk_to], optional: optional}
|
463
|
+
@hawk_keys[key.to_sym] = { bind_to: [hawk_to], optional: optional }
|
464
464
|
use_shorthand = !options["hawk"].include?("{")
|
465
465
|
|
466
466
|
if use_shorthand # only include the hawk scope if using the shorthand
|
@@ -473,7 +473,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
473
473
|
end
|
474
474
|
end
|
475
475
|
|
476
|
-
|
477
476
|
def setup_attachments
|
478
477
|
@attachments = {}
|
479
478
|
|
@@ -538,7 +537,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
538
537
|
|
539
538
|
direct_upload = nil
|
540
539
|
field_for_original_filename = nil
|
541
|
-
dropzone
|
540
|
+
dropzone = nil
|
542
541
|
end
|
543
542
|
|
544
543
|
if thumbnail && !eval("#{singular_class}.reflect_on_attachment(:#{key}).variants.include?(:#{thumbnail})")
|
@@ -549,11 +548,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
549
548
|
"
|
550
549
|
end
|
551
550
|
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
dropzone: dropzone}
|
551
|
+
@attachments[key.to_sym] = { thumbnail: thumbnail,
|
552
|
+
field_for_original_filename: field_for_original_filename,
|
553
|
+
direct_upload: direct_upload,
|
554
|
+
dropzone: dropzone }
|
557
555
|
end
|
558
556
|
|
559
557
|
puts "ATTACHMENTS: #{@attachments}"
|
@@ -561,15 +559,15 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
561
559
|
end
|
562
560
|
|
563
561
|
def identify_object_owner
|
564
|
-
auth_assoc = @auth && @auth.gsub("current_","")
|
562
|
+
auth_assoc = @auth && @auth.gsub("current_", "")
|
565
563
|
|
566
|
-
if @object_owner_sym &&
|
564
|
+
if @object_owner_sym && !@self_auth
|
567
565
|
auth_assoc_field = auth_assoc + "_id" unless @god
|
568
566
|
assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
|
569
567
|
|
570
568
|
if assoc
|
571
569
|
@ownership_field = assoc.name.to_s + "_id"
|
572
|
-
elsif
|
570
|
+
elsif !@nested_set.any?
|
573
571
|
exit_message = "*** Oops: It looks like is no association `#{@object_owner_sym}` from the object #{@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."
|
574
572
|
raise(HotGlue::Error, exit_message)
|
575
573
|
|
@@ -582,7 +580,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
582
580
|
|
583
581
|
raise(HotGlue::Error, exit_message)
|
584
582
|
end
|
585
|
-
elsif
|
583
|
+
elsif @object_owner_sym && !@object_owner_eval.include?(".")
|
586
584
|
@ownership_field = @object_owner_name + "_id"
|
587
585
|
end
|
588
586
|
end
|
@@ -595,18 +593,16 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
595
593
|
:confirmation_token, :confirmed_at,
|
596
594
|
:confirmation_sent_at, :unconfirmed_email
|
597
595
|
|
598
|
-
@exclude_fields.push(
|
599
|
-
|
600
|
-
|
601
|
-
@columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
|
596
|
+
@exclude_fields.push(@ownership_field.to_sym) if !@ownership_field.nil?
|
602
597
|
|
598
|
+
@columns = @the_object.columns.map(&:name).map(&:to_sym).reject { |field| @exclude_fields.include?(field) }
|
603
599
|
|
604
600
|
else
|
605
|
-
@columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
|
601
|
+
@columns = @the_object.columns.map(&:name).map(&:to_sym).reject { |field| !@include_fields.include?(field) }
|
606
602
|
end
|
607
603
|
|
608
604
|
if @attachments.any?
|
609
|
-
puts "
|
605
|
+
puts "Adding attachments-as-columns: #{@attachments}"
|
610
606
|
@attachments.keys.each do |attachment|
|
611
607
|
@columns << attachment if !@columns.include?(attachment)
|
612
608
|
end
|
@@ -615,21 +611,16 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
615
611
|
end
|
616
612
|
end
|
617
613
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
614
|
def check_if_sample_file_is_present
|
624
615
|
if sample_file_path.nil?
|
625
616
|
puts "you have no sample file path set in config/hot_glue.yml"
|
626
617
|
settings = File.read("config/hot_glue.yml")
|
627
618
|
@sample_file_path = "spec/files/computer_code.jpg"
|
628
619
|
added_setting = ":sample_file_path: #{sample_file_path}"
|
629
|
-
File.open("config/hot_glue.yml", "w") { |f| f.write settings + "\n" +
|
620
|
+
File.open("config/hot_glue.yml", "w") { |f| f.write settings + "\n" + added_setting }
|
630
621
|
|
631
622
|
puts "adding `#{added_setting}` to config/hot_glue.yml"
|
632
|
-
elsif !
|
623
|
+
elsif !File.exist?(sample_file_path)
|
633
624
|
puts "NO SAMPLE FILE FOUND: adding sample file at #{sample_file_path}"
|
634
625
|
template "computer_code.jpg", File.join("#{filepath_prefix}spec/files/", "computer_code.jpg")
|
635
626
|
end
|
@@ -638,11 +629,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
638
629
|
end
|
639
630
|
|
640
631
|
def fields_filtered_for_email_lookups
|
641
|
-
@columns.reject{|c| @alt_lookups.keys.include?(c) } + @alt_lookups.values.map{|v| ("__lookup_#{v[:lookup_as]}").to_sym}
|
632
|
+
@columns.reject { |c| @alt_lookups.keys.include?(c) } + @alt_lookups.values.map { |v| ("__lookup_#{v[:lookup_as]}").to_sym }
|
642
633
|
end
|
643
634
|
|
644
635
|
def creation_syntax
|
645
|
-
merge_with = @alt_lookups.collect{ |key, data|
|
636
|
+
merge_with = @alt_lookups.collect { |key, data|
|
646
637
|
"#{data[:assoc].downcase}: #{data[:assoc].downcase}_factory.#{data[:assoc].downcase}"
|
647
638
|
}.join(", ")
|
648
639
|
|
@@ -686,14 +677,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
686
677
|
unless @no_specs
|
687
678
|
dest_file = File.join("#{filepath_prefix}spec/features#{namespace_with_dash}", "#{plural}_behavior_spec.rb")
|
688
679
|
|
689
|
-
if
|
680
|
+
if File.exist?(dest_file)
|
690
681
|
existing_file = File.open(dest_file)
|
691
682
|
existing_content = existing_file.read
|
692
683
|
if existing_content =~ /\#HOTGLUE-SAVESTART/
|
693
|
-
if
|
684
|
+
if existing_content !~ /\#HOTGLUE-END/
|
694
685
|
raise "Your file at #{dest_file} contains a #HOTGLUE-SAVESTART marker without #HOTGLUE-END"
|
695
686
|
end
|
696
|
-
@existing_content =
|
687
|
+
@existing_content = existing_content[(existing_content =~ /\#HOTGLUE-SAVESTART/)..(existing_content =~ /\#HOTGLUE-END/) - 1]
|
697
688
|
@existing_content << "#HOTGLUE-END"
|
698
689
|
|
699
690
|
end
|
@@ -702,7 +693,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
702
693
|
@existing_content = " #HOTGLUE-SAVESTART\n #HOTGLUE-END"
|
703
694
|
end
|
704
695
|
|
705
|
-
|
706
696
|
template "system_spec.rb.erb", dest_file
|
707
697
|
end
|
708
698
|
|
@@ -716,7 +706,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
716
706
|
end
|
717
707
|
|
718
708
|
def testing_name
|
719
|
-
singular_class.gsub("::","_").underscore
|
709
|
+
singular_class.gsub("::", "_").underscore
|
720
710
|
end
|
721
711
|
|
722
712
|
def spec_related_column_lets
|
@@ -735,7 +725,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
735
725
|
end
|
736
726
|
|
737
727
|
def columns_spec_with_sample_data
|
738
|
-
@columns_map.map
|
728
|
+
@columns_map.map { |col, col_object|
|
739
729
|
unless col_object.is_a?(AssociationField)
|
740
730
|
random_data = col_object.spec_random_data
|
741
731
|
col.to_s + ": '" + random_data.to_s + "'"
|
@@ -744,14 +734,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
744
734
|
end
|
745
735
|
|
746
736
|
def regenerate_me_code
|
747
|
-
"rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].collect{|x| x.gsub(/\s*=\s*([\S\s]+)/, '=\'\1\'')}.join(" ")}"
|
737
|
+
"rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].collect { |x| x.gsub(/\s*=\s*([\S\s]+)/, '=\'\1\'') }.join(" ")}"
|
748
738
|
end
|
749
739
|
|
750
740
|
def object_parent_mapping_as_argument_for_specs
|
751
741
|
|
752
742
|
if @self_auth
|
753
743
|
""
|
754
|
-
elsif @nested_set.any? &&
|
744
|
+
elsif @nested_set.any? && !@nested_set.last[:optional]
|
755
745
|
", " + @nested_set.last[:singular] + ": " + @nested_set.last[:singular]
|
756
746
|
elsif @auth && !@god
|
757
747
|
", #{@auth_identifier}: #{@auth}"
|
@@ -771,9 +761,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
771
761
|
res
|
772
762
|
end
|
773
763
|
|
764
|
+
def nested_path
|
765
|
+
@nested_set.collect{| arg| arg[:plural] + "/\#{#{arg[:singular]}.id}/" }.join("/")
|
766
|
+
end
|
767
|
+
|
768
|
+
|
774
769
|
def objest_nest_params_by_id_for_specs
|
775
|
-
@nested_set.map{|arg|
|
776
|
-
"#{arg[:singular]}_id: #{arg[:singular]}.id"
|
770
|
+
@nested_set.map { |arg|
|
771
|
+
"#{arg[:singular]}_id: #{arg[:singular] }.id"
|
777
772
|
}.join(",\n ")
|
778
773
|
end
|
779
774
|
|
@@ -790,8 +785,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
790
785
|
end
|
791
786
|
|
792
787
|
def capybara_make_updates(which_partial = :create)
|
793
|
-
@columns_map.map { |
|
794
|
-
show_only_list = which_partial == :create ? @show_only : (@update_show_only
|
788
|
+
@columns_map.map { |col, col_obj|
|
789
|
+
show_only_list = which_partial == :create ? @show_only : (@update_show_only + @show_only)
|
795
790
|
|
796
791
|
if show_only_list.include?(col)
|
797
792
|
" page.should have_no_selector(:css, \"[name='#{testing_name}[#{ col.to_s }]'\")"
|
@@ -803,7 +798,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
803
798
|
|
804
799
|
def path_helper_args
|
805
800
|
if @nested_set.any? && @nested
|
806
|
-
[(@nested_set).collect{|a| "#{a[:singular]}"}
|
801
|
+
[(@nested_set).collect { |a| "#{a[:singular]}" }, singular].join(",")
|
807
802
|
else
|
808
803
|
singular
|
809
804
|
end
|
@@ -811,9 +806,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
811
806
|
|
812
807
|
def path_helper_singular
|
813
808
|
if @nested
|
814
|
-
"#{@namespace+"_" if @namespace}#{(@nested_set.collect{|x| x[:singular]}.join("_") + "_" if @nested_set.any?)}#{@controller_build_folder_singular}_path"
|
809
|
+
"#{@namespace + "_" if @namespace}#{(@nested_set.collect { |x| x[:singular] }.join("_") + "_" if @nested_set.any?)}#{@controller_build_folder_singular}_path"
|
815
810
|
else
|
816
|
-
"#{@namespace+"_" if @namespace}#{@controller_build_folder_singular}_path"
|
811
|
+
"#{@namespace + "_" if @namespace}#{@controller_build_folder_singular}_path"
|
817
812
|
end
|
818
813
|
end
|
819
814
|
|
@@ -840,7 +835,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
840
835
|
top_level: true)
|
841
836
|
end
|
842
837
|
|
843
|
-
|
844
838
|
def delete_path_helper
|
845
839
|
HotGlue.optionalized_ternary(namespace: @namespace,
|
846
840
|
target: @singular,
|
@@ -867,15 +861,15 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
867
861
|
end
|
868
862
|
|
869
863
|
def line_path_partial
|
870
|
-
"#{@namespace+"/" if @namespace}#{@controller_build_folder}/line"
|
864
|
+
"#{@namespace + "/" if @namespace}#{@controller_build_folder}/line"
|
871
865
|
end
|
872
866
|
|
873
867
|
def show_path_partial
|
874
|
-
"#{@namespace+"/" if @namespace}#{@controller_build_folder}/show"
|
868
|
+
"#{@namespace + "/" if @namespace}#{@controller_build_folder}/show"
|
875
869
|
end
|
876
870
|
|
877
871
|
def list_path_partial
|
878
|
-
"#{@namespace+"/" if @namespace}#{@controller_build_folder}/list"
|
872
|
+
"#{@namespace + "/" if @namespace}#{@controller_build_folder}/list"
|
879
873
|
end
|
880
874
|
|
881
875
|
def new_path_name
|
@@ -888,11 +882,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
888
882
|
|
889
883
|
def nested_assignments
|
890
884
|
return "" if @nested_set.none?
|
891
|
-
@nested_set.map{|a| "#{a}: #{a}"}.join(", ") #metaprgramming into Ruby hash
|
885
|
+
@nested_set.map { |a| "#{a}: #{a}" }.join(", ") # metaprgramming into Ruby hash
|
892
886
|
end
|
893
887
|
|
894
888
|
def nested_assignments_top_level # this is by accessing the instance variable-- only use at top level
|
895
|
-
@nested_set.map{|a| "#{a[:singular]}"}.join(", ") #metaprgramming into Ruby hash
|
889
|
+
@nested_set.map { |a| "#{a[:singular]}" }.join(", ") # metaprgramming into Ruby hash
|
896
890
|
end
|
897
891
|
|
898
892
|
def nest_assignments_operator(top_level = false, leading_comma = false)
|
@@ -908,11 +902,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
908
902
|
end
|
909
903
|
|
910
904
|
def nested_objects_arity
|
911
|
-
@nested_set.map{|a| "@#{a[:singular]}"}.join(", ")
|
905
|
+
@nested_set.map { |a| "@#{a[:singular]}" }.join(", ")
|
912
906
|
end
|
913
907
|
|
914
908
|
def nested_arity_for_path
|
915
|
-
[@nested_set[0..-1].collect{|a| "@#{a[:singular]}"}].join(", ") #metaprgramming into arity for the Rails path helper
|
909
|
+
[@nested_set[0..-1].collect { |a| "@#{a[:singular]}" }].join(", ") # metaprgramming into arity for the Rails path helper
|
916
910
|
end
|
917
911
|
|
918
912
|
def object_scope
|
@@ -958,7 +952,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
958
952
|
end
|
959
953
|
|
960
954
|
def no_devise_installed
|
961
|
-
!Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }['devise']
|
955
|
+
!Gem::Specification.sort_by { |g| [g.name.downcase, g.version] }.group_by { |g| g.name }['devise']
|
962
956
|
end
|
963
957
|
|
964
958
|
def magic_button_output
|
@@ -989,27 +983,24 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
989
983
|
source_filename = cc_filename_with_extensions("#{@markup}/#{view}", "#{@markup}")
|
990
984
|
dest_filename = cc_filename_with_extensions("#{view}", "#{@markup}")
|
991
985
|
|
992
|
-
|
993
986
|
dest_filepath = File.join("#{filepath_prefix}app/views#{namespace_with_dash}",
|
994
987
|
@controller_build_folder, dest_filename)
|
995
988
|
|
996
|
-
|
997
989
|
template source_filename, dest_filepath
|
998
|
-
gsub_file dest_filepath,
|
990
|
+
gsub_file dest_filepath, '\%', '%'
|
999
991
|
|
1000
992
|
end
|
1001
993
|
end
|
1002
994
|
|
1003
995
|
turbo_stream_views.each do |view|
|
1004
996
|
formats.each do |format|
|
1005
|
-
source_filename = cc_filename_with_extensions(
|
997
|
+
source_filename = cc_filename_with_extensions("#{@markup}/#{view}.turbo_stream.#{@markup}")
|
1006
998
|
dest_filename = cc_filename_with_extensions("#{view}", "turbo_stream.#{@markup}")
|
1007
999
|
dest_filepath = File.join("#{filepath_prefix}app/views#{namespace_with_dash}",
|
1008
1000
|
@controller_build_folder, dest_filename)
|
1009
1001
|
|
1010
|
-
|
1011
1002
|
template source_filename, dest_filepath
|
1012
|
-
gsub_file dest_filepath,
|
1003
|
+
gsub_file dest_filepath, '\%', '%'
|
1013
1004
|
|
1014
1005
|
end
|
1015
1006
|
end
|
@@ -1022,7 +1013,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1022
1013
|
dest_filename = cc_filename_with_extensions("#{singular_class.underscore}", "rb")
|
1023
1014
|
dest_filepath = File.join("#{filepath_prefix}app/models", dest_filename)
|
1024
1015
|
|
1025
|
-
|
1026
1016
|
puts "appending turbo callbacks to #{dest_filepath}"
|
1027
1017
|
|
1028
1018
|
text = File.read(dest_filepath)
|
@@ -1034,7 +1024,30 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1034
1024
|
append_text << " after_update_commit lambda { broadcast_replace_to self, target: \"#{@namespace}__\#{dom_id(self)}\", partial: \"#{@namespace}/#{@plural}/line\" }\n after_destroy_commit lambda { broadcast_remove_to self, target: \"#{@namespace}__\#{dom_id(self)}\"}\n"
|
1035
1025
|
|
1036
1026
|
replace = text.gsub(/class #{singular_class} < ApplicationRecord/, append_text)
|
1037
|
-
File.open(dest_filepath, "w") {|file| file.puts replace}
|
1027
|
+
File.open(dest_filepath, "w") { |file| file.puts replace }
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
def insert_into_nav_template
|
1032
|
+
# how does this get called(?)
|
1033
|
+
nav_file = "#{Rails.root}/app/views/#{namespace_with_trailing_dash}_nav.html.#{@markup}"
|
1034
|
+
if include_nav_template
|
1035
|
+
append_text = " <li class='nav-item'>
|
1036
|
+
<%= link_to '#{@list_label_heading}', #{path_helper_plural}, class: \"nav-link \#{'active' if nav == '#{plural_name}'}\" %>
|
1037
|
+
</li>"
|
1038
|
+
|
1039
|
+
text = File.read(nav_file)
|
1040
|
+
if text.include?(append_text)
|
1041
|
+
puts "SKIPPING: Nav link for #{singular_name} already exists in #{nav_file}"
|
1042
|
+
else
|
1043
|
+
puts "APPENDING: nav link for #{singular_name} #{nav_file}"
|
1044
|
+
|
1045
|
+
replace = text.gsub(/\<\/ul\>/, append_text + "\n</ul>")
|
1046
|
+
|
1047
|
+
File.open("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_nav.html.#{@markup}", "w") { |file|
|
1048
|
+
file.puts replace
|
1049
|
+
}
|
1050
|
+
end
|
1038
1051
|
end
|
1039
1052
|
end
|
1040
1053
|
|
@@ -1051,7 +1064,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1051
1064
|
end
|
1052
1065
|
|
1053
1066
|
def all_views
|
1054
|
-
res =
|
1067
|
+
res = %w(index _line _list _show)
|
1055
1068
|
|
1056
1069
|
unless @no_create
|
1057
1070
|
res += %w(new _new_form _new_button)
|
@@ -1061,7 +1074,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1061
1074
|
res += %w{edit _edit}
|
1062
1075
|
end
|
1063
1076
|
|
1064
|
-
if !(
|
1077
|
+
if !(@no_edit && @no_create)
|
1065
1078
|
res << '_form'
|
1066
1079
|
end
|
1067
1080
|
res
|
@@ -1113,7 +1126,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1113
1126
|
def all_line_fields
|
1114
1127
|
@template_builder.all_line_fields(
|
1115
1128
|
col_identifier: @layout_strategy.column_classes_for_line_fields,
|
1116
|
-
perc_width: @layout_strategy.each_col,
|
1129
|
+
perc_width: @layout_strategy.each_col, # undefined method `each_col'
|
1117
1130
|
layout_strategy: @layout_strategy,
|
1118
1131
|
layout_object: @layout_object
|
1119
1132
|
)
|
@@ -1172,7 +1185,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1172
1185
|
end
|
1173
1186
|
|
1174
1187
|
def controller_magic_button_update_actions
|
1175
|
-
@magic_buttons.collect{ |magic_button|
|
1188
|
+
@magic_buttons.collect { |magic_button|
|
1176
1189
|
" if #{singular}_params[:#{magic_button}]
|
1177
1190
|
begin
|
1178
1191
|
res = @#{singular}.#{magic_button}!
|
@@ -1187,15 +1200,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1187
1200
|
}.join("\n") + "\n"
|
1188
1201
|
end
|
1189
1202
|
|
1190
|
-
|
1191
1203
|
def controller_update_params_tap_away_magic_buttons
|
1192
|
-
@magic_buttons.collect{ |magic_button|
|
1204
|
+
@magic_buttons.collect { |magic_button|
|
1193
1205
|
".tap{ |ary| ary.delete('__#{magic_button}') }"
|
1194
1206
|
}.join("")
|
1195
1207
|
end
|
1196
1208
|
|
1197
1209
|
def controller_update_params_tap_away_alt_lookups
|
1198
|
-
@alt_lookups.collect{ |key, data|
|
1210
|
+
@alt_lookups.collect { |key, data|
|
1199
1211
|
".tap{ |ary| ary.delete('__lookup_#{data[:lookup_as]}') }"
|
1200
1212
|
}.join("")
|
1201
1213
|
end
|
@@ -1210,7 +1222,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1210
1222
|
|
1211
1223
|
def n_plus_one_includes
|
1212
1224
|
if @associations.any? || @attachments.any?
|
1213
|
-
".includes(" + (@associations.map{|x| x} + @attachments.collect{|k,v| "#{k}_attachment"}).map{|x| ":#{x.to_s}"}.join(", ") + ")"
|
1225
|
+
".includes(" + (@associations.map { |x| x } + @attachments.collect { |k, v| "#{k}_attachment" }).map { |x| ":#{x.to_s}" }.join(", ") + ")"
|
1214
1226
|
else
|
1215
1227
|
""
|
1216
1228
|
end
|
@@ -1222,7 +1234,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1222
1234
|
if @nested_set.none?
|
1223
1235
|
"\"\""
|
1224
1236
|
else
|
1225
|
-
@nested_set.collect{|arg|
|
1237
|
+
@nested_set.collect { |arg|
|
1226
1238
|
"(((\"__#{arg[:singular]}-\#{" + "@" + arg[:singular] + ".id}\") if @" + arg[:singular] + ") || \"\")"
|
1227
1239
|
}.join(" + ")
|
1228
1240
|
end
|
@@ -1234,7 +1246,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1234
1246
|
if @nested_set.none?
|
1235
1247
|
""
|
1236
1248
|
else
|
1237
|
-
", \n nested_for: \"" + @nested_set.collect{|a| "#{a[:singular]}-" + '#{' + instance_symbol + a[:singular] + ".id}"}.join("__") + "\""
|
1249
|
+
", \n nested_for: \"" + @nested_set.collect { |a| "#{a[:singular]}-" + '#{' + instance_symbol + a[:singular] + ".id}" }.join("__") + "\""
|
1238
1250
|
end
|
1239
1251
|
end
|
1240
1252
|
|
@@ -1245,23 +1257,23 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1245
1257
|
end
|
1246
1258
|
|
1247
1259
|
def hawk_to_ruby
|
1248
|
-
res = @hawk_keys.collect{ |k,v|
|
1260
|
+
res = @hawk_keys.collect { |k, v|
|
1249
1261
|
"#{k.to_s}: [#{v[:bind_to].join(".")}]"
|
1250
1262
|
}.join(", ")
|
1251
1263
|
res
|
1252
1264
|
end
|
1253
1265
|
|
1254
1266
|
def controller_attachment_orig_filename_pickup_syntax
|
1255
|
-
@attachments.collect{ |key, attachment|
|
1267
|
+
@attachments.collect { |key, attachment| "\n" + " modified_params[:#{ attachment[:field_for_original_filename] }] = #{singular}_params['#{ key }'].original_filename" if attachment[:field_for_original_filename] }.compact.join("\n")
|
1256
1268
|
end
|
1257
1269
|
|
1258
1270
|
def any_datetime_fields?
|
1259
|
-
(@columns - @attachments.keys.collect(&:to_sym)).collect{|col| eval("#{singular_class}.columns_hash['#{col}']").type}.include?(:datetime)
|
1271
|
+
(@columns - @attachments.keys.collect(&:to_sym)).collect { |col| eval("#{singular_class}.columns_hash['#{col}']").type }.include?(:datetime)
|
1260
1272
|
end
|
1261
1273
|
|
1262
1274
|
def post_action_parental_updates
|
1263
1275
|
if @nested_set.any?
|
1264
|
-
"\n" + @nested_set.collect{ |data|
|
1276
|
+
"\n" + @nested_set.collect { |data|
|
1265
1277
|
parent = data[:singular]
|
1266
1278
|
"@#{singular}.#{parent}.reload"
|
1267
1279
|
}.join("\n")
|
@@ -1269,7 +1281,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
1269
1281
|
end
|
1270
1282
|
|
1271
1283
|
def turbo_parental_updates
|
1272
|
-
@nested_set.collect{|
|
1284
|
+
@nested_set.collect { |data|
|
1273
1285
|
"<%= turbo_stream.replace \"#{@namespace + '__' if @namespace}\#{dom_id(@#{data[:singular]})}\" do %>
|
1274
1286
|
<%= render partial: \"#{@namespace}/#{data[:plural]}/edit\", locals: {#{data[:singular]}: @#{singular}.#{data[:singular]}.reload} %>
|
1275
1287
|
<% end %>"
|