hot-glue 0.4.7 → 0.4.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,8 @@ require 'ffaker'
3
3
 
4
4
  require_relative './markup_templates/base'
5
5
  require_relative './markup_templates/erb'
6
- require_relative './markup_templates/haml'
7
- require_relative './markup_templates/slim'
6
+ # require_relative './markup_templates/haml'
7
+ # require_relative './markup_templates/slim'
8
8
 
9
9
  require_relative './layout/builder'
10
10
 
@@ -12,6 +12,50 @@ module HotGlue
12
12
  class Error < StandardError
13
13
  end
14
14
 
15
+ def self.optionalized_ternary(params)
16
+ namespace = params[:namespace] || nil
17
+ target = params[:target]
18
+ nested_set = params[:nested_set]
19
+ modifier = params[:modifier] || ""
20
+ with_params = params[:with_params] || false
21
+ top_level = params[:top_level] || false
22
+
23
+ instance_sym = top_level ? "@" : ""
24
+
25
+ put_form = params[:put_form] || false
26
+
27
+ if nested_set.nil? || nested_set.empty?
28
+ return modifier + "#{(namespace + '_') if namespace}#{target}_path" + (("(#{instance_sym}#{target})" if put_form) || "")
29
+ elsif nested_set[0][:optional] == false
30
+ return modifier + ((namespace + "_" if namespace) || "") + nested_set.collect{|x|
31
+ x[:singular] + "_"
32
+ }.join() + target + "_path" + (("(#{nested_set.collect{
33
+ |x| instance_sym + x[:singular] }.join(",")
34
+ }#{ put_form ? ',' + instance_sym + target : '' })" if with_params) || "")
35
+
36
+ else
37
+ # copy the first item, make a ternery in this cycle, and recursively move to both the
38
+ # is present path and the is optional path
39
+
40
+ nonoptional = nested_set[0].dup
41
+ nonoptional[:optional] = false
42
+ rest_of_nest = nested_set[1..-1]
43
+
44
+ all_params = {namespace: namespace,
45
+ target: target,
46
+ modifier: modifier,
47
+ top_level: top_level,
48
+ with_params: with_params,
49
+ put_form: put_form}
50
+ is_present_path = HotGlue.optionalized_ternary(all_params.merge({ nested_set: [nonoptional, *rest_of_nest]}) )
51
+
52
+ is_missing_path = HotGlue.optionalized_ternary(all_params.merge({ nested_set: rest_of_nest}) )
53
+
54
+
55
+ return "defined?(#{instance_sym + nested_set[0][:singular]}) ? #{is_present_path} : #{is_missing_path}"
56
+ end
57
+ end
58
+
15
59
  def self.derrive_reference_name(thing_as_string)
16
60
  assoc_class = eval(thing_as_string)
17
61
 
@@ -206,6 +250,10 @@ module HotGlue
206
250
  @display_list_after_update = options['display_list_after_update'] || false
207
251
  @smart_layout = options['smart_layout']
208
252
 
253
+ if options['include'].include?(":") && @smart_layout
254
+ raise "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"
255
+ end
256
+
209
257
 
210
258
  @container_name = @layout == "hotglue" ? "scaffold-container" : "container-fluid"
211
259
  @downnest = options['downnest'] || false
@@ -231,16 +279,42 @@ module HotGlue
231
279
  raise "This controller appears to be the same as the authentication object but in this context you cannot build a new/create action; please re-run with --no-create flag"
232
280
  end
233
281
 
282
+ # old syntax
234
283
  @nested_args = []
284
+
285
+ # new syntax
286
+ # @nested_set = [
287
+ # {
288
+ # singular: ...,
289
+ # plural: ...,
290
+ # optional: false
291
+ # }]
292
+ @nested_set = []
293
+
235
294
  if ! @nested.nil?
236
- @nested_args = @nested.split("/")
295
+
296
+
297
+ @nested_args = @nested.split("/").collect{|x| x.gsub("~","")}
298
+
299
+ @nested_set = @nested.split("/").collect { |arg|
300
+ is_optional = arg.start_with?("~")
301
+ arg.gsub!("~","")
302
+ {
303
+ singular: arg,
304
+ plural: arg.pluralize,
305
+ optional: is_optional
306
+ }
307
+
308
+ }
309
+
310
+ puts "@nested_set is #{@nested_set}"
237
311
  @nested_args_plural = {}
