hot-glue 0.2.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -2
  3. data/Gemfile.lock +3 -23
  4. data/LICENCE +11 -4
  5. data/README.md +0 -642
  6. data/app/helpers/hot_glue/controller_helper.rb +2 -1
  7. data/lib/generators/hot_glue/install_generator.rb +121 -33
  8. data/lib/generators/hot_glue/markup_templates/erb.rb +53 -27
  9. data/lib/generators/hot_glue/markup_templates/haml.rb +5 -3
  10. data/lib/generators/hot_glue/scaffold_generator.rb +224 -58
  11. data/lib/generators/hot_glue/templates/controller.rb.erb +39 -32
  12. data/lib/generators/hot_glue/templates/erb/_form.erb +1 -1
  13. data/lib/generators/hot_glue/templates/erb/_line.erb +3 -2
  14. data/lib/generators/hot_glue/templates/erb/_list.erb +24 -8
  15. data/lib/generators/hot_glue/templates/erb/_show.erb +27 -4
  16. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +4 -4
  17. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +2 -2
  18. data/lib/generators/hot_glue/templates/erb/edit.erb +2 -5
  19. data/lib/generators/hot_glue/templates/erb/index.erb +11 -9
  20. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +5 -2
  21. data/lib/generators/hot_glue/templates/haml/_line.haml +1 -1
  22. data/lib/generators/hot_glue/templates/haml/_list.haml +6 -2
  23. data/lib/generators/hot_glue/templates/haml/create.turbo_stream.haml +3 -3
  24. data/lib/generators/hot_glue/templates/haml/destroy.turbo_stream.haml +1 -1
  25. data/lib/generators/hot_glue/templates/haml/edit.haml +0 -2
  26. data/lib/generators/hot_glue/templates/haml/index.haml +2 -3
  27. data/lib/generators/hot_glue/templates/system_spec.rb.erb +19 -8
  28. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_dark_knight.scss +158 -0
  29. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_bootstrap.scss +154 -0
  30. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_los_gatos.scss +182 -0
  31. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_mountain_view.scss +179 -0
  32. data/lib/hot-glue.rb +1 -2
  33. data/lib/hotglue/version.rb +1 -1
  34. metadata +13 -33
@@ -31,7 +31,7 @@ module HotGlue
31
31
  end
32
32
 
33
33
  class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
34
- hook_for :form_builder, :as => :scaffold
34
+ hook_for :form_builder, :as => :scaffold
35
35
 
36
36
  source_root File.expand_path('templates', __dir__)
37
37
  attr_accessor :path, :singular, :plural, :singular_class, :nest_with
@@ -51,20 +51,18 @@ module HotGlue
51
51
  class_option :no_specs, type: :boolean, default: false
52
52
  class_option :no_delete, type: :boolean, default: false
53
53
  class_option :no_create, type: :boolean, default: false
54
+ class_option :no_edit, type: :boolean, default: false
54
55
  class_option :no_paginate, type: :boolean, default: false
55
56
  class_option :big_edit, type: :boolean, default: false
56
57
  class_option :show_only, type: :string, default: ""
57
- class_option :markup, type: :string, default: "erb"
58
- class_option :stimulus_syntax, type: :boolean, default: nil
59
-
60
-
61
-
62
- # def erb_replace_ampersands
63
- # if @template_builder.is_a?(HotGlue::ErbTemplate)
64
- # @output_buffer.gsub!('\%', '%')
65
- # end
66
- # end
58
+ class_option :stimulus_syntax, type: :boolean, default: nil
59
+ class_option :downnest, type: :string, default: nil
60
+ class_option :nestable, type: :boolean, default: false
61
+ class_option :magic_buttons, type: :string, default: nil
62
+ class_option :display_list_after_update, type: :boolean, default: false
67
63
 
64
+ class_option :markup, type: :string, default: nil # deprecated -- use in app config instead
65
+ class_option :layout, type: :string, default: nil # deprecated -- use in app config instead
68
66
 
69
67
 
70
68
  def initialize(*meta_args)
