hot-glue 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +17 -17
- data/README.md +30 -0
- data/config/database.yml +83 -8
- data/config/hot_glue.yml +3 -0
- data/db/schema.rb +3 -3
- data/lib/generators/hot_glue/install_generator.rb +2 -2
- data/lib/generators/hot_glue/layout/builder.rb +115 -0
- data/lib/generators/hot_glue/markup_templates/erb.rb +159 -178
- data/lib/generators/hot_glue/markup_templates/haml.rb +7 -2
- data/lib/generators/hot_glue/scaffold_generator.rb +98 -81
- data/lib/generators/hot_glue/templates/controller.rb.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_form.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_list.erb +9 -12
- data/lib/generators/hot_glue/templates/erb/_show.erb +7 -7
- data/lib/generators/hot_glue/templates/system_spec.rb.erb +37 -26
- data/lib/hotglue/version.rb +1 -1
- metadata +6 -24
- data/db/migrate/20210306212711_create_abcs.rb +0 -11
- data/db/migrate/20210306223300_create_defs.rb +0 -9
- data/db/migrate/20210306223305_create_ghis.rb +0 -9
- data/db/migrate/20210306223309_create_jkls.rb +0 -9
- data/db/migrate/20210306223701_devise_create_users.rb +0 -44
- data/db/migrate/20210306225506_create_xyzs.rb +0 -9
@@ -6,6 +6,8 @@ require_relative './markup_templates/erb'
|
|
6
6
|
require_relative './markup_templates/haml'
|
7
7
|
require_relative './markup_templates/slim'
|
8
8
|
|
9
|
+
require_relative './layout/builder'
|
10
|
+
|
9
11
|
module HotGlue
|
10
12
|
class Error < StandardError
|
11
13
|
end
|
@@ -56,26 +58,27 @@ module HotGlue
|
|
56
58
|
class_option :no_paginate, type: :boolean, default: false
|
57
59
|
class_option :big_edit, type: :boolean, default: false
|
58
60
|
class_option :show_only, type: :string, default: ""
|
59
|
-
|
61
|
+
|
62
|
+
class_option :stimulus_syntax, type: :boolean, default: nil # TODO: rename to ujs_syntax and default to false
|
63
|
+
|
60
64
|
class_option :downnest, type: :string, default: nil
|
61
|
-
class_option :nestable, type: :boolean, default: false
|
62
65
|
class_option :magic_buttons, type: :string, default: nil
|
63
66
|
class_option :display_list_after_update, type: :boolean, default: false
|
64
|
-
|
67
|
+
class_option :smart_layout, type: :boolean, default: false
|
65
68
|
class_option :markup, type: :string, default: nil # deprecated -- use in app config instead
|
66
|
-
class_option :layout, type: :string, default: nil #
|
69
|
+
class_option :layout, type: :string, default: nil # if used here it will override what is in the config
|
67
70
|
|
68
71
|
|
69
72
|
def initialize(*meta_args)
|
70
73
|
super
|
71
74
|
|
75
|
+
|
72
76
|
begin
|
73
77
|
@the_object = eval(class_name)
|
74
78
|
rescue StandardError => e
|
75
79
|
message = "*** Oops: It looks like there is no object for #{class_name}. Please define the object + database table first."
|
76
80
|
puts message
|
77
|
-
|
78
|
-
# raise(HotGlue::Error, message)
|
81
|
+
raise(HotGlue::Error, message)
|
79
82
|
end
|
80
83
|
|
81
84
|
if !options['spec_only'].nil? && !options['no_spec'].nil?
|
@@ -83,10 +86,13 @@ module HotGlue
|
|
83
86
|
end
|
84
87
|
|
85
88
|
if !options['exclude'].empty? && !options['include'].empty?
|
86
|
-
|
87
|
-
|
89
|
+
exit_message = "*** Oops: You seem to have specified both --include and --exclude. Please use one or the other. Aborting."
|
90
|
+
puts exit_message
|
91
|
+
|
92
|
+
raise(HotGlue::Error, exit_message)
|
88
93
|
end
|
89
94
|
|
95
|
+
|
90
96
|
if @stimulus_syntax.nil?
|
91
97
|
if Rails.version.split(".")[0].to_i >= 7
|
92
98
|
@stimulus_syntax = true
|
@@ -96,13 +102,14 @@ module HotGlue
|
|
96
102
|
end
|
97
103
|
|
98
104
|
if !options['markup'].nil?
|
99
|
-
|
100
|
-
|
105
|
+
message = "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`"
|
106
|
+
raise(HotGlue::Error, message)
|
107
|
+
|
101
108
|
end
|
102
109
|
|
103
110
|
if !options['markup'].nil?
|
104
|
-
|
105
|
-
|
111
|
+
message = "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`"
|
112
|
+
raise(HotGlue::Error, message)
|
106
113
|
end
|
107
114
|
|
108
115
|
yaml_from_config = YAML.load(File.read("config/hot_glue.yml"))
|
@@ -111,8 +118,8 @@ module HotGlue
|
|
111
118
|
if @markup == "erb"
|
112
119
|
@template_builder = HotGlue::ErbTemplate.new
|
113
120
|
elsif @markup == "slim"
|
114
|
-
|
115
|
-
|
121
|
+
message = "SLIM IS NOT IMPLEMENTED; please see https://github.com/jasonfb/hot-glue/issues/3"
|
122
|
+
raise(HotGlue::Error, message)
|
116
123
|
@template_builder = HotGlue::SlimTemplate.new
|
117
124
|
|
118
125
|
elsif @markup == "haml"
|
@@ -120,13 +127,16 @@ module HotGlue
|
|
120
127
|
end
|
121
128
|
|
122
129
|
|
123
|
-
|
130
|
+
if !options['layout']
|
131
|
+
@layout = yaml_from_config[:layout]
|
124
132
|
|
125
|
-
|
126
|
-
|
133
|
+
if !['hotglue', 'bootstrap'].include? @layout
|
134
|
+
raise "Invalid option #{@layout} in Hot glue config (config/hot_glue.yml). You must either use --layout= when generating or have a file config/hotglue.yml; specify layout as either 'hotglue' or 'bootstrap'"
|
135
|
+
end
|
136
|
+
else
|
137
|
+
@layout = options['layout']
|
127
138
|
end
|
128
139
|
|
129
|
-
|
130
140
|
args = meta_args[0]
|
131
141
|
@singular = args.first.tableize.singularize # should be in form hello_world
|
132
142
|
@plural = options['plural'] || @singular + "s" # supply to override; leave blank to use default
|
@@ -144,7 +154,8 @@ module HotGlue
|
|
144
154
|
|
145
155
|
if !options['include'].empty?
|
146
156
|
@include_fields = []
|
147
|
-
|
157
|
+
# semicolon to denote layout columns; commas separate fields
|
158
|
+
@include_fields += options['include'].gsub(":","").split(",").collect(&:to_sym)
|
148
159
|
end
|
149
160
|
|
150
161
|
|
@@ -168,10 +179,9 @@ module HotGlue
|
|
168
179
|
@no_list = options['no_list'] || false
|
169
180
|
|
170
181
|
@display_list_after_update = options['display_list_after_update'] || false
|
182
|
+
@smart_layout = options['smart_layout']
|
171
183
|
|
172
184
|
|
173
|
-
|
174
|
-
@col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col"
|
175
185
|
@container_name = @layout == "hotglue" ? "scaffold-container" : "container-fluid"
|
176
186
|
|
177
187
|
@downnest = options['downnest'] || false
|
@@ -211,7 +221,6 @@ module HotGlue
|
|
211
221
|
@build_update_action = !@no_edit || !@magic_buttons.empty?
|
212
222
|
# if the magic buttons are present, build the update action anyway
|
213
223
|
|
214
|
-
# @nestable = options['nestable'] || false
|
215
224
|
|
216
225
|
if @auth && ! @self_auth && @nested_args.none?
|
217
226
|
@object_owner_sym = @auth.gsub("current_", "").to_sym
|
@@ -227,17 +236,22 @@ module HotGlue
|
|
227
236
|
end
|
228
237
|
end
|
229
238
|
|
230
|
-
|
231
|
-
|
232
239
|
@reference_name = HotGlue.derrive_reference_name(singular_class)
|
233
240
|
|
234
241
|
identify_object_owner
|
235
242
|
setup_fields
|
236
243
|
|
244
|
+
builder = HotGlue::Layout::Builder.new({
|
245
|
+
include_setting: options['include'],
|
246
|
+
downnest_children: @downnest_children,
|
247
|
+
no_edit: @no_edit,
|
248
|
+
no_delete: @no_delete,
|
249
|
+
columns: @columns,
|
250
|
+
smart_layout: @smart_layout
|
251
|
+
})
|
252
|
+
@layout_object = builder.construct
|
237
253
|
|
238
|
-
if @nested_args.none? && File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
|
239
|
-
@menu_file_exists = true
|
240
|
-
end
|
254
|
+
@menu_file_exists = true if @nested_args.none? && File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
|
241
255
|
end
|
242
256
|
|
243
257
|
def identify_object_owner
|
@@ -256,17 +270,15 @@ module HotGlue
|
|
256
270
|
if @god
|
257
271
|
exit_message= "*** Oops: Gd mode could not find the association(#{@object_owner_sym}). Something is wrong."
|
258
272
|
else
|
259
|
-
@auth_check =
|
273
|
+
@auth_check = eval(@auth_identifier.titleize)
|
260
274
|
@nested_args.each do |arg|
|
261
|
-
|
262
|
-
if !@auth_check.method("#{arg}s")
|
275
|
+
if ! @auth_check.reflect_on_association("#{arg}s".to_sym)
|
263
276
|
exit_message = "*** Oops: your nesting chain does not have a association for #{arg}s on #{@auth_check} something is wrong."
|
264
277
|
end
|
265
278
|
end
|
266
279
|
end
|
267
280
|
puts exit_message
|
268
|
-
|
269
|
-
|
281
|
+
raise(HotGlue::Error, exit_message)
|
270
282
|
end
|
271
283
|
end
|
272
284
|
end
|
@@ -307,26 +319,20 @@ module HotGlue
|
|
307
319
|
begin
|
308
320
|
eval(assoc.class_name)
|
309
321
|
rescue NameError => e
|
310
|
-
exit_message = "*** Oops: The model #{singular_class} is missing an association for
|
322
|
+
exit_message = "*** Oops: The model #{singular_class} is missing an association for :#{assoc_name} or the model #{assoc_name.titlecase} doesn't exist. TODO: Please implement a model for #{assoc_name.titlecase}; your model #{singular_class.titlecase} should belong_to :#{assoc_name}. To make a controller that can read all records, specify with --god."
|
311
323
|
puts exit_message
|
312
|
-
|
313
|
-
# raise(HotGlue::Error, exit_message)
|
314
|
-
|
324
|
+
raise(HotGlue::Error, exit_message)
|
315
325
|
end
|
316
326
|
|
317
327
|
|
318
328
|
if assoc.nil?
|
319
329
|
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
320
330
|
puts exit_message
|
321
|
-
|
322
|
-
# raise(HotGlue::Error,exit_message)
|
331
|
+
raise(HotGlue::Error,exit_message)
|
323
332
|
end
|
324
333
|
|
325
334
|
assoc_class = eval(assoc.class_name)
|
326
|
-
|
327
335
|
name_list = [:name, :to_label, :full_name, :display_name, :email]
|
328
|
-
|
329
|
-
|
330
336
|
if name_list.collect{ |field|
|
331
337
|
assoc_class.column_names.include?(field.to_s) || assoc_class.instance_methods.include?(field)
|
332
338
|
}.any?
|
@@ -340,7 +346,6 @@ module HotGlue
|
|
340
346
|
end
|
341
347
|
end
|
342
348
|
|
343
|
-
#
|
344
349
|
def formats
|
345
350
|
[format]
|
346
351
|
end
|
@@ -365,17 +370,21 @@ module HotGlue
|
|
365
370
|
|
366
371
|
unless @no_specs
|
367
372
|
dest_file = File.join("#{'spec/dummy/' if Rails.env.test?}spec/system#{namespace_with_dash}", "#{plural}_behavior_spec.rb")
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
if
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
373
|
+
if File.exists?(dest_file)
|
374
|
+
existing_file = File.open(dest_file)
|
375
|
+
existing_content = existing_file.read
|
376
|
+
if existing_content =~ /\#HOTGLUE-SAVESTART/
|
377
|
+
if existing_content !~ /\#HOTGLUE-END/
|
378
|
+
raise "Your file at #{dest_file} contains a #HOTGLUE-SAVESTART marker without #HOTGLUE-END"
|
379
|
+
end
|
380
|
+
@existing_content = existing_content[(existing_content =~ /\#HOTGLUE-SAVESTART/) .. (existing_content =~ /\#HOTGLUE-END/)-1]
|
381
|
+
@existing_content << "#HOTGLUE-END"
|
376
382
|
|
383
|
+
end
|
384
|
+
existing_file.rewind
|
385
|
+
else
|
386
|
+
@existing_content = " #HOTGLUE-SAVESTART\n #HOTGLUE-END"
|
377
387
|
end
|
378
|
-
existing_file.rewind
|
379
388
|
|
380
389
|
template "system_spec.rb.erb", dest_file
|
381
390
|
end
|
@@ -386,24 +395,26 @@ module HotGlue
|
|
386
395
|
def list_column_headings
|
387
396
|
if @nested_args.any?
|
388
397
|
column_width = each_col * @columns.count
|
389
|
-
|
390
|
-
"<div class='#{@col_identifier}' style='flex-basis: #{column_width}%'>"
|
391
398
|
else
|
392
|
-
|
393
|
-
column_width: each_col,
|
394
|
-
columns: @columns,
|
395
|
-
col_identifier: @col_identifier
|
396
|
-
)
|
399
|
+
column_width = 0
|
397
400
|
end
|
398
401
|
|
402
|
+
if !@smart_layout
|
403
|
+
col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col-md-1"
|
404
|
+
else
|
405
|
+
col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col-md-2"
|
406
|
+
end
|
399
407
|
|
408
|
+
@template_builder.list_column_headings(
|
409
|
+
columns: @layout_object[:columns][:container],
|
410
|
+
col_identifier: col_identifier,
|
411
|
+
layout: @layout,
|
412
|
+
column_width: column_width
|
413
|
+
)
|
400
414
|
end
|
401
415
|
|
402
416
|
def columns_spec_with_sample_data
|
403
417
|
@columns.map { |c|
|
404
|
-
if eval("#{singular_class}.columns_hash['#{c}']").nil?
|
405
|
-
byebug
|
406
|
-
end
|
407
418
|
type = eval("#{singular_class}.columns_hash['#{c}']").type
|
408
419
|
random_data = case type
|
409
420
|
when :integer
|
@@ -608,21 +619,6 @@ module HotGlue
|
|
608
619
|
magic_buttons: @magic_buttons
|
609
620
|
)
|
610
621
|
end
|
611
|
-
# def erb_replace_ampersands!(filename = nil)
|
612
|
-
#
|
613
|
-
# return if filename.nil?
|
614
|
-
# file = File.open(filename, "r")
|
615
|
-
# contents = file.read
|
616
|
-
# file.close
|
617
|
-
#
|
618
|
-
# file = File.open(filename, "w")
|
619
|
-
# file.write( contents.gsub('\%', '%'))
|
620
|
-
# file.close
|
621
|
-
# end
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
622
|
|
627
623
|
def copy_view_files
|
628
624
|
return if @specs_only
|
@@ -674,20 +670,35 @@ module HotGlue
|
|
674
670
|
end
|
675
671
|
|
676
672
|
def all_views
|
677
|
-
res = %w(index
|
673
|
+
res = %w(index _line _list _show _errors)
|
678
674
|
|
679
675
|
unless @no_create
|
680
676
|
res += %w(new _new_form _new_button)
|
681
677
|
end
|
682
678
|
|
679
|
+
unless @no_edit
|
680
|
+
res << 'edit'
|
681
|
+
res << '_form'
|
682
|
+
end
|
683
|
+
|
683
684
|
res
|
684
685
|
end
|
685
686
|
|
686
687
|
def turbo_stream_views
|
687
|
-
res =
|
688
|
+
res = []
|
688
689
|
unless @no_delete
|
689
690
|
res << 'destroy'
|
690
691
|
end
|
692
|
+
|
693
|
+
unless @no_create
|
694
|
+
res << 'create'
|
695
|
+
end
|
696
|
+
|
697
|
+
unless @no_edit
|
698
|
+
res << 'edit'
|
699
|
+
res << 'update'
|
700
|
+
end
|
701
|
+
|
691
702
|
res
|
692
703
|
end
|
693
704
|
|
@@ -705,13 +716,19 @@ module HotGlue
|
|
705
716
|
end
|
706
717
|
|
707
718
|
def all_form_fields
|
719
|
+
# TODO: DRY THIS
|
720
|
+
if !@smart_layout
|
721
|
+
col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col-md-1"
|
722
|
+
else
|
723
|
+
col_identifier = @layout == "hotglue" ? "scaffold-cell" : "col-md-2"
|
724
|
+
end
|
708
725
|
|
709
726
|
@template_builder.all_form_fields(
|
710
|
-
columns: @columns,
|
727
|
+
columns: @layout_object[:columns][:container],
|
711
728
|
show_only: @show_only,
|
712
729
|
singular_class: singular_class,
|
713
730
|
singular: singular,
|
714
|
-
col_identifier:
|
731
|
+
col_identifier: col_identifier
|
715
732
|
)
|
716
733
|
end
|
717
734
|
|
@@ -743,7 +760,7 @@ module HotGlue
|
|
743
760
|
|
744
761
|
@template_builder.all_line_fields(
|
745
762
|
perc_width: column_width,
|
746
|
-
columns:
|
763
|
+
columns: @layout_object[:columns][:container],
|
747
764
|
show_only: @show_only,
|
748
765
|
singular_class: singular_class,
|
749
766
|
singular: singular,
|
@@ -38,7 +38,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
38
38
|
|
39
39
|
<% if any_nested? %><% nest_chain = [@nested_args[0]]; this_scope = @nested_args[0] + 's'; %> <% @nested_args[1..-1].each { |arg|
|
40
40
|
this_scope = "#{nest_chain.last}.#{arg}s"
|
41
|
-
nest_chain <<
|
41
|
+
nest_chain << arg
|
42
42
|
%>
|
43
43
|
def <%= arg %>
|
44
44
|
@<%= arg %> ||= <%= this_scope %>.find(params[:<%= arg %>_id])
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="row">
|
2
2
|
<%= all_form_fields %>
|
3
3
|
|
4
|
-
<div class="
|
4
|
+
<div class="<%= @layout == "hotglue" ? 'scaffold-cell' : 'col-md-2' %>">
|
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>
|
@@ -2,31 +2,30 @@
|
|
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) || "") + plural + '/new_button", locals: {' + nested_assignments + '}' + '%\>'.gsub('\\',"")
|
5
|
+
<% unless @no_create %><%= '<%= render partial: "' + ((@namespace+"/" if @namespace) || "") + plural + '/new_button", locals: {' + nested_assignments + '}' + '%\>'.gsub('\\',"") %><br /><% end %>
|
6
6
|
|
7
7
|
<% unless @no_list %>
|
8
|
-
<div class="row scaffold-row">
|
8
|
+
<div class="row scaffold-heading-row">
|
9
9
|
<%= list_column_headings %>
|
10
10
|
<% if @downnest_children.any? %>
|
11
11
|
<% each_downnest_width = @downnest_children.count == 1 ? 40 : (60/@downnest_children.count).floor %>
|
12
|
-
<% downnest_column_style = @layout == "hotglue" ? 'style="flex-basis: ' + each_downnest_width + '%;' : "" %>
|
12
|
+
<% downnest_column_style = @layout == "hotglue" ? 'style="flex-basis: ' + each_downnest_width.to_s + '%;' : "" %>
|
13
13
|
|
14
|
-
<% @downnest_children.
|
15
|
-
<div class="
|
16
|
-
<
|
14
|
+
<% @downnest_children.each_with_index do |downnest,i| %>
|
15
|
+
<div class=" scaffold-col-heading<%= " col-sm-#{ @layout_object[:portals][downnest][:size] }" if @layout=="bootstrap" %>" <%= downnest_column_style %>>
|
16
|
+
<strong>
|
17
17
|
<%= downnest.titleize %>
|
18
|
-
</
|
18
|
+
</strong>
|
19
19
|
</div>
|
20
20
|
<% end %>
|
21
21
|
<% end %>
|
22
22
|
|
23
23
|
<% button_column_style = @layout == "hotglue" ? 'style="flex-basis: 150px' : "" %>
|
24
24
|
|
25
|
-
<div class='
|
25
|
+
<div class=' scaffold-col-heading scaffold-col-heading-buttons<%= ' col-md-2' if @layout=="bootstrap" %>' <%= button_column_style %>>
|
26
26
|
|
27
27
|
</div>
|
28
28
|
</div>
|
29
|
-
|
30
29
|
<\% if <%= plural %>.empty? %>
|
31
30
|
<div>
|
32
31
|
None
|
@@ -36,8 +35,6 @@
|
|
36
35
|
<\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %><%= nested_assignments_with_leading_comma if @nestable %><%= ", nested_for: nested_for" if @nestable %> } %>
|
37
36
|
<\% end %>
|
38
37
|
<%= @no_paginate ? "" : paginate %>
|
39
|
-
|
40
|
-
</div>
|
41
|
-
<% end %>
|
38
|
+
<% end %>
|
42
39
|
</div>
|
43
40
|
<\% end %>
|
@@ -3,12 +3,13 @@
|
|
3
3
|
<% if @downnest_children.any? %>
|
4
4
|
<% each_downnest_width = @downnest_children.count == 1 ? 33 : (53/@downnest_children.count).floor %>
|
5
5
|
|
6
|
-
<% @downnest_children.
|
6
|
+
<% @downnest_children.each_with_index do |downnest,i| %>
|
7
7
|
|
8
8
|
<% downnest_object = eval("#{singular_class}.reflect_on_association(:#{downnest})") %>
|
9
|
-
<%
|
10
|
-
<%
|
11
|
-
|
9
|
+
<% downnest_class = downnest_object.class_name %>
|
10
|
+
<% downnest_object_name = eval("#{downnest_class}.table_name") %>
|
11
|
+
<% downnest_style = @layout == "hotglue" ? 'style="flex-basis: ' + each_downnest_width.to_s + '%"' : "" %>
|
12
|
+
<div class="<%= " col-md-#{@layout_object[:portals][downnest][:size]}" if @layout == "bootstrap" %> scaffold-downnest" <%= downnest_style %> >
|
12
13
|
<\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {
|
13
14
|
nested_for: "<% if @nested_args.any? %>#{nested_for + "__" if nested_for}<% end %><%= @singular %>-#{<%= @singular %>.id}",
|
14
15
|
<%= @singular %>: <%= @singular %><%= nest_assignments_operator(false, true) %>,
|
@@ -19,15 +20,14 @@
|
|
19
20
|
|
20
21
|
<% button_style = @layout == "hotglue" ? 'style="flex-basis: ' + (100 - (column_width * @columns.count)).floor.to_s + '%;"' : "" %>
|
21
22
|
<div class="<%= @col_identifier %> scaffold-line-buttons <%= ' col-md-2' if @layout == "bootstrap" %>" <%= button_style %>>
|
23
|
+
<%= magic_button_output %>
|
24
|
+
|
22
25
|
<% if destroy_action %>
|
23
26
|
<\%= form_with url: <%= path_helper_singular %>(<%= path_helper_args %>), html: {style: "display: inline-block;"}, method: :delete do |f| %>
|
24
27
|
<\%= f.submit "Delete".html_safe, data: <%= delete_confirmation_syntax %>, class: "delete-<%= singular %>-button btn btn-primary btn-sm" %>
|
25
28
|
<\% end %>
|
26
29
|
<% end %>
|
27
30
|
|
28
|
-
|
29
|
-
<%= magic_button_output %>
|
30
|
-
|
31
31
|
<% unless @no_edit %>
|
32
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" %>
|
33
33
|
<% end %>
|
@@ -4,18 +4,18 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
4
4
|
include HotGlue::ControllerHelper
|
5
5
|
<%= @existing_content %>
|
6
6
|
<% unless @god %>let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
else
|
7
|
+
<%= (@columns - @show_only).map { |col|
|
8
|
+
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
9
|
+
case type
|
10
|
+
when :integer
|
11
|
+
if col.to_s.ends_with?("_id")
|
12
|
+
assoc = "#{col.to_s.gsub('_id','')}"
|
13
|
+
"let!(:#{assoc}1) {create(:#{assoc})}"
|
16
14
|
end
|
17
|
-
|
18
|
-
|
15
|
+
else
|
16
|
+
end
|
17
|
+
}.compact.join("\n")
|
18
|
+
%>
|
19
19
|
<% item1_addOns = ""
|
20
20
|
if (eval(@singular_class).instance_methods.include?(display_class.to_s))
|
21
21
|
item1_addOns << "#{display_class}: FFaker::Name.name"
|
@@ -32,7 +32,7 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
32
32
|
when :float
|
33
33
|
"#{col}: rand(1)*10000"
|
34
34
|
when :boolean
|
35
|
-
"#{col}: !!rand(2).
|
35
|
+
"#{col}: !!rand(2).floor"
|
36
36
|
when :time
|
37
37
|
"#{col}: Time.current + rand(5000).seconds"
|
38
38
|
when :date
|
@@ -41,7 +41,7 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
41
41
|
"#{col}: DateTime.current + rand(1000).seconds"
|
42
42
|
when :integer
|
43
43
|
if col.to_s.ends_with?("_id")
|
44
|
-
#
|
44
|
+
"#{col.to_s.gsub('_id','')}: #{col.to_s.gsub('_id','')}1"
|
45
45
|
else
|
46
46
|
"#{col}: rand(100)"
|
47
47
|
end
|
@@ -82,13 +82,20 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
82
82
|
expect(page).to have_selector(:xpath, './/h3[contains(., "New <%= singular.titlecase %>")]')
|
83
83
|
|
84
84
|
<%=
|
85
|
-
@columns.map { |col|
|
85
|
+
(@columns - @show_only).map { |col|
|
86
86
|
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
87
87
|
case type
|
88
|
-
when :
|
88
|
+
when :date
|
89
|
+
" " + "new_#{col} = Date.current + (rand(100).days) \n" +
|
90
|
+
' ' + "find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
91
|
+
when :time
|
89
92
|
# " " + "new_#{col} = DateTime.current + (rand(100).days) \n" +
|
90
93
|
# ' ' + "find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
91
94
|
|
95
|
+
when :datetime
|
96
|
+
" " + "new_#{col} = DateTime.current + (rand(100).days) \n" +
|
97
|
+
' ' + "find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
98
|
+
|
92
99
|
when :integer
|
93
100
|
|
94
101
|
if col.to_s.ends_with?("_id")
|
@@ -118,6 +125,9 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
118
125
|
" " + "new_#{col} = 'new_test-email@nowhere.com' \n" +
|
119
126
|
" find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
120
127
|
end
|
128
|
+
when :text
|
129
|
+
" " + "new_#{col} = FFaker::Lorem.paragraphs(1).join("") \n" +
|
130
|
+
" find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
|
121
131
|
end
|
122
132
|
|
123
133
|
}.join("\n")
|
@@ -125,8 +135,9 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
125
135
|
%>
|
126
136
|
click_button "Save"
|
127
137
|
expect(page).to have_content("Successfully created")
|
128
|
-
<%=
|
129
|
-
|
138
|
+
<%=" " +
|
139
|
+
|
140
|
+
(@columns - @show_only).map { |col|
|
130
141
|
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
131
142
|
|
132
143
|
case type
|
@@ -147,7 +158,6 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
147
158
|
|
148
159
|
}.compact.join("\n ")
|
149
160
|
%>
|
150
|
-
|
151
161
|
end
|
152
162
|
end<% end %>
|
153
163
|
|
@@ -157,9 +167,9 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
157
167
|
visit <%= path_helper_plural %>
|
158
168
|
find("a.edit-<%= singular %>-button[href='/<%= namespace_with_slash %><%= plural %>/#{<%= singular %>1.id}/edit']").click
|
159
169
|
|
160
|
-
expect(page).to have_content("Editing #{<%= singular %>1.<%= @display_class
|
170
|
+
expect(page).to have_content("Editing #{<%= singular %>1.<%= @display_class %>.squish || "(no name)"}")
|
161
171
|
<%=
|
162
|
-
@columns.map { |col|
|
172
|
+
(@columns - @show_only).map { |col|
|
163
173
|
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
164
174
|
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
165
175
|
sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
|
@@ -201,11 +211,15 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
201
211
|
" new_#{col} = rand(1)*5000 \n" +
|
202
212
|
" find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s })"
|
203
213
|
when :date
|
204
|
-
"
|
205
|
-
"
|
214
|
+
" new_#{col} = Date.current + rand(100).days \n" +
|
215
|
+
" find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s })"
|
206
216
|
when :time
|
207
217
|
" new_#{col} = Time.current + rand(144).hours \n" +
|
208
218
|
" find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s })"
|
219
|
+
when :datetime
|
220
|
+
" new_#{col} = DateTime.current + rand(1000).minutes \n" +
|
221
|
+
" find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s })"
|
222
|
+
|
209
223
|
when :enum
|
210
224
|
" list_of_#{col.to_s} = #{singular_class}.defined_enums['#{col.to_s}'].keys \n" +
|
211
225
|
" " + "new_#{col.to_s} = list_of_#{col.to_s}[rand(list_of_#{col.to_s}.length)].to_s \n" +
|
@@ -221,7 +235,7 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
221
235
|
click_button "Save"
|
222
236
|
within("turbo-frame#<%= singular %>__#{<%= singular %>1.id} ") do
|
223
237
|
<%=
|
224
|
-
@columns.map { |col|
|
238
|
+
(@columns - @show_only).map { |col|
|
225
239
|
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
226
240
|
case type
|
227
241
|
when :datetime
|
@@ -239,7 +253,6 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
239
253
|
end
|
240
254
|
}.compact.join("\n")
|
241
255
|
%>
|
242
|
-
|
243
256
|
end
|
244
257
|
end
|
245
258
|
end <% end %>
|
@@ -250,8 +263,6 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
|
|
250
263
|
accept_alert do
|
251
264
|
find("form[action='<%= namespace_with_dash %>/<%= plural %>/#{<%= singular %>1.id}'] > input.delete-<%= singular %>-button").click
|
252
265
|
end
|
253
|
-
# find("form[action='<%= namespace_with_dash %>/<%= plural %>/#{<%= singular %>1.id}'] > input.delete-<%= singular %>-button").click
|
254
|
-
|
255
266
|
expect(page).to_not have_content(<%= singular %>1.<%= @display_class %>)
|
256
267
|
expect(<%= singular_class %>.where(id: <%= singular %>1.id).count).to eq(0)
|
257
268
|
end
|
data/lib/hotglue/version.rb
CHANGED