312
+
313
+
238
314
  @nested_args.each do |a|
239
315
  @nested_args_plural[a] = a + "s"
240
316
  end
241
317
  end
242
- @nestable = @nested_args.any?
243
-
244
318
 
245
319
  @magic_buttons = []
246
320
  if options['magic_buttons']
@@ -257,11 +331,14 @@ module HotGlue
257
331
  if @auth && ! @self_auth && @nested_args.none?
258
332
  @object_owner_sym = @auth.gsub("current_", "").to_sym
259
333
  @object_owner_eval = @auth
334
+ @object_owner_optional = false
260
335
  else
261
336
 
262
337
  if @nested_args.any?
263
- @object_owner_sym = @nested_args.last.to_sym
264
- @object_owner_eval = "@#{@nested_args.last}"
338
+ @object_owner_sym = @nested_set.last[:singular].to_sym
339
+ @object_owner_eval = "@#{@nested_set.last[:singular]}"
340
+ @object_owner_name = @nested_set.last[:singular]
341
+ @object_owner_optional = @nested_set.last[:optional]
265
342
  else
266
343
  @object_owner_sym = ""
267
344
  @object_owner_eval = ""
@@ -304,11 +381,12 @@ module HotGlue
304
381
  auth_assoc_field = auth_assoc + "_id" unless @god
305
382
  assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
306
383
 
307
-
308
384
  if assoc
309
385
  @ownership_field = assoc.name.to_s + "_id"
310
386
  elsif ! @nested_args.any?
311
- exit_message = "*** Oops: It looks like is no association from current_#{@object_owner_sym} to a class called #{@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."
387
+
388
+ exit_message = "*** Oops: It looks like is no association from class called #{@singular_class} to the current_#{@object_owner_sym}. 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."
389
+ raise(HotGlue::Error, exit_message)
312
390
 
313
391
  else
314
392
 
@@ -317,6 +395,7 @@ module HotGlue
317
395
  else
318
396
  exit_message = "*** Oops: Missing relationship from class #{singular_class} to :#{@object_owner_sym} maybe add `belongs_to :#{@object_owner_sym}` to #{singular_class}\n (If your user is called something else, pass with flag auth=current_X where X is the model for your auth object 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 flag). To make a controller that can read all records, specify with --god."
319
397
  end
398
+
320
399
  raise(HotGlue::Error, exit_message)
321
400
  end
322
401
  end
@@ -532,11 +611,44 @@ module HotGlue
532
611
  end
533
612
 
534
613
  def path_helper_plural
535
- if ! @nested
536
- "#{@namespace+"_" if @namespace}#{@controller_build_folder}_path"
537
- else
538
- "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{plural}_path"
539
- end
614
+ HotGlue.optionalized_ternary(namespace: @namespace,
615
+ target: @controller_build_folder,
616
+ nested_set: @nested_set)
617
+ end
618
+
619
+ def form_path_new_helper
620
+ HotGlue.optionalized_ternary(namespace: @namespace,
621
+ target: @controller_build_folder,
622
+ nested_set: @nested_set,
623
+ with_params: true,
624
+ top_level: false)
625
+ end
626
+
627
+ def form_path_edit_helper
628
+ HotGlue.optionalized_ternary(namespace: @namespace,
629
+ target: @singular,
630
+ nested_set: @nested_set,
631
+ with_params: true,
632
+ put_form: true,
633
+ top_level: true)
634
+ end
635
+
636
+
637
+ def delete_path_helper
638
+ HotGlue.optionalized_ternary(namespace: @namespace,
639
+ target: @singular,
640
+ nested_set: @nested_set,
641
+ with_params: true,
642
+ put_form: true)
643
+ end
644
+
645
+ def edit_path_helper
646
+ HotGlue.optionalized_ternary(namespace: @namespace,
647
+ target: @singular,
648
+ nested_set: @nested_set,
649
+ modifier: "edit_",
650
+ with_params: true,
651
+ put_form: true)
540
652
  end
541
653
 
542
654
  def path_arity
@@ -560,13 +672,19 @@ module HotGlue
560
672
  end
561
673
 