@@ -74,11 +72,18 @@ module HotGlue
74
72
  @the_object = eval(class_name)
75
73
  rescue StandardError => e
76
74
  message = "*** Oops: It looks like there is no object for #{class_name}. Please define the object + database table first."
77
- raise(HotGlue::Error, message)
75
+ puts message
76
+ exit
77
+ # raise(HotGlue::Error, message)
78
78
  end
79
79
 
80
- if @specs_only && @no_specs
81
- 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. sorry.")
80
+ if !options['spec_only'].nil? && !options['no_spec'].nil?
81
+ puts "*** 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. sorry."
82
+ end
83
+
84
+ if !options['exclude'].empty? && !options['include'].empty?
85
+ puts "*** Oops: You seem to have specified both --include and --exclude. Please use one or the other. Aborting."
86
+ exit
82
87
  end
83
88
 
84
89
  if @stimulus_syntax.nil?
@@ -89,17 +94,36 @@ module HotGlue
89
94
  end
90
95
  end
91
96
 
92
- if options['markup'] == "erb"
97
+ if !options['markup'].nil?
98
+ puts "Using --markup flag in the generator is deprecated; instead, use a file at config/hot_glue.yml with a key markup set to `erb` or `haml`"
99
+ exit
100
+ end
101
+
102
+ if !options['markup'].nil?
103
+ puts "Using --layout flag in the generator is deprecated; instead, use a file at config/hot_glue.yml with a key markup set to `erb` or `haml`"
104
+ exit
105
+ end
106
+
107
+ yaml_from_config = YAML.load(File.read("config/hot_glue.yml"))
108
+ @markup = yaml_from_config[:markup]
109
+
110
+ if @markup == "erb"
93
111
  @template_builder = HotGlue::ErbTemplate.new
94
- elsif options['markup'] == "slim"
112
+ elsif @markup == "slim"
95
113
  puts "SLIM IS NOT IMPLEMENTED; please see https://github.com/jasonfb/hot-glue/issues/3"
96
114
  abort
97
115
  @template_builder = HotGlue::SlimTemplate.new
98
116
 
99
- elsif options['markup'] == "haml"
117
+ elsif @markup == "haml"
100
118
  @template_builder = HotGlue::HamlTemplate.new
101
119
  end
102
- @markup = options['markup']
120
+
121
+
122
+ @layout = yaml_from_config[:layout]
123
+
124
+ if !['hotglue', 'bootstrap'].include? @layout
125
+ raise "Invalid option #{@layout} in Hot glue config (config/hot_glue.yml). You must pass either hotglue (default) or bootstrap to config"
126
+ end
103
127
 
104
128
 
105
129
  args = meta_args[0]
@@ -114,6 +138,7 @@ module HotGlue
114
138
 
115
139
  @singular_class = @singular.titleize.gsub(" ", "")
116
140
  @exclude_fields = []
141
+
117
142
  @exclude_fields += options['exclude'].split(",").collect(&:to_sym)
118
143
 
119
144
  if !options['include'].empty?
@@ -138,6 +163,23 @@ module HotGlue
138
163
  @no_paginate = options['no_paginate'] || false
139
164
  @big_edit = options['big_edit']
140
165
 
166
+ @no_edit = options['no_edit'] || false
167
+ @display_list_after_update = options['display_list_after_update'] || false
168
+
169
+
170
+
171
+ @col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col"
172
+ @container_name = @layout == "hotglue" ? "scaffold-container" : "container-fluid"
173
+
174
+ @downnest = options['downnest'] || false
175
+
176
+ @downnest_children = []
177
+
178
+ if @downnest
179
+ @downnest_children = @downnest.split(",")
180
+ end
181
+
182
+
141
183
  if @god
142
184
  @auth = nil
143
185
  end
@@ -155,9 +197,18 @@ module HotGlue
155
197
  @nested_args_plural[a] = a + "s"
156
198
  end
157
199
  end
200
+ @nestable = @nested_args.any?
201
+
158
202
 
