hot-glue 0.2.3 → 0.2.9E
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/.travis.yml +15 -0
- data/Gemfile +8 -2
- data/Gemfile.lock +35 -24
- data/README.md +307 -85
- data/Rakefile +34 -24
- data/app/helpers/hot_glue/controller_helper.rb +6 -4
- data/app/helpers/hot_glue_helper.rb +4 -0
- data/app/views/layouts/_flash_notices.erb +12 -0
- data/lib/generators/hot_glue/install_generator.rb +55 -0
- data/lib/generators/hot_glue/markup_templates/erb.rb +51 -8
- data/lib/generators/hot_glue/markup_templates/haml.rb +2 -2
- data/lib/generators/hot_glue/scaffold_generator.rb +87 -35
- data/lib/generators/hot_glue/templates/capybara_login.rb +8 -0
- data/lib/generators/hot_glue/templates/confirmable.js +14 -0
- data/lib/generators/hot_glue/templates/controller.rb.erb +18 -22
- data/lib/generators/hot_glue/templates/erb/_line.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_list.erb +10 -2
- data/lib/generators/hot_glue/templates/erb/_show.erb +18 -2
- data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +3 -3
- data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/edit.erb +3 -13
- data/lib/generators/hot_glue/templates/erb/index.erb +1 -2
- data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +5 -2
- data/lib/generators/hot_glue/templates/haml/_line.haml +1 -1
- data/lib/generators/hot_glue/templates/haml/_list.haml +5 -1
- data/lib/generators/hot_glue/templates/haml/create.turbo_stream.haml +3 -3
- data/lib/generators/hot_glue/templates/haml/destroy.turbo_stream.haml +1 -1
- data/lib/generators/hot_glue/templates/haml/edit.haml +0 -2
- data/lib/generators/hot_glue/templates/haml/index.haml +1 -2
- data/lib/generators/hot_glue/templates/system_spec.rb.erb +146 -47
- data/lib/hot-glue.rb +1 -2
- data/lib/hotglue/version.rb +1 -1
- metadata +23 -33
@@ -18,6 +18,61 @@ module HotGlue
|
|
18
18
|
copy_file "erb/_flash_notices.erb", "#{'spec/dummy/' if Rails.env.test?}app/views/layouts/_flash_notices.erb"
|
19
19
|
|
20
20
|
end
|
21
|
+
|
22
|
+
if Rails.version.split(".")[0].to_i >= 7
|
23
|
+
copy_file "confirmable.js", "#{'spec/dummy/' if Rails.env.test?}app/javascript/controllers/confirmable.js"
|
24
|
+
end
|
25
|
+
|
26
|
+
if Rails.version.split(".")[0].to_i == 6
|
27
|
+
app_js_contents = File.read("app/javascript/packs/application.js")
|
28
|
+
if app_js_contents.include?("import Turbolinks from \"turbolinks\"")
|
29
|
+
app_js_contents.gsub!("import Turbolinks from \"turbolinks\"", "import { Turbo } from \"@hotwired/turbo-rails\"")
|
30
|
+
puts " HOTGLUE --> fixed packs/application.js: swapping old Turbolinks syntas for new Turbo-Rails syntax [ import { Turbo } from \"@hotwired/turbo-rails\" ] "
|
31
|
+
end
|
32
|
+
|
33
|
+
if app_js_contents.include?("Turbolinks.start()")
|
34
|
+
app_js_contents.gsub!("Turbolinks.start()", "Turbo.start()")
|
35
|
+
puts " HOTGLUE --> fixed packs/application.js: swapping old Turbolinks syntas for new Turbo-Rails syntax[ Turbolinks.start() ] "
|
36
|
+
end
|
37
|
+
File.write("app/javascript/packs/application.js", app_js_contents)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
rails_helper_contents = File.read("spec/rails_helper.rb")
|
43
|
+
if !rails_helper_contents.include?("Capybara.default_driver =")
|
44
|
+
rails_helper_contents << "\nCapybara.default_driver = :selenium_chrome_headless "
|
45
|
+
puts " HOTGLUE --> added to spec/rails_helper.rb: `Capybara.default_driver = :selenium_chrome_headless` "
|
46
|
+
end
|
47
|
+
|
48
|
+
if !rails_helper_contents.include?("include FactoryBot::Syntax::Methods")
|
49
|
+
rails_helper_contents.gsub!("RSpec.configure do |config|", "RSpec.configure do |config| \n
|
50
|
+
config.include FactoryBot::Syntax::Methods
|
51
|
+
")
|
52
|
+
puts " HOTGLUE --> added to spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
|
53
|
+
end
|
54
|
+
|
55
|
+
if ! rails_helper_contents.include?("require 'support/capybara_login.rb'")
|
56
|
+
rails_helper_contents.gsub!("require 'rspec/rails'","require 'rspec/rails' \nrequire 'support/capybara_login.rb'")
|
57
|
+
puts " HOTGLUE --> added to spec/rails_helper.rb: `require 'support/capybara_login.rb'` "
|
58
|
+
end
|
59
|
+
File.write("spec/rails_helper.rb", rails_helper_contents)
|
60
|
+
|
61
|
+
|
62
|
+
application_layout_contents = File.read("app/views/layouts/application.html.erb")
|
63
|
+
|
64
|
+
if !application_layout_contents.include?("render partial: 'layouts/flash_notices'")
|
65
|
+
application_layout_contents.gsub!("<body>", "<body>\n
|
66
|
+
<%= render partial: 'layouts/flash_notices' %>
|
67
|
+
")
|
68
|
+
File.write("app/views/layouts/application.html.erb", application_layout_contents)
|
69
|
+
puts " HOTGLUE --> added to app/views/layouts/application.html.erb: `<%= render partial: 'layouts/flash_notices' %>` "
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
if !File.exists?("spec/support/capybara_login.rb")
|
74
|
+
copy_file "capybara_login.rb", "#{'spec/dummy/' if Rails.env.test?}spec/support/capybara_login.rb"
|
75
|
+
end
|
21
76
|
end
|
22
77
|
end
|
23
78
|
end
|
@@ -11,6 +11,34 @@ module HotGlue
|
|
11
11
|
"</div>"
|
12
12
|
end
|
13
13
|
|
14
|
+
|
15
|
+
def magic_button_output(*args)
|
16
|
+
path_helper_singular = args[0][:path_helper_singular]
|
17
|
+
path_helper_args = args[0][:path_helper_args]
|
18
|
+
singular = args[0][:singular]
|
19
|
+
magic_buttons = args[0][:magic_buttons]
|
20
|
+
|
21
|
+
magic_buttons.collect{ |button_name|
|
22
|
+
"<%= form_with model: #{singular}, url: #{path_helper_singular}(#{path_helper_args}) do |f| %>
|
23
|
+
<%= f.hidden_field :#{button_name}, value: \"#{button_name}\" %>
|
24
|
+
<%= f.submit '#{button_name.titleize}'.html_safe, data: {confirm: 'Are you sure you want to #{button_name} this #{singular}?'}, class: '#{singular}-button btn btn-primary ' %>
|
25
|
+
<% end %>"
|
26
|
+
}.join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
def text_area_output(col, field_length, col_identifier )
|
30
|
+
lines = field_length % 40
|
31
|
+
if lines > 5
|
32
|
+
lines = 5
|
33
|
+
end
|
34
|
+
|
35
|
+
"<div class=\"#{col_identifier} form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\">" +
|
36
|
+
"<%= f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}' %>" +
|
37
|
+
"<label class='form-text'>#{col.to_s.humanize}</label>"+
|
38
|
+
"</div>"
|
39
|
+
|
40
|
+
end
|
41
|
+
|
14
42
|
def list_column_headings(*args)
|
15
43
|
columns = args[0][:columns]
|
16
44
|
|
@@ -19,7 +47,6 @@ module HotGlue
|
|
19
47
|
|
20
48
|
|
21
49
|
def all_form_fields(*args)
|
22
|
-
|
23
50
|
columns = args[0][:columns]
|
24
51
|
show_only = args[0][:show_only]
|
25
52
|
singular_class = args[0][:singular_class]
|
@@ -71,19 +98,17 @@ module HotGlue
|
|
71
98
|
|
72
99
|
end
|
73
100
|
when :string
|
74
|
-
|
75
|
-
|
76
|
-
field_output(col, nil, limit, col_identifier)
|
101
|
+
if sql_type == "varchar" || sql_type == "character varying"
|
102
|
+
field_output(col, nil, limit || 40, col_identifier)
|
77
103
|
else
|
78
|
-
text_area_output(col,
|
104
|
+
text_area_output(col, 65536, col_identifier)
|
79
105
|
end
|
80
106
|
|
81
107
|
when :text
|
82
|
-
|
83
|
-
if limit <= 256
|
108
|
+
if sql_type == "varchar"
|
84
109
|
field_output(col, nil, limit, col_identifier)
|
85
110
|
else
|
86
|
-
text_area_output(col,
|
111
|
+
text_area_output(col, 65536, col_identifier)
|
87
112
|
end
|
88
113
|
when :float
|
89
114
|
limit ||= 256
|
@@ -113,7 +138,16 @@ module HotGlue
|
|
113
138
|
" <%= f.radio_button(:#{col.to_s}, '1', checked: #{singular}.#{col.to_s} ? 'checked' : '') %>\n" +
|
114
139
|
" <%= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1') %>\n" +
|
115
140
|
"</div>"
|
141
|
+
when :enum
|
142
|
+
enum_name = "enum_name"
|
143
|
+
# byebug
|
144
|
+
enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col.to_s}'}[0].sql_type")
|
145
|
+
"<div class='#{col_identifier} form-group <%= 'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s}) %>' >
|
146
|
+
<%= f.collection_select(:#{col.to_s}, enum_to_collection_select( #{singular_class}.defined_enums['#{enum_type}']), :key, :value, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control') %>
|
147
|
+
<label class='small form-text text-muted'>#{col.to_s.humanize}</label></div>"
|
148
|
+
|
116
149
|
end
|
150
|
+
|
117
151
|
end
|
118
152
|
}.join("\n")
|
119
153
|
return res
|
@@ -216,6 +250,14 @@ module HotGlue
|
|
216
250
|
NO
|
217
251
|
<% end %>
|
218
252
|
</div>
|
253
|
+
" when :enum
|
254
|
+
"<div class='#{col_identifer}'>
|
255
|
+
<% if #{singular}.#{col}.nil? %>
|
256
|
+
<span class='alert-danger'>MISSING</span>
|
257
|
+
<% else %>
|
258
|
+
<%= #{singular}.#{col} %>
|
259
|
+
<% end %>
|
260
|
+
</div>
|
219
261
|
"
|
220
262
|
end #end of switch
|
221
263
|
}.join("\n")
|
@@ -224,4 +266,5 @@ module HotGlue
|
|
224
266
|
|
225
267
|
|
226
268
|
|
269
|
+
|
227
270
|
end
|
@@ -64,7 +64,7 @@ module HotGlue
|
|
64
64
|
exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
65
65
|
exit
|
66
66
|
end
|
67
|
-
display_column = derrive_reference_name(assoc.class_name)
|
67
|
+
display_column = HotGlue.derrive_reference_name(assoc.class_name)
|
68
68
|
|
69
69
|
|
70
70
|
"#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
|
@@ -162,7 +162,7 @@ module HotGlue
|
|
162
162
|
raise(HotGlue::Error,exit_message)
|
163
163
|
end
|
164
164
|
|
165
|
-
display_column = derrive_reference_name(assoc.class_name)
|
165
|
+
display_column = HotGlue.derrive_reference_name(assoc.class_name)
|
166
166
|
|
167
167
|
|
168
168
|
"#{col_identifer}
|
@@ -31,7 +31,7 @@ module HotGlue
|
|
31
31
|
end
|
32
32
|
|
33
33
|
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
34
|
-
|
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,21 +51,16 @@ 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
58
|
class_option :markup, type: :string, default: "erb"
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# if @template_builder.is_a?(HotGlue::ErbTemplate)
|
64
|
-
# @output_buffer.gsub!('\%', '%')
|
65
|
-
# end
|
66
|
-
# end
|
67
|
-
|
68
|
-
|
59
|
+
class_option :stimulus_syntax, type: :boolean, default: nil
|
60
|
+
class_option :downnest, type: :string, default: nil
|
61
|
+
class_option :nestable, type: :boolean, default: false
|
62
|
+
class_option :magic_buttons, type: :string, default: nil
|
63
|
+
class_option :display_list_after_update, type: :boolean, default: false
|
69
64
|
|
70
65
|
def initialize(*meta_args)
|
71
66
|
super
|
@@ -106,7 +101,7 @@ module HotGlue
|
|
106
101
|
@singular = args.first.tableize.singularize # should be in form hello_world
|
107
102
|
@plural = options['plural'] || @singular + "s" # supply to override; leave blank to use default
|
108
103
|
@auth = options['auth'] || "current_user"
|
109
|
-
@auth_identifier = options['auth_identifier'] || (
|
104
|
+
@auth_identifier = options['auth_identifier'] || (! @god && @auth.gsub("current_", "")) || nil
|
110
105
|
|
111
106
|
|
112
107
|
@nest = (!options['nest'].empty? && options['nest']) || nil
|
@@ -114,6 +109,7 @@ module HotGlue
|
|
114
109
|
|
115
110
|
@singular_class = @singular.titleize.gsub(" ", "")
|
116
111
|
@exclude_fields = []
|
112
|
+
|
117
113
|
@exclude_fields += options['exclude'].split(",").collect(&:to_sym)
|
118
114
|
|
119
115
|
if !options['include'].empty?
|
@@ -138,6 +134,13 @@ module HotGlue
|
|
138
134
|
@no_paginate = options['no_paginate'] || false
|
139
135
|
@big_edit = options['big_edit']
|
140
136
|
|
137
|
+
@no_edit = options['no_edit'] || false
|
138
|
+
@display_list_after_update = options['display_list_after_update'] || false
|
139
|
+
|
140
|
+
|
141
|
+
@downnest_relationship = options['downnest'] || false
|
142
|
+
|
143
|
+
|
141
144
|
if @god
|
142
145
|
@auth = nil
|
143
146
|
end
|
@@ -156,8 +159,16 @@ module HotGlue
|
|
156
159
|
end
|
157
160
|
end
|
158
161
|
|
159
|
-
|
160
|
-
|
162
|
+
|
163
|
+
@magic_buttons = []
|
164
|
+
if options['magic_buttons']
|
165
|
+
@magic_buttons = options['magic_buttons'].split(',')
|
166
|
+
end
|
167
|
+
|
168
|
+
@build_update_action = !@no_edit || !@magic_buttons.empty?
|
169
|
+
# if the magic buttons are present, build the update action anyway
|
170
|
+
|
171
|
+
@nestable = options['nestable'] || false
|
161
172
|
|
162
173
|
if @auth && ! @self_auth && @nested_args.none?
|
163
174
|
@object_owner_sym = @auth.gsub("current_", "").to_sym
|
@@ -173,6 +184,8 @@ module HotGlue
|
|
173
184
|
end
|
174
185
|
end
|
175
186
|
|
187
|
+
|
188
|
+
|
176
189
|
@reference_name = HotGlue.derrive_reference_name(singular_class)
|
177
190
|
|
178
191
|
identify_object_owner
|
@@ -286,6 +299,8 @@ module HotGlue
|
|
286
299
|
nil
|
287
300
|
end
|
288
301
|
|
302
|
+
|
303
|
+
|
289
304
|
def copy_controller_and_spec_files
|
290
305
|
@default_colspan = @columns.size
|
291
306
|
unless @specs_only
|
@@ -381,24 +396,32 @@ module HotGlue
|
|
381
396
|
end
|
382
397
|
|
383
398
|
def path_helper_args
|
384
|
-
if @nested_args.any?
|
385
|
-
[(@nested_args).collect{|a| "
|
399
|
+
if @nested_args.any? && @nestable
|
400
|
+
[(@nested_args).collect{|a| "#{a}"} , singular].join(",")
|
386
401
|
else
|
387
402
|
singular
|
388
403
|
end
|
389
404
|
end
|
390
405
|
|
391
406
|
def path_helper_singular
|
392
|
-
|
407
|
+
if @nestable
|
408
|
+
"#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
|
409
|
+
else
|
410
|
+
"#{@namespace+"_" if @namespace}#{singular}_path"
|
411
|
+
end
|
393
412
|
end
|
394
413
|
|
395
414
|
def path_helper_plural
|
396
|
-
|
415
|
+
if ! @nestable
|
416
|
+
"#{@namespace+"_" if @namespace}#{plural}_path"
|
417
|
+
else
|
418
|
+
"#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{plural}_path"
|
419
|
+
end
|
397
420
|
end
|
398
421
|
|
399
422
|
def path_arity
|
400
423
|
res = ""
|
401
|
-
if @nested_args.any?
|
424
|
+
if @nested_args.any? && @nestable
|
402
425
|
res << nested_objects_arity + ", "
|
403
426
|
end
|
404
427
|
res << "@" + singular
|
@@ -417,28 +440,37 @@ module HotGlue
|
|
417
440
|
end
|
418
441
|
|
419
442
|
def new_path_name
|
420
|
-
|
421
443
|
base = "new_#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_") if @nested_args.any?}#{singular}_path"
|
422
444
|
if @nested_args.any?
|
423
445
|
base += "(" + @nested_args.collect { |arg|
|
424
|
-
"
|
446
|
+
"#{arg}.id"
|
425
447
|
}.join(", ") + ")"
|
426
448
|
end
|
427
449
|
base
|
428
450
|
end
|
429
451
|
|
430
452
|
def nested_assignments
|
453
|
+
return "" if @nested_args.none?
|
454
|
+
@nested_args.map{|a| "#{a}: #{a}"}.join(", ") #metaprgramming into Ruby hash
|
455
|
+
end
|
456
|
+
|
457
|
+
def nested_assignments_top_level # this is by accessing the instance variable-- only use at top level
|
431
458
|
@nested_args.map{|a| "#{a}: @#{a}"}.join(", ") #metaprgramming into Ruby hash
|
432
459
|
end
|
433
460
|
|
434
|
-
|
461
|
+
|
462
|
+
def nest_assignments_operator(top_level = false, leading_comma = false)
|
435
463
|
if @nested_args.any?
|
436
|
-
", #{nested_assignments}"
|
464
|
+
"#{', ' if leading_comma}#{top_level ? nested_assignments_top_level : nested_assignments }"
|
437
465
|
else
|
438
466
|
""
|
439
467
|
end
|
440
468
|
end
|
441
469
|
|
470
|
+
def nested_assignments_with_leading_comma
|
471
|
+
nest_assignments_operator(false, true)
|
472
|
+
end
|
473
|
+
|
442
474
|
def nested_objects_arity
|
443
475
|
@nested_args.map{|a| "@#{a}"}.join(", ")
|
444
476
|
end
|
@@ -490,6 +522,15 @@ module HotGlue
|
|
490
522
|
!Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }['devise']
|
491
523
|
end
|
492
524
|
|
525
|
+
|
526
|
+
def magic_button_output
|
527
|
+
@template_builder.magic_button_output(
|
528
|
+
path_helper_singular: path_helper_singular,
|
529
|
+
path_helper_args: path_helper_args,
|
530
|
+
singular: singular,
|
531
|
+
magic_buttons: @magic_buttons
|
532
|
+
)
|
533
|
+
end
|
493
534
|
# def erb_replace_ampersands!(filename = nil)
|
494
535
|
#
|
495
536
|
# return if filename.nil?
|
@@ -652,24 +693,35 @@ module HotGlue
|
|
652
693
|
else
|
653
694
|
""
|
654
695
|
end
|
655
|
-
|
696
|
+
end
|
656
697
|
|
657
|
-
|
698
|
+
def paginate
|
658
699
|
@template_builder.paginate(plural: plural)
|
659
|
-
|
700
|
+
end
|
660
701
|
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
702
|
+
def delete_confirmation_syntax
|
703
|
+
if !@stimulus_syntax
|
704
|
+
"{confirm: 'Are you sure?'}"
|
705
|
+
else
|
706
|
+
"{controller: 'confirmable', 'confirm-message': \"Are you sure you want to delete \#{ #{@singular}.#{ display_class } } \", 'action': 'confirmation#confirm'}"
|
707
|
+
end
|
666
708
|
end
|
667
|
-
end
|
668
709
|
|
669
710
|
|
670
|
-
|
671
|
-
|
711
|
+
def controller_magic_button_update_actions
|
712
|
+
@magic_buttons.collect{ |magic_button|
|
713
|
+
" @#{singular}.#{magic_button}! if #{singular}_params[:#{magic_button}]"
|
714
|
+
}.join("\n")
|
715
|
+
end
|
672
716
|
|
717
|
+
def controller_update_params_tap_away_magic_buttons
|
718
|
+
@magic_buttons.collect{ |magic_button|
|
719
|
+
".tap{ |ary| ary.delete('#{magic_button}') }"
|
720
|
+
}.join("")
|
721
|
+
end
|
722
|
+
|
723
|
+
private # thor does something fancy like sending the class all of its own methods during some strange run sequence
|
724
|
+
# does not like public methods
|
673
725
|
def cc_filename_with_extensions(name, file_format = format)
|
674
726
|
[name, file_format].compact.join(".")
|
675
727
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
console.log("defining Confirmable....")
|
4
|
+
export default class extends Controller {
|
5
|
+
static values = { message: String }
|
6
|
+
|
7
|
+
confirm(event) {
|
8
|
+
|
9
|
+
if(!window.confirm(this.message)) {
|
10
|
+
event.preventDefault();
|
11
|
+
event.stopPropagation()
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
@@ -1,21 +1,20 @@
|
|
1
1
|
class <%= controller_class_name %> < <%= controller_descends_from %>
|
2
|
-
|
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 %>
|
7
9
|
before_action :<%= arg %>
|
8
10
|
<% } %><% end %>
|
9
11
|
before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
|
10
|
-
|
11
|
-
include HotGlue::ControllerHelper
|
12
|
+
after_action -> { flash.discard }, if: -> { request.format.symbol == :turbo_stream }
|
12
13
|
|
13
14
|
<% if no_devise_installed %>
|
14
15
|
# TODO: implement current_user or use Devise
|
15
16
|
<% end %>
|
16
17
|
|
17
|
-
|
18
|
-
|
19
18
|
<% if any_nested? %><% nest_chain = [] %> <% @nested_args.each { |arg|
|
20
19
|
if !@god
|
21
20
|
this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "#{nest_chain.last}.#{arg}s"
|
@@ -49,7 +48,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
<% if create_action %> def new <% if
|
51
|
+
<% if create_action %> def new <% if ! @god %>
|
53
52
|
@<%= singular_name %> = <%= class_name %>.new(<%= @object_owner_sym %>: <%= @object_owner_eval %>)
|
54
53
|
<% else %>
|
55
54
|
@<%= singular_name %> = <%= class_name %>.new
|
@@ -77,34 +76,37 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
77
76
|
format.html
|
78
77
|
end
|
79
78
|
end
|
80
|
-
end
|
79
|
+
end
|
81
80
|
|
82
|
-
def show
|
81
|
+
<% end %> def show
|
83
82
|
respond_to do |format|
|
84
83
|
format.html
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
88
|
-
def edit
|
87
|
+
<% unless @no_edit %> def edit
|
89
88
|
respond_to do |format|
|
90
89
|
format.turbo_stream
|
91
90
|
format.html
|
92
91
|
end
|
93
92
|
end
|
94
93
|
|
95
|
-
def update
|
96
|
-
|
94
|
+
<% end %><% if @build_update_action %> def update
|
95
|
+
<%= controller_magic_button_update_actions %>
|
96
|
+
|
97
|
+
if @<%= singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params<%= @auth ? ', ' + @auth : '' %>)<%= controller_update_params_tap_away_magic_buttons %>)
|
97
98
|
flash[:notice] = "Saved #{@<%= singular %>.<%= display_class %>}"
|
98
99
|
else
|
99
100
|
flash[:alert] = "<%= singular_name.titlecase %> could not be saved."
|
100
101
|
end
|
102
|
+
<% if @display_list_after_update %> load_all_<%= plural %><% end %>
|
101
103
|
respond_to do |format|
|
102
104
|
format.turbo_stream
|
103
105
|
format.html
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
|
-
<% if destroy_action %> def destroy
|
109
|
+
<% end %><% if destroy_action %> def destroy
|
108
110
|
begin
|
109
111
|
@<%=singular_name%>.destroy
|
110
112
|
rescue StandardError => e
|
@@ -115,10 +117,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
115
117
|
format.turbo_stream
|
116
118
|
format.html { redirect_to <%= path_helper_plural %> }
|
117
119
|
end
|
118
|
-
end
|
120
|
+
end
|
119
121
|
|
120
|
-
|
121
|
-
params.require(:<%=singular_name%>).permit( <%= @columns %> )
|
122
|
+
<% end %>def <%=singular_name%>_params
|
123
|
+
params.require(:<%=singular_name%>).permit( <%= @columns + @magic_buttons.collect(&:to_sym) %> )
|
122
124
|
end
|
123
125
|
|
124
126
|
def default_colspan
|
@@ -126,18 +128,12 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
126
128
|
end
|
127
129
|
|
128
130
|
def namespace
|
129
|
-
<% if @namespace %>
|
130
|
-
"<%= @namespace %>/"
|
131
|
-
<% else %>
|
132
|
-
""
|
133
|
-
<% end %>
|
131
|
+
<% if @namespace %>"<%= @namespace %>/" <% else %>""<% end %>
|
134
132
|
end
|
135
133
|
|
136
|
-
|
137
134
|
def common_scope
|
138
135
|
@nested_args
|
139
136
|
end
|
140
|
-
|
141
137
|
end
|
142
138
|
|
143
139
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
<\%= turbo_frame_tag "<%= singular %>__#{ <%= singular %>.id }" do %>
|
3
3
|
<div class='row' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
|
4
|
-
<\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %>} %>
|
4
|
+
<\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %><%= nest_assignments_operator(false, true) if @nestable %> } %>
|
5
5
|
</div>
|
6
6
|
<\% end %>
|
7
7
|
|
@@ -1,5 +1,13 @@
|
|
1
1
|
<\%= turbo_frame_tag "<%= plural %>-list" do %>
|
2
|
-
<div class="container-fluid "
|
2
|
+
<div class="container-fluid ">
|
3
|
+
<h4><%= plural.gsub("_", " ").upcase %></h4>
|
4
|
+
<div class="row">
|
5
|
+
<div class="col-md-12">
|
6
|
+
<% unless @no_create %><%= '<%= render partial: "' + ((@namespace+"/" if @namespace) || "") + plural + '/new_button", locals: {' + nested_assignments + '}' + '%\>'.gsub('\\',"") %><% end %>
|
7
|
+
</div>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
|
3
11
|
<div class="row">
|
4
12
|
<%= list_column_headings %>
|
5
13
|
<div class='col buttons-col'></div>
|
@@ -11,7 +19,7 @@
|
|
11
19
|
</div>
|
12
20
|
<\% end %>
|
13
21
|
<\% <%= plural %>.each do |<%= singular %>| %>
|
14
|
-
<\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular
|
22
|
+
<\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %><%= nested_assignments_with_leading_comma if @nestable %> } %>
|
15
23
|
<\% end %>
|
16
24
|
|
17
25
|
<%= @no_paginate ? "" : paginate %>
|
@@ -1,8 +1,24 @@
|
|
1
1
|
<%= all_line_fields %>
|
2
|
+
|
3
|
+
<% if @downnest_relationship %>
|
4
|
+
<div class="col">
|
5
|
+
<\%= render partial: "dashboard/<%= @downnest_relationship %>/list", locals: {
|
6
|
+
<%= @singular %>: <%= @singular %>,
|
7
|
+
<%= @downnest_relationship %>: <%= @singular %>.<%= @downnest_relationship %>} %>
|
8
|
+
</div>
|
9
|
+
<% end %>
|
10
|
+
|
2
11
|
<div class="col">
|
3
12
|
<% if destroy_action %>
|
4
|
-
<\%=
|
13
|
+
<\%= form_with url: <%= path_helper_singular %>(<%= path_helper_args %>), method: :delete do |f| %>
|
14
|
+
<\%= f.submit "Delete".html_safe, data: <%= delete_confirmation_syntax %>, class: "delete-<%= singular %>-button btn btn-primary " %>
|
15
|
+
<\% end %>
|
5
16
|
<% end %>
|
6
|
-
|
17
|
+
|
18
|
+
|
19
|
+
<%= magic_button_output %>
|
20
|
+
|
21
|
+
<% unless @no_edit %>
|
7
22
|
<\%= 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 " %>
|
23
|
+
<% end %>
|
8
24
|
</div>
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<\% if @<%= singular %>.errors.none? %>
|
2
2
|
<\%= turbo_stream.replace "<%= plural %>-list" do %>
|
3
|
-
<\%= render partial: "list", locals: {<%= plural %>: @<%= plural %>} %>
|
3
|
+
<\%= render partial: "list", locals: {<%= plural %>: @<%= plural %> <%= nest_assignments_operator(true, true) %>} %>
|
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" %>
|
8
|
+
<\%= render partial: "new_button", locals: {<%= nest_assignments_operator(true, false) %>} %>
|
9
9
|
<\% else %>
|
10
|
-
<\%= render partial: "new_form", locals: {<%= singular %>: @<%= singular %>} %>
|
10
|
+
<\%= render partial: "new_form", locals: {<%= singular %>: @<%= singular %> <%= nest_assignments_operator(true, true) %> } %>
|
11
11
|
<\% end %>
|
12
12
|
<\% end %>
|
13
13
|
<\%= turbo_stream.replace "flash_notices" do %>
|