562
674
  def new_path_name
563
- base = "new_#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_") if @nested_args.any?}#{@controller_build_folder_singular}_path"
564
- if @nested_args.any?
565
- base += "(" + @nested_args.collect { |arg|
566
- "#{arg}.id"
567
- }.join(", ") + ")"
568
- end
569
- base
675
+
676
+ HotGlue.optionalized_ternary(namespace: @namespace,
677
+ target: singular,
678
+ nested_set: @nested_set,
679
+ modifier: "new_",
680
+ with_params: true)
681
+ # base = "new_#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_") if @nested_args.any?}#{@controller_build_folder_singular}_path"
682
+ # if @nested_args.any?
683
+ # base += "(" + @nested_args.collect { |arg|
684
+ # "#{arg}.id"
685
+ # }.join(", ") + ")"
686
+ # end
687
+ # base
570
688
  end
571
689
 
572
690
  def nested_assignments
@@ -650,8 +768,11 @@ module HotGlue
650
768
 
651
769
  def magic_button_output
652
770
  @template_builder.magic_button_output(
653
- path_helper_singular: path_helper_singular,
654
- path_helper_args: path_helper_args,
771
+ path: HotGlue.optionalized_ternary(namespace: @namespace,
772
+ target: @singular,
773
+ nested_set: @nested_set,
774
+ with_params: true,
775
+ put_form: true),
655
776
  singular: singular,
656
777
  magic_buttons: @magic_buttons,
657
778
  small_buttons: @small_buttons
@@ -763,12 +884,7 @@ module HotGlue
763
884
  end
764
885
 
765
886
  def all_form_fields
766
- # TODO: DRY THIS
767
- if !@smart_layout
768
- col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col-md-1"
769
- else
770
- col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col-md-2"
771
- end
887
+ col_identifier = (@layout == "hotglue") ? "scaffold-cell" : "col-md-#{@layout_object[:columns][:size_each]}"
772
888
 
773
889
  @template_builder.all_form_fields(
774
890
  columns: @layout_object[:columns][:container],
@@ -805,6 +921,7 @@ module HotGlue
805
921
  end
806
922
 
807
923
  def all_line_fields
924
+ col_identifier = (@layout == "hotglue") ? "scaffold-cell" : "col-md-#{@layout_object[:columns][:size_each]}"
808
925
 
809
926
  @template_builder.all_line_fields(
810
927
  perc_width: column_width,
@@ -812,7 +929,8 @@ module HotGlue
812
929
  show_only: @show_only,
813
930
  singular_class: singular_class,
814
931
  singular: singular,
815
- layout: @layout
932
+ layout: @layout,
933
+ col_identifier: col_identifier
816
934
  )
817
935
  end
818
936
 
@@ -905,10 +1023,10 @@ module HotGlue
905
1023
 
906
1024
 
907
1025
  def nested_for_turbo_id_list_constructor
908
- if @nested_args.none?
909
- ""
1026
+ if @nested_set.any?
1027
+ '+ (((\'__\' + nested_for) if defined?(nested_for)) || "")'
910
1028
  else
911
- "+ ('__' + nested_for)"
1029
+ ""
912
1030
  end
913
1031
  end
914
1032
 
@@ -916,9 +1034,11 @@ module HotGlue
916
1034
  instance_symbol = "@" if top_level
917
1035
  instance_symbol = "" if !top_level
918
1036
  if @nested_args.none?
919
- ""
1037
+ "\"\""
920
1038
  else
921
- "__" + @nested_args.collect{|a| "#{a}-" + '#{' + instance_symbol + a + '.id}'}.join("__")
1039
+ @nested_set.collect{|arg|
1040
+ "(((\"__#{arg[:singular]}-\#{" + "@" + arg[:singular] + ".id}\") if @" + arg[:singular] + ") || \"\")"
1041
+ }.join(" + ")
922
1042
  end
923
1043
  end
924
1044
 
@@ -3,66 +3,61 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
3
3
  include HotGlue::ControllerHelper
4
4
 
5
5
  <% unless @auth_identifier == '' || @god %>before_action :authenticate_<%= @auth_identifier %>!<% end %>
6
- <% if any_nested? %><% nest_chain = [] %> <% @nested_args.each { |arg|
6
+ <% if any_nested? %><% nest_chain = [] %> <% @nested_set.each { |arg|
7
7
 
8
- if auth_identifier == arg
8
+ if auth_identifier == arg[:singular]
9
9
  this_scope = auth_object
10
10
  elsif nest_chain.empty?
11
- this_scope = "#{@auth ? auth_object : class_name}.#{arg}s"
11
+ this_scope = "#{@auth ? auth_object : class_name}.#{arg}s"
12
12
  else
13
- this_scope = "#{nest_chain.last}.#{arg}s"
13
+ this_scope = "#{nest_chain.last}.#{arg[:plural]}"
14
14
  end
15
15
 
16
16
  nest_chain << arg %>
17
- before_action :<%= arg %>
17
+ before_action :<%= arg[:singular] %><%= ", if: -> { params.include?(:#{arg[:singular]}_id) }" if arg[:optional] %>
18
+
18
19
  <% } %><% end %>
19
20
  before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
20
21
  after_action -> { flash.discard }, if: -> { request.format.symbol == :turbo_stream }
21
22
  <% if @nested_args.any? %>
22
- def <%= @nested_args[0] %><% if @god
23
+ def <%= @nested_set[0][:singular] %><% if @god
23
24
  next_object = nil
24
- collect_objects = @nested_args.reverse.collect {|x|
25
- if eval("#{next_object || class_name}.reflect_on_association(:#{x})").nil?
26
- 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
+ collect_objects = @nested_set.reverse.collect {|x|
26
+ if eval("#{next_object || class_name}.reflect_on_association(:#{x[:singular]})").nil?
27
+ raise "***** Unable to find the association `#{x[:singular]}` on the class #{next_object || class_name} ..... you probably want to add `belongs_to :#{x}` to the #{next_object || class_name} object?"
27
28
  end
28
- next_object = eval("#{next_object || class_name}.reflect_on_association(:#{x})").class_name
29
+ next_object = eval("#{next_object || class_name}.reflect_on_association(:#{x[:singular]})").class_name
29
30
  }
30
31
  root_object = collect_objects.last
31
32
  else
32
- if @nested_args[0] == @auth_identifier
33
+ if @nested_set[0][:singular] == @auth_identifier
33
34
  root_object = @auth
34
35
  else
35
- root_object = @auth + "." + @nested_args[0] + "s"
36
+ root_object = @auth + "." + @nested_set[0][:plural]
36
37
  end
37
38
  end
38
- %><% if !@god && @nested_args[0] == @auth_identifier %>
39
- @<%= @nested_args[0] %> ||= <%= root_object %> <% elsif !@god %>
40
- @<%= @nested_args[0] %> ||= <%= root_object %>.find(params[:<%= @nested_args[0] %>_id]) <% else %>
41
- @<%= @nested_args[0] %> ||= <%= root_object %>.find(params[:<%= @nested_args[0] %>_id]) <% end %>
39
+ %><% if !@god && @nested_set[0][:singular] == @auth_identifier %>
40
+ @<%= @nested_set[0][:singular] %> ||= <%= root_object %> <% else %>
41
+ @<%= @nested_set[0][:singular] %> ||= <%= root_object %>.find(params[:<%= @nested_set[0][:singular] %>_id])<%= " if params.include?(:#{@nested_set[0][:singular]}_id)" if @nested_set[0][:optional] %> <% end %>
42
42
  end
43
- <% end %>
44
- <% if any_nested? %><% nest_chain = [@nested_args[0]]; this_scope = @nested_args[0] + 's'; %> <% @nested_args[1..-1].each { |arg|
45
- this_scope = "#{nest_chain.last}.#{arg}s"
46
- nest_chain << arg
47
- %>
48
- def <%= arg %>
49
- @<%= arg %> ||= <%= this_scope %>.find(params[:<%= arg %>_id])
43
+ <% end %><% if any_nested? %><% nest_chain = [@nested_set[0][:singular]]; this_scope = @nested_set[0][:plural]; %> <% @nested_set[1..-1].each_with_index { |arg,index|
44
+ this_scope = "#{nest_chain.last}.#{arg[:plural]}"
45
+ nest_chain << arg %>
46
+ def <%= arg[:singular] %>
47
+ @<%= arg[:singular] %> ||= (<%= this_scope %>.find(params[:<%= arg[:singular] %>_id])<%= " if params.include?(:#{@nested_set[index][:singular]}_id)" if @god && arg[:optional] %>)<% if @god && arg[:optional] %> || (<%= collect_objects[index] %>.find(params[:<%= arg[:singular] %>_id]) if params.include?(:<%= arg[:singular] %>_id) ) <% end %>
50
48
  end<% } %> <% end %> <% if !@self_auth %>
51
49
 
52
50
  def load_<%= singular_name %>
53
- @<%= singular_name %> = <%= object_scope.gsub("@",'') %>.find(params[:id])
51
+ @<%= singular_name %> = (<%= object_scope.gsub("@",'') %>.find(params[:id])<%= " if params.include?(:#{@nested_set.last[:singular]}_id)" if @nested_set[0] && @nested_set[0][:optional] %>)<% if @nested_set[0] && @nested_set[0][:optional] %> || <%= class_name %>.find(params[:id])<% end %>
54
52
  end
55
53
  <% else %>
56
54
  def load_<%= singular_name %>
57
- @<%= singular_name %> = <%= auth_object.gsub("@",'') %>
55
+ @<%= singular_name %> = (<%= auth_object.gsub("@",'') %><%= " if params.include?(:#{@nested_set[0][:singular]}_id)" if @nested_set[0][:optional] %>)<% if @nested_set[0][:optional] %> || <%= class_name %>.find(params[:id])<% end %>
58
56
  end<% end %>
59
57
 
60
- def load_all_<%= plural %>
61
- <% if !@self_auth %>
62
- @<%= plural_name %> = <%= object_scope.gsub("@",'') %>.page(params[:page])
63
- <% else %>
64
- @<%= plural_name %> = <%= class_name %>.where(id: <%= auth_object.gsub("@",'') %>.id) # returns iterable even though this <%= singular_name %> is anly allowed access to themselves
65
- <% end %>
58
+ def load_all_<%= plural %> <% if !@self_auth %>
59
+ @<%= plural_name %> = ( <%= object_scope.gsub("@",'') %>.page(params[:page])<%= " if params.include?(:#{ @nested_set.last[:singular]}_id)" if @nested_set[0] && @nested_set[0][:optional] %>) <% if @nested_set[0] && @nested_set[0][:optional] %> || <%= class_name %>.all<% end %> <% else %>
60
+ @<%= plural_name %> = <%= class_name %>.where(id: <%= auth_object.gsub("@",'') %>.id) # returns iterable even though this <%= singular_name %> is anly allowed access to themselves<% end %>
66
61
  end
67
62
 
68
63
  def index
@@ -75,7 +70,8 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
75
70
  <% if create_action %> def new
76
71
  <% if ! @god %>
77
72
  @<%= singular_name %> = <%= class_name %>.new(<%= @object_owner_sym %>: <%= @object_owner_eval %>)
78
- <% else %>
73
+ <% elsif @object_owner_optional && any_nested? %>
74
+ @<%= singular_name %> = <%= class_name %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {})) <% else %>
79
75
  @<%= singular_name %> = <%= class_name %>.new(<% if any_nested? %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)
80
76
  <% end %>
81
77
  respond_to do |format|
@@ -84,7 +80,9 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
84
80
  end
85
81
 
86
82
  def create
87
- modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<% if ! @object_owner_sym.empty? %>.merge!(<%= @object_owner_sym %>: <%= @object_owner_eval %> )<% end %> <%= @auth ? ', ' + @auth : '' %>)
83
+ modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<% if ! @object_owner_sym.empty? %>.merge!(<% if @object_owner_optional && any_nested? %><%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {} <% else %> <%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>) <% end %>)
84
+
85
+
88
86
  @<%=singular_name %> = <%= class_name %>.create(modified_params)
89
87
 
90
88
  if @<%= singular_name %>.save
@@ -1,7 +1,7 @@
1
1
 
2
2
  <\%= turbo_frame_tag "<%= singular %>__#{ <%= singular %>.id }" do %>
3
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 %> } %>
4
+ <\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %> }<% @nested_set.each do |nest_arg| %>.merge(defined?(<%= nest_arg[:singular] %>) ? {<%= nest_arg[:singular] %>: <%= nest_arg[:singular] %>, nested_for: "<%= nest_arg[:singular] %>-#{<%= nest_arg[:singular] %>.id}"} : {})<% end %> %>
5
5
 