159
- # the @object_owner will always be object that will 'own' the object
160
- # for new and create
203
+ @magic_buttons = []
204
+ if options['magic_buttons']
205
+ @magic_buttons = options['magic_buttons'].split(',')
206
+ end
207
+
208
+ @build_update_action = !@no_edit || !@magic_buttons.empty?
209
+ # if the magic buttons are present, build the update action anyway
210
+
211
+ # @nestable = options['nestable'] || false
161
212
 
162
213
  if @auth && ! @self_auth && @nested_args.none?
163
214
  @object_owner_sym = @auth.gsub("current_", "").to_sym
@@ -173,6 +224,8 @@ module HotGlue
173
224
  end
174
225
  end
175
226
 
227
+
228
+
176
229
  @reference_name = HotGlue.derrive_reference_name(singular_class)
177
230
 
178
231
  identify_object_owner
@@ -193,21 +246,19 @@ module HotGlue
193
246
 
194
247
  else
195
248
  if @god
196
-
197
- exit_message= "*** Oops: god mode could not find the association(?). something is wrong."
249
+ exit_message= "*** Oops: Gd mode could not find the association(#{@object_owner_sym}). Something is wrong."
198
250
  else
199
251
  @auth_check = "current_user"
200
252
  @nested_args.each do |arg|
201
253
 
202
254
  if !@auth_check.method("#{arg}s")
203
- exit_message= "*** Oops: your nesting chain does not have a assocation for #{arg}s on #{@auth_check} something is wrong."
255
+ exit_message = "*** Oops: your nesting chain does not have a association for #{arg}s on #{@auth_check} something is wrong."
204
256
  end
205
- byebug
206
- puts ""
207
257
  end
208
258
  end
259
+ puts exit_message
260
+ exit
209
261
 
210
- raise(HotGlue::Error, exit_message)
211
262
  end
212
263
  end
213
264
  end
@@ -249,14 +300,18 @@ module HotGlue
249
300
  eval(assoc.class_name)
250
301
  rescue NameError => e
251
302
  exit_message = "*** Oops: The model #{singular_class} is missing an association for #{assoc_name} or the model doesn't exist. TODO: Please implement a model for #{assoc_name.titlecase}; your model #{singular_class.titlecase} should have_many :#{assoc_name}s. To make a controller that can read all records, specify with --god."
252
- raise(HotGlue::Error, exit_message)
303
+ puts exit_message
304
+ exit
305
+ # raise(HotGlue::Error, exit_message)
253
306
 
254
307
  end
255
308
 
256
309
 
257
310
  if assoc.nil?
258
- exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
259
- raise(HotGlue::Error,exit_message)
311
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
312
+ puts exit_message
313
+ exit
314
+ # raise(HotGlue::Error,exit_message)
260
315
  end
261
316
 
262
317
  assoc_class = eval(assoc.class_name)
@@ -269,7 +324,7 @@ module HotGlue
269
324
  }.any?
270
325
  # do nothing here
271
326
  else
272
- exit_message= "*** Oops: Missing a label for #{assoc.class_name.upcase}. Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name.upcase} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
327
+ exit_message = "*** Oops: Missing a label for #{assoc.class_name.upcase}. Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name.upcase} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
273
328
  raise(HotGlue::Error,exit_message)
274
329
  end
275
330
  end
@@ -286,8 +341,6 @@ module HotGlue
286
341
  nil
287
342
  end
288
343
 
289
-
290
-
291
344
  def copy_controller_and_spec_files
292
345
  @default_colspan = @columns.size
293
346
  unless @specs_only
@@ -310,7 +363,18 @@ module HotGlue
310
363
  end
311
364
 
312
365
  def list_column_headings
313
- @template_builder.list_column_headings(columns: @columns)
366
+ if @nested_args.any?
367
+ column_width = each_col * @columns.count
368
+
369
+ "<div class='#{@col_identifier}' style='flex-basis: #{column_width}%'>"
370
+ else
371
+ @template_builder.list_column_headings(
372
+ column_width: each_col,
373
+ columns: @columns,
374
+ col_identifier: @col_identifier
375
+ )
376
+ end
377
+
314
378
 
315
379
  end
316
380
 
