hot-glue 0.5.6 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -1
- data/LICENSE +12 -5
- data/README.md +302 -47
- data/lib/generators/hot_glue/install_generator.rb +2 -2
- data/lib/generators/hot_glue/layout/builder.rb +6 -2
- data/lib/generators/hot_glue/layout_strategy/base.rb +1 -0
- data/lib/generators/hot_glue/layout_strategy/bootstrap.rb +17 -3
- data/lib/generators/hot_glue/markup_templates/erb.rb +96 -41
- data/lib/generators/hot_glue/scaffold_generator.rb +165 -53
- data/lib/generators/hot_glue/templates/controller.rb.erb +42 -30
- data/lib/generators/hot_glue/templates/erb/_form.erb +2 -2
- data/lib/generators/hot_glue/templates/erb/_line.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_new_button.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_new_form.erb +4 -4
- data/lib/generators/hot_glue/templates/erb/_show.erb +2 -2
- data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +1 -1
- data/lib/generators/hot_glue/templates/haml/_form.haml +1 -1
- data/lib/generators/hot_glue/templates/system_spec.rb.erb +56 -34
- data/lib/hotglue/version.rb +1 -1
- data/script/clean_generated_code +5 -0
- data/script/test +10 -2
- metadata +2 -2
@@ -121,6 +121,7 @@ module HotGlue
|
|
121
121
|
class_option :no_paginate, type: :boolean, default: false
|
122
122
|
class_option :big_edit, type: :boolean, default: false
|
123
123
|
class_option :show_only, type: :string, default: ""
|
124
|
+
class_option :update_show_only, type: :string, default: ""
|
124
125
|
|
125
126
|
class_option :ujs_syntax, type: :boolean, default: nil
|
126
127
|
class_option :downnest, type: :string, default: nil
|
@@ -133,19 +134,24 @@ module HotGlue
|
|
133
134
|
class_option :hawk, type: :string, default: nil
|
134
135
|
class_option :with_turbo_streams, type: :boolean, default: false
|
135
136
|
|
136
|
-
class_option :
|
137
|
+
class_option :label, default: nil
|
138
|
+
class_option :list_label_heading, default: nil
|
139
|
+
class_option :new_button_label, default: nil
|
140
|
+
class_option :new_form_heading, default: nil
|
137
141
|
|
142
|
+
class_option :no_list_label, type: :boolean, default: false
|
138
143
|
class_option :no_list_heading, type: :boolean, default: false
|
139
144
|
|
140
|
-
|
141
145
|
# determines if the labels show up BEFORE or AFTER on the NEW/EDIT (form)
|
142
146
|
class_option :form_labels_position, type: :string, default: 'after' # choices are before, after, omit
|
143
147
|
class_option :form_placeholder_labels, type: :boolean, default: false # puts the field names into the placeholder labels
|
144
148
|
|
145
|
-
|
146
|
-
# NOT YET IMPLEMENTED
|
147
149
|
# determines if labels appear within the rows of the VIEWABLE list (does NOT affect the list heading)
|
148
150
|
class_option :inline_list_labels, default: 'omit' # choices are before, after, omit
|
151
|
+
class_option :factory_creation, default: ''
|
152
|
+
class_option :alt_foreign_key_lookup, default: '' #
|
153
|
+
|
154
|
+
|
149
155
|
|
150
156
|
def initialize(*meta_args)
|
151
157
|
super
|
@@ -259,8 +265,9 @@ module HotGlue
|
|
259
265
|
|
260
266
|
if !options['include'].empty?
|
261
267
|
@include_fields = []
|
268
|
+
|
262
269
|
# semicolon to denote layout columns; commas separate fields
|
263
|
-
@include_fields += options['include'].
|
270
|
+
@include_fields += options['include'].split(":").collect{|x|x.split(",")}.flatten.collect(&:to_sym)
|
264
271
|
end
|
265
272
|
|
266
273
|
|
@@ -269,6 +276,13 @@ module HotGlue
|
|
269
276
|
@show_only += options['show_only'].split(",").collect(&:to_sym)
|
270
277
|
end
|
271
278
|
|
279
|
+
@update_show_only = []
|
280
|
+
if !options['update_show_only'].empty?
|
281
|
+
@update_show_only += options['update_show_only'].split(",").collect(&:to_sym)
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
|
272
286
|
@god = options['god'] || options['gd'] || false
|
273
287
|
@specs_only = options['specs_only'] || false
|
274
288
|
|
@@ -404,6 +418,8 @@ module HotGlue
|
|
404
418
|
identify_object_owner
|
405
419
|
setup_hawk_keys
|
406
420
|
|
421
|
+
@factory_creation = options['factory_creation'].gsub(";", "\n")
|
422
|
+
|
407
423
|
|
408
424
|
|
409
425
|
# SETUP FIELDS & LAYOUT
|
@@ -421,15 +437,66 @@ module HotGlue
|
|
421
437
|
smart_layout: @smart_layout )
|
422
438
|
@layout_object = builder.construct
|
423
439
|
|
424
|
-
@menu_file_exists = true if @nested_set.none? && File.
|
440
|
+
@menu_file_exists = true if @nested_set.none? && File.exist?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
|
425
441
|
|
426
442
|
@turbo_streams = !!options['with_turbo_streams']
|
443
|
+
|
444
|
+
|
445
|
+
# syntax should be xyz_id{xyz_email},abc_id{abc_email}
|
446
|
+
# instead of a drop-down for the foreign entity, a text field will be presented
|
447
|
+
# You must ALSO use a factory that contains a parameter of the same name as the 'value' (for example, `xyz_email`)
|
448
|
+
|
449
|
+
alt_lookups_entry = options['alt_foreign_key_lookup'].split(",")
|
450
|
+
@alt_lookups = {}
|
451
|
+
@alt_foreign_key_lookup = alt_lookups_entry.each do |setting|
|
452
|
+
setting =~ /(.*){(.*)}/
|
453
|
+
key, lookup_as = $1, $2
|
454
|
+
assoc = eval("#{class_name}.reflect_on_association(:#{key.to_s.gsub("_id","")}).class_name")
|
455
|
+
|
456
|
+
data = {lookup_as: lookup_as.gsub("+",""),
|
457
|
+
assoc: assoc,
|
458
|
+
with_create: lookup_as.include?("+")}
|
459
|
+
@alt_lookups[key] = data
|
460
|
+
end
|
461
|
+
|
462
|
+
puts "------ ALT LOOKUPS for #{@alt_lookups}"
|
463
|
+
|
464
|
+
@update_alt_lookups = @alt_lookups.collect{|key, value|
|
465
|
+
@update_show_only.include?(key) ?
|
466
|
+
{ key: value }
|
467
|
+
: nil}.compact
|
468
|
+
|
469
|
+
@label = options['label'] || ( eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? eval("#{class_name}.class_variable_get(:@@table_label_singular)") : singular.gsub("_", " ").titleize )
|
470
|
+
@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 )
|
471
|
+
|
472
|
+
@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 )
|
473
|
+
@new_form_heading = options['new_form_heading'] || "New #{@label}"
|
427
474
|
end
|
428
475
|
|
476
|
+
|
477
|
+
def fields_filtered_for_email_lookups
|
478
|
+
@columns.reject{|c| @alt_lookups.keys.include?(c) } + @alt_lookups.values.map{|v| ("__lookup_#{v[:lookup_as]}").to_sym}
|
479
|
+
end
|
480
|
+
|
481
|
+
|
482
|
+
def creation_syntax
|
483
|
+
|
484
|
+
merge_with = @alt_lookups.collect{ |key, data|
|
485
|
+
"#{data[:assoc].downcase}: #{data[:assoc].downcase}_factory.#{data[:assoc].downcase}"
|
486
|
+
}.join(", ")
|
487
|
+
|
488
|
+
if @factory_creation == ''
|
489
|
+
"@#{singular_name } = #{ class_name }.create(modified_params)"
|
490
|
+
else
|
491
|
+
"#{@factory_creation}\n" +
|
492
|
+
" @#{singular_name } = #{ class_name }.create(modified_params#{'.merge(' + merge_with + ')' if !merge_with.empty?})"
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
429
496
|
def setup_hawk_keys
|
430
497
|
@hawk_keys = {}
|
431
498
|
|
432
|
-
if options[
|
499
|
+
if options["hawk"]
|
433
500
|
options['hawk'].split(",").each do |hawk_entry|
|
434
501
|
# format is: abc_id[thing]
|
435
502
|
|
@@ -443,7 +510,9 @@ module HotGlue
|
|
443
510
|
|
444
511
|
hawk_scope = key.gsub("_id", "").pluralize
|
445
512
|
@hawk_keys[key.to_sym] = [hawk_to]
|
446
|
-
|
513
|
+
use_shorthand = !options["hawk"].include?("{")
|
514
|
+
|
515
|
+
if use_shorthand # only include the hawk scope if using the shorthand
|
447
516
|
@hawk_keys[key.to_sym] << hawk_scope
|
448
517
|
end
|
449
518
|
end
|
@@ -496,6 +565,7 @@ module HotGlue
|
|
496
565
|
@columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
|
497
566
|
end
|
498
567
|
|
568
|
+
|
499
569
|
@associations = []
|
500
570
|
@columns.each do |col|
|
501
571
|
if col.to_s.starts_with?("_")
|
@@ -571,9 +641,9 @@ module HotGlue
|
|
571
641
|
end
|
572
642
|
|
573
643
|
unless @no_specs
|
574
|
-
dest_file = File.join("#{'spec/dummy/' if Rails.env.test?}spec/
|
644
|
+
dest_file = File.join("#{'spec/dummy/' if Rails.env.test?}spec/features#{namespace_with_dash}", "#{plural}_behavior_spec.rb")
|
575
645
|
|
576
|
-
if File.
|
646
|
+
if File.exist?(dest_file)
|
577
647
|
existing_file = File.open(dest_file)
|
578
648
|
existing_content = existing_file.read
|
579
649
|
if existing_content =~ /\#HOTGLUE-SAVESTART/
|
@@ -589,17 +659,36 @@ module HotGlue
|
|
589
659
|
@existing_content = " #HOTGLUE-SAVESTART\n #HOTGLUE-END"
|
590
660
|
end
|
591
661
|
|
662
|
+
|
592
663
|
template "system_spec.rb.erb", dest_file
|
593
664
|
end
|
594
665
|
|
595
666
|
template "#{@markup}/_errors.#{@markup}", File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", "_errors.#{@markup}")
|
596
667
|
end
|
597
668
|
|
669
|
+
def spec_foreign_association_merge_hash
|
670
|
+
", #{testing_name}: #{testing_name}1"
|
671
|
+
end
|
672
|
+
|
673
|
+
def spec_related_column_lets
|
674
|
+
(@columns - @show_only).map { |col|
|
675
|
+
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
676
|
+
if (type == :integer && col.to_s.ends_with?("_id") || type == :uuid)
|
677
|
+
assoc = "#{col.to_s.gsub('_id','')}"
|
678
|
+
the_foreign_class = eval(@singular_class + ".reflect_on_association(:" + assoc + ")").class_name.split("::").last.underscore
|
679
|
+
hawk_keys_on_lets = (@hawk_keys["#{assoc}_id".to_sym] ? ", #{@auth.gsub('current_', '')}: #{@auth}": "")
|
680
|
+
|
681
|
+
" let!(:#{assoc}1) {create(:#{the_foreign_class}" + hawk_keys_on_lets + ")}"
|
682
|
+
end
|
683
|
+
}.compact.join("\n")
|
684
|
+
end
|
685
|
+
|
598
686
|
def list_column_headings
|
599
687
|
@template_builder.list_column_headings(
|
600
688
|
columns: @layout_object[:columns][:container],
|
601
689
|
col_identifier: @layout_strategy.column_classes_for_column_headings,
|
602
|
-
column_width: @layout_strategy.column_width
|
690
|
+
column_width: @layout_strategy.column_width,
|
691
|
+
singular: @singular
|
603
692
|
)
|
604
693
|
end
|
605
694
|
|
@@ -622,11 +711,13 @@ module HotGlue
|
|
622
711
|
|
623
712
|
|
624
713
|
def regenerate_me_code
|
625
|
-
"rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].join(" ")}"
|
714
|
+
"rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].collect{|x| x.gsub(/\s*=\s*([\S\s]+)/, '=\'\1\'')}.join(" ")}"
|
626
715
|
end
|
627
716
|
|
628
717
|
def object_parent_mapping_as_argument_for_specs
|
629
|
-
if @
|
718
|
+
if @self_auth
|
719
|
+
""
|
720
|
+
elsif @nested_set.any?
|
630
721
|
", " + @nested_set.last[:singular] + ": " + @nested_set.last[:singular]
|
631
722
|
elsif @auth
|
632
723
|
", #{@auth_identifier}: #{@auth}"
|
@@ -640,7 +731,7 @@ module HotGlue
|
|
640
731
|
end
|
641
732
|
|
642
733
|
@nested_set.each do |arg|
|
643
|
-
res << "
|
734
|
+
res << "let(:#{arg[:singular]}) {create(:#{arg[:singular]} #{last_parent} )}\n"
|
644
735
|
last_parent = ", #{arg[:singular]}: #{arg[:singular]}"
|
645
736
|
end
|
646
737
|
res
|
@@ -661,7 +752,7 @@ module HotGlue
|
|
661
752
|
end
|
662
753
|
|
663
754
|
def testing_name
|
664
|
-
singular_class_name.gsub("::","_").
|
755
|
+
singular_class_name.gsub("::","_").underscore
|
665
756
|
end
|
666
757
|
|
667
758
|
def singular_class_name
|
@@ -676,8 +767,8 @@ module HotGlue
|
|
676
767
|
@auth_identifier
|
677
768
|
end
|
678
769
|
|
679
|
-
def test_capybara_block
|
680
|
-
(@columns - @show_only).map { |col|
|
770
|
+
def test_capybara_block(which_partial = :create)
|
771
|
+
(@columns - (which_partial == :create ? @show_only : (@update_show_only+@show_only))).map { |col|
|
681
772
|
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
682
773
|
case type
|
683
774
|
when :date
|
@@ -692,16 +783,17 @@ module HotGlue
|
|
692
783
|
' ' + "find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
693
784
|
|
694
785
|
when :integer
|
695
|
-
|
696
786
|
if col.to_s.ends_with?("_id")
|
697
|
-
|
698
|
-
" #{col}_selector = find(\"[name='#{singular}[#{col}]']\").click \n" +
|
699
|
-
" #{col}_selector.first('option', text: #{assoc}1.name).select_option"
|
787
|
+
capybara_block_for_association(col_name: col, which_partial: which_partial)
|
700
788
|
else
|
701
789
|
" new_#{col} = rand(10) \n" +
|
702
|
-
|
703
|
-
|
790
|
+
" find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
704
791
|
end
|
792
|
+
when :float
|
793
|
+
" " + "new_#{col} = rand(10) \n" +
|
794
|
+
" find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
795
|
+
when :uuid
|
796
|
+
capybara_block_for_association(col_name: col, which_partial: which_partial)
|
705
797
|
|
706
798
|
when :enum
|
707
799
|
" list_of_#{col.to_s} = #{singular_class}.defined_enums['#{col.to_s}'].keys \n" +
|
@@ -709,17 +801,21 @@ module HotGlue
|
|
709
801
|
' find("select[name=\'' + singular + '[' + col.to_s + ']\'] option[value=\'#{new_' + col.to_s + '}\']").select_option'
|
710
802
|
|
711
803
|
when :boolean
|
712
|
-
"
|
713
|
-
"
|
804
|
+
" new_#{col} = 1 \n" +
|
805
|
+
" find(\"[name='#{testing_name}[#{col}]'][value='\#{new_" + col.to_s + "}']\").choose"
|
714
806
|
when :string
|
715
|
-
|
716
|
-
|
717
|
-
"
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
"
|
722
|
-
|
807
|
+
faker_string =
|
808
|
+
if col.to_s.include?('email')
|
809
|
+
"FFaker::Internet.email"
|
810
|
+
elsif col.to_s.include?('domain')
|
811
|
+
"FFaker::Internet.domain_name"
|
812
|
+
elsif col.to_s.include?('ip_address') || col.to_s.ends_with?('_ip')
|
813
|
+
"FFaker::Internet.ip_v4_address"
|
814
|
+
else
|
815
|
+
"FFaker::Movie.title"
|
816
|
+
end
|
817
|
+
" " + "new_#{col} = #{faker_string} \n" +
|
818
|
+
" find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
723
819
|
when :text
|
724
820
|
" " + "new_#{col} = FFaker::Lorem.paragraphs(1).join("") \n" +
|
725
821
|
" find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
@@ -729,6 +825,20 @@ module HotGlue
|
|
729
825
|
end
|
730
826
|
|
731
827
|
|
828
|
+
def capybara_block_for_association(col_name: nil , which_partial: nil )
|
829
|
+
assoc = col_name.to_s.gsub('_id','')
|
830
|
+
if which_partial == :update && @update_show_only.include?(col_name)
|
831
|
+
# do not update tests
|
832
|
+
elsif @alt_lookups.keys.include?(col_name.to_s)
|
833
|
+
lookup = @alt_lookups[col_name.to_s][:lookup_as]
|
834
|
+
" find(\"[name='#{singular}[__lookup_#{lookup}]']\").fill_in( with: #{assoc}1.#{lookup} )"
|
835
|
+
else
|
836
|
+
" #{col_name}_selector = find(\"[name='#{singular}[#{col_name}]']\").click \n" +
|
837
|
+
" #{col_name}_selector.first('option', text: #{assoc}1.name).select_option"
|
838
|
+
end
|
839
|
+
end
|
840
|
+
|
841
|
+
|
732
842
|
def path_helper_args
|
733
843
|
if @nested_set.any? && @nested
|
734
844
|
[(@nested_set).collect{|a| "#{a[:singular]}"} , singular].join(",")
|
@@ -911,7 +1021,7 @@ module HotGlue
|
|
911
1021
|
|
912
1022
|
|
913
1023
|
def include_nav_template
|
914
|
-
File.
|
1024
|
+
File.exist?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_nav.html.#{@markup}")
|
915
1025
|
end
|
916
1026
|
|
917
1027
|
def copy_view_files
|
@@ -948,7 +1058,7 @@ module HotGlue
|
|
948
1058
|
|
949
1059
|
# menu_file = "app/views#{namespace_with_dash}/menu.erb"
|
950
1060
|
#
|
951
|
-
# if File.
|
1061
|
+
# if File.exist?(menu_file)
|
952
1062
|
# # TODO: can I insert the new menu item into the menu programatically here?
|
953
1063
|
# # not sure how i would achieve this without nokogiri
|
954
1064
|
#
|
@@ -1004,9 +1114,11 @@ module HotGlue
|
|
1004
1114
|
|
1005
1115
|
unless @no_edit
|
1006
1116
|
res << 'edit'
|
1007
|
-
res << '_form'
|
1008
1117
|
end
|
1009
1118
|
|
1119
|
+
if !( @no_edit && @no_create)
|
1120
|
+
res << '_form'
|
1121
|
+
end
|
1010
1122
|
res
|
1011
1123
|
end
|
1012
1124
|
|
@@ -1041,35 +1153,28 @@ module HotGlue
|
|
1041
1153
|
[]
|
1042
1154
|
end
|
1043
1155
|
|
1044
|
-
def
|
1156
|
+
def form_fields_html
|
1045
1157
|
@template_builder.all_form_fields(
|
1046
1158
|
columns: @layout_object[:columns][:container],
|
1047
1159
|
show_only: @show_only,
|
1160
|
+
update_show_only: @update_show_only,
|
1048
1161
|
singular_class: singular_class,
|
1049
1162
|
singular: singular,
|
1050
1163
|
hawk_keys: @hawk_keys,
|
1051
1164
|
col_identifier: @layout_strategy.column_classes_for_form_fields,
|
1052
1165
|
ownership_field: @ownership_field,
|
1053
1166
|
form_labels_position: @form_labels_position,
|
1054
|
-
form_placeholder_labels: @form_placeholder_labels
|
1167
|
+
form_placeholder_labels: @form_placeholder_labels,
|
1168
|
+
alt_lookups: @alt_lookups
|
1055
1169
|
)
|
1056
1170
|
end
|
1057
1171
|
|
1058
|
-
|
1059
1172
|
def list_label
|
1060
|
-
|
1061
|
-
eval("#{class_name}.class_variable_get(:@@table_label_plural)")
|
1062
|
-
else
|
1063
|
-
plural.gsub("_", " ").upcase
|
1064
|
-
end
|
1173
|
+
@list_label_heading
|
1065
1174
|
end
|
1066
1175
|
|
1067
|
-
def
|
1068
|
-
|
1069
|
-
eval("#{class_name}.class_variable_get(:@@table_label_singular)")
|
1070
|
-
else
|
1071
|
-
singular.gsub("_", " ").upcase
|
1072
|
-
end
|
1176
|
+
def new_thing_label
|
1177
|
+
@new_thing_label
|
1073
1178
|
end
|
1074
1179
|
|
1075
1180
|
def all_line_fields
|
@@ -1155,12 +1260,18 @@ module HotGlue
|
|
1155
1260
|
}.join("\n") + "\n"
|
1156
1261
|
end
|
1157
1262
|
|
1263
|
+
|
1158
1264
|
def controller_update_params_tap_away_magic_buttons
|
1159
1265
|
@magic_buttons.collect{ |magic_button|
|
1160
|
-
".tap{ |ary| ary.delete('#{magic_button}') }"
|
1266
|
+
".tap{ |ary| ary.delete('__#{magic_button}') }"
|
1161
1267
|
}.join("")
|
1162
1268
|
end
|
1163
1269
|
|
1270
|
+
def controller_update_params_tap_away_alt_lookups
|
1271
|
+
@alt_lookups.collect{ |key, data|
|
1272
|
+
".tap{ |ary| ary.delete('__lookup_#{data[:lookup_as]}') }"
|
1273
|
+
}.join("")
|
1274
|
+
end
|
1164
1275
|
|
1165
1276
|
def nested_for_turbo_id_list_constructor
|
1166
1277
|
if @nested_set.any?
|
@@ -1207,9 +1318,10 @@ module HotGlue
|
|
1207
1318
|
end
|
1208
1319
|
|
1209
1320
|
def hawk_to_ruby
|
1210
|
-
@hawk_keys.collect{ |k,v|
|
1211
|
-
"#{k}: [#{v[0]}, \"#{v[1]}\"]
|
1321
|
+
res = @hawk_keys.collect{ |k,v|
|
1322
|
+
"#{k}: [#{v[0]}, \"#{v[1]}\"]"
|
1212
1323
|
}.join(", ")
|
1324
|
+
res
|
1213
1325
|
end
|
1214
1326
|
end
|
1215
1327
|
end
|
@@ -5,8 +5,8 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
5
5
|
helper :hot_glue
|
6
6
|
include HotGlue::ControllerHelper
|
7
7
|
|
8
|
-
<% unless @auth_identifier == '' || @god %>before_action :<%= auth_root %><% end %>
|
9
|
-
|
8
|
+
<% unless @auth_identifier == '' || @god %>before_action :<%= auth_root %><% end %><% if any_nested? %>
|
9
|
+
<% nest_chain = [] %> <% @nested_set.each { |arg|
|
10
10
|
|
11
11
|
if auth_identifier == arg[:singular]
|
12
12
|
this_scope = auth_object
|
@@ -17,13 +17,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
17
17
|
end
|
18
18
|
|
19
19
|
nest_chain << arg %>
|
20
|
-
before_action :<%= arg[:singular] %><%= ", if: -> { params.include?(:#{arg[:singular]}_id) }" if arg[:optional] %>
|
21
|
-
|
22
|
-
<% } %><% end %>
|
20
|
+
before_action :<%= arg[:singular] %><%= ", if: -> { params.include?(:#{arg[:singular]}_id) }" if arg[:optional] %><% } %><% end %>
|
23
21
|
before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
|
24
|
-
after_action -> { flash.discard }, if: -> { request.format.symbol ==
|
25
|
-
<% if @nested_set.any? %>
|
26
|
-
def <%= @nested_set[0][:singular] %><% if @god
|
22
|
+
after_action -> { flash.discard }, if: -> { request.format.symbol == :turbo_stream }
|
23
|
+
<% if @nested_set.any? %>def <%= @nested_set[0][:singular] %><% if @god
|
27
24
|
next_object = nil
|
28
25
|
collect_objects = @nested_set.reverse.collect {|x|
|
29
26
|
if eval("#{next_object || class_name}.reflect_on_association(:#{x[:singular]})").nil?
|
@@ -39,9 +36,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
39
36
|
root_object = @auth + "." + @nested_set[0][:plural]
|
40
37
|
end
|
41
38
|
end
|
42
|
-
%>
|
43
|
-
|
44
|
-
<% else %>
|
39
|
+
%><% if !@god && @nested_set[0][:singular] == @auth_identifier %>
|
40
|
+
@<%= @nested_set[0][:singular] %> ||= <%= root_object %>
|
41
|
+
<% else %>
|
42
|
+
@<%= @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 %>
|
45
43
|
end
|
46
44
|
<% end %><% if any_nested? %><% nest_chain = [@nested_set[0][:singular]]; this_scope = @nested_set[0][:plural]; %>
|
47
45
|
<% for index in 0..(@nested_set.count - 1) do
|
@@ -54,18 +52,18 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
54
52
|
def <%= arg[:singular] %>
|
55
53
|
@<%= arg[:singular] %> ||= (<%= this_scope %>.find(params[:<%= arg[:singular] %>_id])<%= " if params.include?(:#{last_arg[:singular]}_id)" if last_arg && @god && last_arg[:optional] %>)
|
56
54
|
<% if @god && last_arg && (last_arg[:optional] ) %>@<%= arg[:singular] %> ||= (<%= collect_objects[index-1] %>.find(params[:<%= arg[:singular] %>_id]) if params.include?(:<%= arg[:singular] %>_id) ) <% end %>
|
57
|
-
end<% end %>
|
58
|
-
<% end %><% end %> <% if !@self_auth %>
|
55
|
+
end<% end %><% end %><% end %> <% if !@self_auth %>
|
59
56
|
def load_<%= singular_name %>
|
60
|
-
@<%= singular_name %> =
|
57
|
+
@<%= 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 %>
|
61
58
|
end
|
62
59
|
<% else %>
|
63
60
|
def load_<%= singular_name %>
|
64
61
|
@<%= singular_name %> = (<%= auth_object.gsub("@",'') %><%= " if params.include?(:#{@nested_set[0][:singular]}_id)" if @nested_set.any? && @nested_set[0][:optional] %>)<% if @nested_set.any? && @nested_set[0][:optional] %> || <%= class_name %>.find(params[:id])<% end %>
|
65
62
|
end<% end %>
|
66
63
|
|
67
|
-
def load_all_<%= plural
|
68
|
-
@<%= plural_name %> =
|
64
|
+
def load_all_<%= plural %><% if !@self_auth %>
|
65
|
+
@<%= plural_name %> = <%= object_scope.gsub("@",'') %>.page(params[:page])<%= n_plus_one_includes %><%= " if params.include?(:#{ @nested_set.last[:singular]}_id)" if @nested_set.any? && @nested_set[0] && @nested_set[0][:optional] %><% if @nested_set[0] && @nested_set[0][:optional] %>
|
66
|
+
@<%= plural_name %> = <%= class_name %>.all<% end %><% else %>
|
69
67
|
@<%= plural_name %> = <%= class_name %>.where(id: <%= auth_object.gsub("@",'') %>.id)<%= n_plus_one_includes %> # returns iterable even though this <%= singular_name %> is only allowed access to themselves<% end %>
|
70
68
|
end
|
71
69
|
|
@@ -73,19 +71,20 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
73
71
|
load_all_<%= plural %>
|
74
72
|
end
|
75
73
|
|
76
|
-
<% if create_action %> def new
|
77
|
-
@<%= singular_name %> = <%= class_name %>.new(<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)
|
78
|
-
@<%= singular_name %> = <%= class_name %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}))
|
74
|
+
<% if create_action %> def new<% if @object_owner_sym %>
|
75
|
+
@<%= singular_name %> = <%= class_name %>.new(<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% elsif @object_owner_optional && any_nested? %>
|
76
|
+
@<%= singular_name %> = <%= class_name %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}))<% else %>
|
79
77
|
@<%= singular_name %> = <%= class_name %>.new(<% if any_nested? %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)
|
80
78
|
<% end %>
|
81
79
|
end
|
82
80
|
|
83
81
|
def create
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
<% if @alt_lookups.any? %><%= @alt_lookups.collect{|key, data|
|
83
|
+
" #{data[:assoc].downcase} = #{data[:assoc]}.#{data[:with_create] ? "find_or_create_by" : "find_by"}(#{data[:lookup_as]}: #{ singular_name }_params[:__lookup_#{data[:lookup_as]}])\n"
|
84
|
+
}.join("/n") %><% end %> <% merge_lookups = @alt_lookups.collect{|key, data| "#{key.gsub("_id", "")}: #{key.gsub("_id", "")}" }.join(",") %>
|
85
|
+
modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<%= controller_update_params_tap_away_alt_lookups %><% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>.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 %>)<%= ".merge(#{merge_lookups})" if !merge_lookups.empty? %><% if @hawk_keys.any? %>
|
86
|
+
modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
|
87
|
+
<%= creation_syntax %>
|
89
88
|
if @<%= singular_name %>.save
|
90
89
|
flash[:notice] = "Successfully created #{@<%= singular %>.<%= display_class %>}"
|
91
90
|
load_all_<%= plural %>
|
@@ -102,9 +101,22 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
102
101
|
end
|
103
102
|
|
104
103
|
<% end %><% if @build_update_action %> def update
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
<% if @alt_lookups.filter{|key,d| ! @update_show_only.include?(key.to_sym) }.any? %><%= @alt_lookups.filter{|key,d| ! @update_show_only.include?(key.to_sym) }.collect{|key, data|
|
105
|
+
" #{data[:assoc].downcase} = #{data[:assoc]}.#{data[:with_create] ? "find_or_create_by" : "find_by"}(#{data[:lookup_as]}: #{ singular_name }_params[:__lookup_#{data[:lookup_as]}])\n"
|
106
|
+
}.join("\n") %><% end %> <% merge_lookups = @alt_lookups.filter{|key,d| ! @update_show_only.include?(key.to_sym) }.collect{|key, data| "#{key.gsub("_id", "")}: #{key.gsub("_id", "")}" }.join(",") %>
|
107
|
+
<% @magic_buttons.each { |button| %>@<%= singular_name %>.<%= button %>! if <%= singular_name %>_params[:__<%= button %>]
|
108
|
+
<% } %>
|
109
|
+
modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>.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 %>)<%= controller_update_params_tap_away_alt_lookups %><%= controller_update_params_tap_away_magic_buttons %><%= ".merge(#{merge_lookups})" if !merge_lookups.empty? %>
|
110
|
+
|
111
|
+
<% if @hawk_keys.any? %> modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
|
112
|
+
<% if @alt_lookups.any? %><%= @alt_lookups.collect{|key, data|
|
113
|
+
unless @factory_creation.include?("#{data[:assoc].downcase} = ")
|
114
|
+
" #{data[:assoc].downcase} = #{data[:assoc]}.#{data[:with_create] ? "find_or_create_by" : "find_by"}(#{data[:lookup_as]}: #{ singular_name }_params[:__lookup_#{data[:lookup_as]}])\n"
|
115
|
+
end
|
116
|
+
}.join("/n") %><% end %><% if (@update_alt_lookups).any? %>
|
117
|
+
<%= @update_alt_lookups.collect{|key, data|
|
118
|
+
" @#{ singular_name }.#{key.gsub("_id", "")} = #{key.gsub("_id", "")}"
|
119
|
+
}.join("/n") %><% end %>
|
108
120
|
if @<%= singular_name %>.update(modified_params)
|
109
121
|
<% if @display_list_after_update %> load_all_<%= plural %><% end %>
|
110
122
|
flash[:notice] = (flash[:notice] || "") << "Saved #{@<%= singular %>.<%= display_class %>}"
|
@@ -120,17 +132,17 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
120
132
|
begin
|
121
133
|
@<%=singular_name%>.destroy
|
122
134
|
rescue StandardError => e
|
123
|
-
flash[:alert] =
|
135
|
+
flash[:alert] = '<%= singular_name.titlecase %> could not be deleted.'
|
124
136
|
end
|
125
137
|
load_all_<%= plural %>
|
126
138
|
end<% end %>
|
127
139
|
|
128
140
|
def <%=singular_name%>_params
|
129
|
-
params.require(:<%= testing_name %>).permit(
|
141
|
+
params.require(:<%= testing_name %>).permit(<%= (fields_filtered_for_email_lookups - @show_only) + @magic_buttons.collect{|x| "__#{x}".to_sym }%>)
|
130
142
|
end
|
131
143
|
|
132
144
|
def namespace
|
133
|
-
<% if @namespace %>
|
145
|
+
<% if @namespace %>'<%= @namespace %>/'<% else %><% end %>
|
134
146
|
end
|
135
147
|
end
|
136
148
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="row">
|
2
|
-
<%=
|
2
|
+
<%= form_fields_html %>
|
3
3
|
|
4
|
-
<div class="<%= @layout_strategy.
|
4
|
+
<div class="<%= @layout_strategy.column_classes_for_button_column %>">
|
5
5
|
<\%= link_to "Cancel", <%= path_helper_plural %>, {class: "btn btn-secondary"} %><% if @no_field_form %>
|
6
6
|
<\%= f.hidden_field "_________" %><% end %>
|
7
7
|
<\%= f.submit "Save", class: "btn btn-primary pull-right" %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% if @turbo_streams %><\%= turbo_stream_from <%= singular %> %>
|
2
2
|
<% end %><\%= turbo_frame_tag "<%= @namespace %>__#{ dom_id(<%= singular %>) }" do %>
|
3
3
|
<div class='<%= @layout_strategy.row_classes %>' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
|
4
|
-
<\%= render partial: '<%=
|
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 %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<\%= turbo_frame_tag "<%= @namespace %>__<%= singular %>-new" do %>
|
2
2
|
<div>
|
3
|
-
<\%= link_to "
|
3
|
+
<\%= link_to "<%= @new_button_label %>", <%= new_path_name %>, disable_with: "Loading...", class: "new-<%= singular %>-button btn btn-primary pull-right <%= 'btn-sm' if @nested_set.any? %> " %>
|
4
4
|
</div>
|
5
5
|
<\% end %>
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<\%= turbo_frame_tag "<%= @namespace %>__<%= singular %>-new" do %>
|
2
|
-
<h3>
|
3
|
-
|
2
|
+
<h3>
|
3
|
+
<%= @new_form_heading %>
|
4
4
|
</h3>
|
5
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
|
-
|
8
|
-
|
7
|
+
locals: { <%= singular %>: <%= singular %>, f: f}<%= @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}}: {})" }.join %> \%>
|
8
|
+
<\% end %>
|
9
9
|
<\% end %>
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<% downnest_class = downnest_object.class_name %>
|
11
11
|
<% downnest_object_name = eval("#{downnest_class}.table_name") %>
|
12
12
|
<% downnest_style = @layout_strategy.downnest_style %>
|
13
|
-
<div class="<%=
|
13
|
+
<div class="<%= @layout_strategy.downnest_portal_column_width(downnest) %> scaffold-downnest" <%= downnest_style %> >
|
14
14
|
<\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {
|
15
15
|
<%= @singular %>: <%= @singular %>,
|
16
16
|
<%= downnest_object_name %>: <%= @singular %>.<%= downnest %>
|
@@ -23,7 +23,7 @@
|
|
23
23
|
<% end %>
|
24
24
|
|
25
25
|
<%= @layout_strategy.button_style %>
|
26
|
-
<div class="
|
26
|
+
<div class=" scaffold-line-buttons <%= @layout_strategy.column_classes_for_button_column %>" <%= @layout_strategy.button_style %>>
|
27
27
|
<%= magic_button_output %>
|
28
28
|
|
29
29
|
<% if destroy_action %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% if !@display_list_after_update %><\%= turbo_stream.replace "<%= namespace %>__#{dom_id(@<%= singular %>)}" do %>
|
1
|
+
<% if !@display_list_after_update %><\%= turbo_stream.replace "<%= @namespace %>__#{dom_id(@<%= singular %>)}" do %>
|
2
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
4
|
<\%= render partial: '<%= list_path_partial %>', locals: {<%= plural %>: @<%= plural %>}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
|