6
6
  </div>
7
7
  <\% end %>
@@ -2,7 +2,7 @@
2
2
  <div class="<%= @container_name %> scaffold-list">
3
3
  <% unless @no_list || @nested_args.any? %><h4><%= plural.gsub("_", " ").upcase %></h4><% end %>
4
4
 
5
- <% unless @no_create %><%= '<%= render partial: "' + ((@namespace+"/" if @namespace) || "") + @controller_build_folder + '/new_button", locals: {' + nested_assignments + '}' + '%\>'.gsub('\\',"") %><br /><% end %>
5
+ <% unless @no_create %><%= '<%= render partial: "' + ((@namespace+"/" if @namespace) || "") + @controller_build_folder + '/new_button", locals: {}' + @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}} : {})"}.join() + ' %\>'.gsub('\\',"") %><br /><% end %>
6
6
 
7
7
  <% unless @no_list %>
8
8
  <% unless @no_list_labels %>
@@ -35,7 +35,10 @@
35
35
  </div>
36
36
  <\% end %>
37
37
  <\% <%= plural %>.each do |<%= singular %>| %>
38
- <\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %><%= nested_assignments_with_leading_comma if @nestable %><%= ", nested_for: nested_for" if @nestable %> } %>
38
+ <\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %>}
39
+ .merge(defined?(nested_for) ? {nested_for: nested_for} : {})
40
+ <%= @nested_set.collect{|arg| " .merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}} : {})"}.join("\n") %>
41
+ %>
39
42
  <\% end %>