@@ -383,24 +447,32 @@ module HotGlue
383
447
  end
384
448
 
385
449
  def path_helper_args
386
- if @nested_args.any?
387
- [(@nested_args).collect{|a| "@#{a}"} , singular].join(",")
450
+ if @nested_args.any? && @nest
451
+ [(@nested_args).collect{|a| "#{a}"} , singular].join(",")
388
452
  else
389
453
  singular
390
454
  end
391
455
  end
392
456
 
393
457
  def path_helper_singular
394
- "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
458
+ if @nest
459
+ "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
460
+ else
461
+ "#{@namespace+"_" if @namespace}#{singular}_path"
462
+ end
395
463
  end
396
464
 
397
465
  def path_helper_plural
398
- "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{plural}_path"
466
+ if ! @nest
467
+ "#{@namespace+"_" if @namespace}#{plural}_path"
468
+ else
469
+ "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{plural}_path"
470
+ end
399
471
  end
400
472
 
401
473
  def path_arity
402
474
  res = ""
403
- if @nested_args.any?
475
+ if @nested_args.any? && @nest
404
476
  res << nested_objects_arity + ", "
405
477
  end
406
478
  res << "@" + singular
@@ -419,28 +491,37 @@ module HotGlue
419
491
  end
420
492
 
421
493
  def new_path_name
422
-
423
494
  base = "new_#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_") if @nested_args.any?}#{singular}_path"
424
495
  if @nested_args.any?
425
496
  base += "(" + @nested_args.collect { |arg|
426
- "@#{arg}.id"
497
+ "#{arg}.id"
427
498
  }.join(", ") + ")"
428
499
  end
429
500
  base
430
501
  end
431
502
 
432
503
  def nested_assignments
504
+ return "" if @nested_args.none?
505
+ @nested_args.map{|a| "#{a}: #{a}"}.join(", ") #metaprgramming into Ruby hash
506
+ end
507
+
508
+ def nested_assignments_top_level # this is by accessing the instance variable-- only use at top level
433
509
  @nested_args.map{|a| "#{a}: @#{a}"}.join(", ") #metaprgramming into Ruby hash
434
510
  end
435
511
 
436
- def nested_assignments_with_leading_comma
512
+
513
+ def nest_assignments_operator(top_level = false, leading_comma = false)
437
514
  if @nested_args.any?
438
- ", #{nested_assignments}"
515
+ "#{', ' + "\n " if leading_comma}#{top_level ? nested_assignments_top_level : nested_assignments }"
439
516
  else
440
517
  ""
441
518
  end
442
519
  end
443
520
 
521
+ def nested_assignments_with_leading_comma
522
+ nest_assignments_operator(false, true)
523
+ end
524
+
444
525
  def nested_objects_arity
445
526
  @nested_args.map{|a| "@#{a}"}.join(", ")
446
527
  end
@@ -457,7 +538,12 @@ module HotGlue
457
538
  "@" + @nested_args.last + ".#{plural}"
458
539
  end
459
540
  else
460
- @singular_class
541
+ if @nested_args.none?
542
+ @singular_class
543
+ else
544
+ "@" + @nested_args.last + ".#{plural}"
545
+ end
546
+
461
547
  end
462
548
  end
463
549
 
@@ -492,6 +578,15 @@ module HotGlue
492
578
  !Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }['devise']
493
579
  end
494
580
 
581
+
582
+ def magic_button_output
583
+ @template_builder.magic_button_output(
584
+ path_helper_singular: path_helper_singular,
585
+ path_helper_args: path_helper_args,
586
+ singular: singular,
587
+ magic_buttons: @magic_buttons
588
+ )
589
+ end
495
590
  # def erb_replace_ampersands!(filename = nil)
496
591
  #
497
592
  # return if filename.nil?
@@ -514,8 +609,10 @@ module HotGlue
514
609
  formats.each do |format|
515
610
  source_filename = cc_filename_with_extensions("#{@markup}/#{view}", "#{@markup}")
516
611
  dest_filename = cc_filename_with_extensions("#{view}", "#{@markup}")
612
+
613
+
517
614
  dest_filepath = File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}",
518
- controller_file_path, dest_filename)
615
+ plural, dest_filename)
519
616
 
520
617
 
521
618
  template source_filename, dest_filepath
@@ -529,7 +626,7 @@ module HotGlue
529
626
  source_filename = cc_filename_with_extensions( "#{@markup}/#{view}.turbo_stream.#{@markup}")
530
627
  dest_filename = cc_filename_with_extensions("#{view}", "turbo_stream.#{@markup}")
531
628
  dest_filepath = File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}",
532
- controller_file_path, dest_filename)
629
+ plural, dest_filename)
533
630
 
534
631
 
535
632
  template source_filename, dest_filepath
@@ -587,20 +684,48 @@ module HotGlue
587
684
  end
588
685
 
589
686
  def all_form_fields
687
+
590
688
  @template_builder.all_form_fields(
591
689
  columns: @columns,
592
690
  show_only: @show_only,
593
691
  singular_class: singular_class,
594
- singular: singular
692
+ singular: singular,
693
+ col_identifier: @col_identifier
595
694
  )
596
695
  end
597
696
 
697
+ def column_width
698
+ @each_col ||= each_col
699
+ end
700
+
701
+ def each_col
702
+ (col_width/@columns.count).to_i
703
+ end
704
+
705
+ def col_width
706
+ downnest_size = case (@downnest_children.count)
707
+
708
+ when 0
709
+ downnest_size = 0
710
+ when 1
711
+ downnest_size = 40
712
+
713
+ else
714
+ downnest_size = 60
715
+
716
+ end
717
+ 100 - downnest_size - 5
718
+ end
719
+
598
720
  def all_line_fields
721
+
599
722
  @template_builder.all_line_fields(
723
+ perc_width: column_width,
600
724
  columns: @columns,
601
725
  show_only: @show_only,
602
726
  singular_class: singular_class,
603
- singular: singular
727
+ singular: singular,
728
+ layout: @layout
604
729
  )
605
730
  end
606
731
 
@@ -654,24 +779,65 @@ module HotGlue
654
779
  else
655
780
  ""
656
781
  end
657
- end
782
+ end
658
783
 
659
- def paginate
784
+ def paginate
660
785
  @template_builder.paginate(plural: plural)
661
- end
786
+ end
662
787
 
663
- def delete_confirmation_syntax
664
- if !@stimulus_syntax
665
- "{confirm: 'Are you sure?'}"
666
- else
667
- "{controller: 'confirmable', 'confirm-message': \"Are you sure you want to delete \#{ #{@singular}.#{ display_class } } \", 'action': 'confirmation#confirm'}"
788
+ def delete_confirmation_syntax
789
+ if !@stimulus_syntax
790
+ "{confirm: 'Are you sure?'}"
791
+ else
792
+ "{controller: 'confirmable', 'confirm-message': \"Are you sure you want to delete \#{ #{@singular}.#{ display_class } } \", 'action': 'confirmation#confirm'}"
793
+ end
668
794
  end
669
- end
670
795
 
671
796
 
672
- private # thor does something fancy like sending the class all of its own methods during some strange run sequence
673
- # does not like public methods
797
+ def controller_magic_button_update_actions
798
+ @magic_buttons.collect{ |magic_button|
799
+ " @#{singular}.#{magic_button}! if #{singular}_params[:#{magic_button}]"
800
+ }.join("\n") + "\n"
801
+ end
802
+
803
+ def controller_update_params_tap_away_magic_buttons
804
+ @magic_buttons.collect{ |magic_button|
805
+ ".tap{ |ary| ary.delete('#{magic_button}') }"
806
+ }.join("")
807
+ end
808
+
809
+
810
+ def nested_for_turbo_id_list_constructor
811
+ if @nested_args.none?
812
+ ""
813
+ else
814
+ "+ ('__' + nested_for)"
815
+ end
816
+ end
674
817
 