40
43
  <%= @no_paginate ? "" : paginate %>
41
44
  <% end %>
@@ -2,8 +2,8 @@
2
2
  <h3>
3
3
  New <%= singular.titlecase %>
4
4
  </h3>
5
- <\%= form_with model: <%= singular %>, url: <%= path_helper_plural %>(<%= nested_objects_arity %>), method: "post" do |f| %>
5
+ <\%= form_with model: <%= singular %>, url: <%= form_path_new_helper %>, method: :post do |f| \%>
6
6
  <\%= render partial: "<%= namespace_with_slash + @controller_build_folder %>/form",
7
- locals: { <%= singular %>: <%= singular %> <%= nest_assignments_operator(false, true) %>, f: f} %>
7
+ locals: { <%= singular %>: <%= singular %>, f: f}<%= @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}}: {})" }.join %> \%>
8
8
  <\% end %>
9
9
  <\% end %>
@@ -6,14 +6,18 @@
6
6
  <% @downnest_children.each_with_index do |downnest,i| %>
7
7
 
8
8
  <% downnest_object = eval("#{singular_class}.reflect_on_association(:#{downnest})") %>
9
+ <% if downnest_object.nil?; raise "no relationship for downnested portal `#{downnest}` found on `#{singular_class}`; please check relationship for has_many :#{downnest}"; end; %>
9
10
  <% downnest_class = downnest_object.class_name %>