818
+ def nested_for_turbo_nested_constructor(top_level = true)
819
+ instance_symbol = "@" if top_level
820
+ instance_symbol = "" if !top_level
821
+ if @nested_args.none?
822
+ ""
823
+ else
824
+ "__" + @nested_args.collect{|a| "#{a}-" + '#{' + instance_symbol + a + '.id}'}.join("__")
825
+ end
826
+ end
827
+
828
+ def nested_for_assignments_constructor(top_level = true)
829
+ instance_symbol = "@" if top_level
830
+ instance_symbol = "" if !top_level
831
+ if @nested_args.none?
832
+ ""
833
+ else
834
+ ", \n nested_for: \"" + @nested_args.collect{|a| "#{a}-" + '#{' + instance_symbol + a + ".id}"}.join("__") + "\""
835
+ end
836
+ end
837
+
838
+
839
+ private # thor does something fancy like sending the class all of its own methods during some strange run sequence
840
+ # does not like public methods
675
841
  def cc_filename_with_extensions(name, file_format = format)
676
842
  [name, file_format].compact.join(".")
677
843
  end
@@ -1,6 +1,8 @@
1
1
  class <%= controller_class_name %> < <%= controller_descends_from %>
2
- <% unless @auth_identifier == '' || @god %>before_action :authenticate_<%= @auth_identifier %>!<% end %>
2
+ helper :hot_glue
3
+ include HotGlue::ControllerHelper
3
4
 
5
+ <% unless @auth_identifier == '' || @god %>before_action :authenticate_<%= @auth_identifier %>!<% end %>
4
6
  <% if any_nested? %><% nest_chain = [] %> <% @nested_args.each { |arg|
5
7
  this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "#{nest_chain.last}.#{arg}s"
6
8
  nest_chain << arg %>
@@ -9,26 +11,41 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
9
11
  before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
10
12
  after_action -> { flash.discard }, if: -> { request.format.symbol == :turbo_stream }
11
13
 
12
- helper :hot_glue
13
- include HotGlue::ControllerHelper
14
-
15
14
  <% if no_devise_installed %>
16
15
  # TODO: implement current_user or use Devise
17
16
  <% end %>
18
17
 
18
+ <% if @nested_args.any? %>
19
+ def <%= @nested_args[0] %>
20
+ <% if @god
21
+ next_object = nil
22
+ collect_objects = @nested_args.reverse.collect {|x|
23
+ if eval("#{next_object || class_name}.reflect_on_association(:#{x})").nil?
24
+ raise "***** Unable to find the association `#{x}` on the class #{next_object || class_name} ..... you probably want to add `belongs_to :#{x}` to the #{next_object || class_name} object?"
25
+ end
26
+ next_object = eval("#{next_object || class_name}.reflect_on_association(:#{x})").class_name
27
+ }
28
+ root_object = collect_objects.last
29
+ else
30
+ root_object = @auth + "." + @nested_args[0] + "s"
31
+ end
32
+
33
+ %>
34
+ <% if !@god %> @<%= @nested_args[0] %> ||= <%= root_object %>.find(params[:<%= @nested_args[0] %>_id])
35
+ <% else %> @<%= @nested_args[0] %> ||= <%= root_object %>.find(params[:<%= @nested_args[0] %>_id]) <% end %>
36
+ end
37
+ <% end %>
19
38
 
20
-
21
- <% if any_nested? %><% nest_chain = [] %> <% @nested_args.each { |arg|
22
- if !@god
23
- this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "#{nest_chain.last}.#{arg}s"
24
- else
25
- this_scope = eval(class_name + ".reflect_on_association(:#{arg})").class_name
26
- end
39
+ <% if any_nested? %><% nest_chain = [@nested_args[0]]; this_scope = @nested_args[0] + 's'; %> <% @nested_args[1..-1].each { |arg|
40
+ this_scope = "#{nest_chain.last}.#{arg}s"
27
41
  nest_chain << arg
28
42
  %>
29
43
  def <%= arg %>
30
44
  @<%= arg %> ||= <%= this_scope %>.find(params[:<%= arg %>_id])
31
- end<% } %><% end %>
45
+ end<% } %>
46
+
47
+ <% end %>
48
+
32
49
 
33
50
  <% if !@self_auth %>
34
51
  def load_<%= singular_name %>
@@ -40,8 +57,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
40
57
  end<% end %>
41
58
 
42
59
  def load_all_<%= plural %>
43
- <% if !@self_auth %>@<%= plural_name %> = <%= object_scope.gsub("@",'') %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
44
- <% else %>@<%= plural_name %> = [<%= auth_object %>]<% end %>
60
+ @<%= plural_name %> = <%= object_scope.gsub("@",'') %>.page(params[:page])
45
61
  end
46
62
 
47
63
  def index
@@ -79,34 +95,35 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
79
95
  format.html
80
96
  end
81
97
  end
82
- end<% end %>
98
+ end
83
99
 
84
- def show
100
+ <% end %> def show
85
101
  respond_to do |format|
86
102
  format.html
87
103
  end
88
104
  end
89
105
 
90
- def edit
106
+ <% unless @no_edit %> def edit
91
107
  respond_to do |format|
92
108
  format.turbo_stream
93
109
  format.html
94
110
  end
95
111
  end
96
112
 
97
- def update
98
- if @<%= singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params<%= @auth ? ', ' + @auth : '' %>))
113
+ <% end %><% if @build_update_action %> def update
114
+ <%= controller_magic_button_update_actions %> if @<%= singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params<%= @auth ? ', ' + @auth : '' %>)<%= controller_update_params_tap_away_magic_buttons %>)
99
115
  flash[:notice] = "Saved #{@<%= singular %>.<%= display_class %>}"