10
11
  <% downnest_object_name = eval("#{downnest_class}.table_name") %>
11
12
  <% downnest_style = @layout == "hotglue" ? 'style="flex-basis: ' + each_downnest_width.to_s + '%"' : "" %>
12
13
  <div class="<%= " col-md-#{@layout_object[:portals][downnest][:size]}" if @layout == "bootstrap" %> scaffold-downnest" <%= downnest_style %> >
13
14
  <\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {
14
- nested_for: "<% if @nested_args.any? %>#{nested_for + "__" if nested_for}<% end %><%= @singular %>-#{<%= @singular %>.id}",
15
- <%= @singular %>: <%= @singular %><%= nest_assignments_operator(false, true) %>,
16
- <%= downnest_object_name %>: <%= @singular %>.<%= downnest %>} %>
15
+ <%= @singular %>: <%= @singular %>,
16
+ <%= downnest_object_name %>: <%= @singular %>.<%= downnest %>
17
+ }
18
+ .merge({nested_for: "<% if @nested_args.any? %>#{nested_for + "__" if defined?(nested_for)}<% end %><%= @singular %>-#{<%= @singular %>.id}"})
19
+ <%= @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}} : {} )"}.join("\n") %>
20
+ \%>
17
21
  </div>
18
22
  <% end %>
19
23
  <% end %>
@@ -23,12 +27,12 @@
23
27
  <%= magic_button_output %>
24
28
 
25
29
  <% if destroy_action %>
26
- <\%= form_with url: <%= path_helper_singular %>(<%= path_helper_args %>), html: {data: {'<%= @ujs_syntax ? 'confirm' : 'turbo-confirm' %>': "Are you sure you want to delete #{ <%= @singular + "." + display_class %> }?"}, style: "display: inline-block;"}, method: :delete do |f| %>
30
+ <\%= form_with url: <%= delete_path_helper %>, html: {data: {'<%= @ujs_syntax ? 'confirm' : 'turbo-confirm' %>': "Are you sure you want to delete #{ <%= @singular + "." + display_class %> }?"}, style: "display: inline-block;"}, method: :delete do |f| %>
27
31
  <\%= f.submit "Delete".html_safe, class: "delete-<%= singular %>-button btn btn-primary btn-sm" %>
28
32
  <\% end %>
29
33
  <% end %>
30
34
 
31
35
  <% unless @no_edit %>
32
- <\%= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_singular %>(<%= path_helper_args %>), <% if @big_edit %>'data-turbo' => 'false', <% end %>disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary btn-sm" %>
36
+ <\%= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, <%= edit_path_helper %>, <% if @big_edit %>'data-turbo' => 'false', <% end %>disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary btn-sm" %>
33
37
  <% end %>
34
38
  </div>
@@ -1,13 +1,13 @@
1
1
  <\% if @<%= singular %>.errors.none? %>
2
- <\%= turbo_stream.replace "<%= plural %>-list<%= nested_for_turbo_nested_constructor %>" do %>
3
- <\%= render partial: "list", locals: {<%= plural %>: @<%= plural %><%= nested_for_assignments_constructor %><%= nest_assignments_operator(true, true) %>} %>
2
+ <\%= turbo_stream.replace "<%= plural %>-list" + <%= nested_for_turbo_nested_constructor %> do %>
3
+ <\%= render partial: "list", locals: {<%= plural %>: @<%= plural %>}<%= @nested_set.collect{|arg| ".merge(@" + arg[:singular] + " ? {nested_for: \"" + arg[:singular] + "-\#{@" + arg[:singular] + ".id}\"" + ", " + arg[:singular] + ": @" + arg[:singular] + "} : {})"}.join() %> \%>
4
4
  <\% end %>
5
5
  <\% end %>
6
6
  <\%= turbo_stream.replace "<%= singular %>-new" do %>
7
7
  <\% if @<%= singular %>.errors.none? %>
8
- <\%= render partial: "new_button", locals: {<%= nest_assignments_operator(true, false) %>} %>
8
+ <\%= render partial: "new_button", locals: {}<%= @nested_set.collect{|arg| ".merge(@" + arg[:singular] + " ? {" + arg[:singular] + ": @" + arg[:singular] + "} : {})"}.join() %> %>
9
9
  <\% else %>
10
- <\%= render partial: "new_form", locals: {<%= singular %>: @<%= singular %> <%= nest_assignments_operator(true, true) %> } %>
10
+ <\%= render partial: "new_form", locals: {<%= singular %>: @<%= singular %>}<%= @nested_set.collect{|arg| ".merge(@" + arg[:singular] + " ? {" + arg[:singular] + ": @" + arg[:singular] + "} : {})"}.join() %> %>
11
11
  <\% end %>
12
12
  <\% end %>
13
13
  <\%= turbo_stream.replace "flash_notices" do %>
@@ -1,3 +1,3 @@
1
- <\%= turbo_stream.replace "<%= plural %>-list<%= nested_for_turbo_nested_constructor %>" do %>
2
- <\%= render partial: "list", locals: {<%=plural%>: @<%=plural%> <%= nested_for_assignments_constructor %> <%= nest_assignments_operator(true, true) %>} %>
1
+ <\%= turbo_stream.replace "<%= plural %>-list" + <%= nested_for_turbo_nested_constructor %> do %>
2
+ <\%= render partial: "list", locals: {<%=plural%>: @<%=plural%> }<%= @nested_set.collect{|arg| ".merge(@" + arg[:singular] + " ? {nested_for: \"" + arg[:singular] + "-\#{@" + arg[:singular] + ".id}\"" + ", " + arg[:singular] + ": @" + arg[:singular] + "} : {})"}.join() %> \%>
3
3
  <\% end %>