100
116
  else
101
117
  flash[:alert] = "<%= singular_name.titlecase %> could not be saved."
102
118
  end
119
+ <% if @display_list_after_update %> load_all_<%= plural %><% end %>
103
120
  respond_to do |format|
104
121
  format.turbo_stream
105
122
  format.html
106
123
  end
107
124
  end
108
125
 
109
- <% if destroy_action %> def destroy
126
+ <% end %><% if destroy_action %> def destroy
110
127
  begin
111
128
  @<%=singular_name%>.destroy
112
129
  rescue StandardError => e
@@ -120,7 +137,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
120
137
  end<% end %>
121
138
 
122
139
  def <%=singular_name%>_params
123
- params.require(:<%=singular_name%>).permit( <%= @columns %> )
140
+ params.require(:<%=singular_name%>).permit( <%= @columns + @magic_buttons.collect(&:to_sym) %> )
124
141
  end
125
142
 
126
143
  def default_colspan
@@ -128,18 +145,8 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
128
145
  end
129
146
 
130
147
  def namespace
131
- <% if @namespace %>
132
- "<%= @namespace %>/"
133
- <% else %>
134
- ""
135
- <% end %>
148
+ <% if @namespace %>"<%= @namespace %>/" <% else %>""<% end %>
136
149
  end
137
-
138
-
139
- def common_scope
140
- @nested_args
141
- end
142
-
143
150
  end
144
151
 
145
152
 
@@ -1,7 +1,7 @@
1
1
  <div class="row">
2
2
  <%= all_form_fields %>
3
3
 
4
- <div class="col">
4
+ <div class="<% @layout == "hotglue" ? 'scaffold-cell' : 'col' %>">
5
5
  <\%= link_to "Cancel", <%= path_helper_plural %>, {class: "btn btn-secondary"} %>
6
6
  <\%= f.submit "Save", class: "btn btn-primary pull-right" %>
7
7
  </div>
@@ -1,7 +1,8 @@
1
1
 
2
2
  <\%= turbo_frame_tag "<%= singular %>__#{ <%= singular %>.id }" do %>
3
- <div class='row' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
4
- <\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %>} %>
3
+ <div class='row scaffold-row' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
4
+ <\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %><%= nest_assignments_operator(false, true) if @nestable %><%= (", nested_for: \"" + @nested_args.collect{|a| a + "-" + '#{'+ a + '.id}' }.join("__") + "\"") if @nestable %> } %>
5
+
5
6
  </div>
6
7
  <\% end %>
7
8