@@ -9,8 +9,8 @@
9
9
  <\% end %>
10
10
 
11
11
  <h2>Editing <\%= @<%= @singular %>.<%= display_class %> %></h2>
12
- <\%= form_with model: <%= "@" + singular%>, url: <%= path_helper_singular %>(<%= path_arity %>) do |f| %>
13
- <\%= render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f} %>
12
+ <\%= form_with model: <%= "@" + singular%>, url: <%= form_path_edit_helper %> do |f| %>
13
+ <\%= render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
14
14
  <\% end %>
15
15
 
16
16
  </div>
@@ -8,7 +8,7 @@
8
8
 
9
9
  <div class="clearfix"></div>
10
10
  <\%= render partial: '<%= list_path_partial %>',
11
- locals: {<%= plural %>: @<%= plural %><%= nested_for_assignments_constructor %><%= nest_assignments_operator(true, true) if @nestable %> } \%>
11
+ locals: {<%= plural %>: @<%= plural %>}<%= @nested_set.collect{|arg| ".merge(@" + arg[:singular] + " ? {nested_for: \"" + arg[:singular] + "-\#{@" + arg[:singular] + ".id}\"" + ", " + arg[:singular] + ": @" + arg[:singular] + "} : {})"}.join() %> \%>
12
12
 
13
13
  <% if @layout == "bootstrap" %></div></div><% else %></div><% end %>
14
14
  </div>
@@ -1 +1 @@
1
- <\%= render partial: "new_form", locals: {<%= singular %>: @<%=singular%><%= nest_assignments_operator(true, true) %>} %>
1
+ <\%= render partial: "new_form", locals: {<%= singular %>: @<%=singular%>}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> %>
@@ -1,7 +1,7 @@
1
1
  <% if !@display_list_after_update %><\%= turbo_stream.replace "<%= singular%>__#{@<%= singular %>.id}" do %>
2
- <\%= render partial: 'line', locals: {<%= singular %>: @<%= singular %> <%= nest_assignments_operator(true,true) %> } %>
2
+ <\%= render partial: 'line', locals: {<%= singular %>: @<%= singular %> }<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
3
3
  <\% end %><% else %><\%= turbo_stream.replace "<%= plural %>-list" do %>
4
- <\%= render partial: '<%= list_path_partial %>', locals: {<%= plural %>: @<%= plural %><%= nest_assignments_operator(true, true) if @nestable %><%= nested_for_assignments_constructor %> } \%>
4
+ <\%= render partial: '<%= list_path_partial %>', locals: {<%= plural %>: @<%= plural %>}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
5
5
  <\% end %>
6
6
  <% end %>
7
7
 
@@ -1,3 +1,5 @@
1
1
  module HotGlue
2
- VERSION = '0.4.7'
2
+ class Version
3
+ CURRENT = '0.4.8.1'
4
+ end
3
5
  end
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.4.7
4
+ version: 0.4.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-26 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,6 +67,7 @@ files:
67
67
  - Gemfile.lock
68
68
  - LICENSE
69
69
  - README.md
70
+ - README2.md
70
71
  - Rakefile
71
72
  - app/assets/config/manifest.js
72
73
  - app/helpers/hot_glue/controller_helper.rb
@@ -81,8 +82,6 @@ files:
81
82
  - lib/generators/hot_glue/layout/builder.rb
82
83
  - lib/generators/hot_glue/markup_templates/base.rb
83
84
  - lib/generators/hot_glue/markup_templates/erb.rb
84
- - lib/generators/hot_glue/markup_templates/haml.rb
85
- - lib/generators/hot_glue/markup_templates/slim.rb
86
85
  - lib/generators/hot_glue/scaffold_generator.rb
87
86
  - lib/generators/hot_glue/templates/base_controller.rb.erb
88
87
  - lib/generators/hot_glue/templates/capybara_login.rb