hot-glue 0.5.12 → 0.5.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +74 -0
  3. data/.github/workflows/test.yml +33 -14
  4. data/.gitignore +0 -2
  5. data/.ruby-version +1 -1
  6. data/Gemfile +4 -2
  7. data/Gemfile.lock +280 -0
  8. data/README.md +73 -1
  9. data/lib/generators/hot_glue/direct_upload_install_generator.rb +1 -1
  10. data/lib/generators/hot_glue/dropzone_install_generator.rb +1 -1
  11. data/lib/generators/hot_glue/field_factory.rb +4 -1
  12. data/lib/generators/hot_glue/fields/association_field.rb +73 -6
  13. data/lib/generators/hot_glue/fields/attachment_field.rb +7 -3
  14. data/lib/generators/hot_glue/fields/boolean_field.rb +21 -0
  15. data/lib/generators/hot_glue/fields/date_field.rb +13 -0
  16. data/lib/generators/hot_glue/fields/date_time_field.rb +14 -2
  17. data/lib/generators/hot_glue/fields/enum_field.rb +40 -7
  18. data/lib/generators/hot_glue/fields/field.rb +44 -4
  19. data/lib/generators/hot_glue/fields/float_field.rb +9 -0
  20. data/lib/generators/hot_glue/fields/integer_field.rb +5 -1
  21. data/lib/generators/hot_glue/fields/string_field.rb +17 -0
  22. data/lib/generators/hot_glue/fields/text_field.rb +17 -0
  23. data/lib/generators/hot_glue/fields/time_field.rb +20 -0
  24. data/lib/generators/hot_glue/fields/uuid_field.rb +2 -3
  25. data/lib/generators/hot_glue/flash_notices_install_generator.rb +20 -0
  26. data/lib/generators/hot_glue/install_generator.rb +16 -15
  27. data/lib/generators/hot_glue/markup_templates/erb.rb +14 -279
  28. data/lib/generators/hot_glue/scaffold_generator.rb +27 -9
  29. data/lib/generators/hot_glue/templates/controller.rb.erb +5 -4
  30. data/lib/generators/hot_glue/templates/erb/_edit.erb +12 -0
  31. data/lib/generators/hot_glue/templates/erb/_flash_notices.erb +12 -8
  32. data/lib/generators/hot_glue/templates/erb/_show.erb +1 -1
  33. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +3 -4
  34. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +7 -1
  35. data/lib/generators/hot_glue/templates/erb/edit.erb +1 -12
  36. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +3 -6
  37. data/lib/generators/hot_glue/templates/system_spec.rb.erb +1 -1
  38. data/lib/hot-glue.rb +4 -1
  39. data/lib/hotglue/version.rb +1 -1
  40. data/script/test +9 -14
  41. metadata +7 -19
  42. data/lib/generators/hot_glue/templates/erb/_errors.erb +0 -11
  43. data/lib/generators/hot_glue/templates/haml/_errors.haml +0 -6
  44. data/lib/generators/hot_glue/templates/haml/_flash_notices.haml +0 -8
  45. data/lib/generators/hot_glue/templates/haml/_form.haml +0 -5
  46. data/lib/generators/hot_glue/templates/haml/_line.haml +0 -6
  47. data/lib/generators/hot_glue/templates/haml/_list.haml +0 -15
  48. data/lib/generators/hot_glue/templates/haml/_new_button.haml +0 -2
  49. data/lib/generators/hot_glue/templates/haml/_new_form.haml +0 -7
  50. data/lib/generators/hot_glue/templates/haml/_show.haml +0 -7
  51. data/lib/generators/hot_glue/templates/haml/create.turbo_stream.haml +0 -14
  52. data/lib/generators/hot_glue/templates/haml/destroy.turbo_stream.haml +0 -2
  53. data/lib/generators/hot_glue/templates/haml/edit.haml +0 -19
  54. data/lib/generators/hot_glue/templates/haml/edit.turbo_stream.haml +0 -4
  55. data/lib/generators/hot_glue/templates/haml/index.haml +0 -8
  56. data/lib/generators/hot_glue/templates/haml/new.haml +0 -1
  57. data/lib/generators/hot_glue/templates/haml/update.turbo_stream.haml +0 -9
@@ -16,7 +16,7 @@ module HotGlue
16
16
  small_buttons: , show_only: ,
17
17
  ownership_field: , form_labels_position: ,
18
18
  inline_list_labels: ,
19
- form_placeholder_labels:, hawk_keys:,
19
+ form_placeholder_labels:, hawk_keys: ,
20
20
  update_show_only:, alt_lookups: , attachments: , columns_map: )
21
21
 
22
22
  @singular = singular
@@ -81,54 +81,16 @@ module HotGlue
81
81
  result = columns.map{ |column|
82
82
  " <div class='#{column_classes} cell--#{singular}--#{column.join("-")}' >" +
83
83
  column.map { |col|
84
- if attachments.keys.include?(col)
85
-
86
- field_result = columns_map[col].form_field_output
87
- field_error_name = columns_map[col].field_error_name
88
- else
89
-
90
- type = eval("#{singular_class}.columns_hash['#{col}']").type
91
- limit = eval("#{singular_class}.columns_hash['#{col}']").limit
92
- sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
93
-
94
- field_result =
95
- if show_only.include?(col.to_sym)
96
- show_only_result(type: type, col: col, singular: singular)
97
- else
98
- case type
99
- when :integer
100
- integer_result(col)
101
- when :uuid
102
- association_result(col)
103
- when :string
104
- string_result(col, sql_type, limit)
105
- when :text
106
- text_result(col, sql_type, limit)
107
- when :float
108
- field_output(col, nil, 5, column_classes)
109
- when :datetime
110
- "<%= datetime_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
111
- when :date
112
- "<%= date_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
113
- when :time
114
- "<%= time_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
115
- when :boolean
116
- boolean_result(col)
117
- when :enum
118
- enum_result(col)
119
- end
120
- end
121
-
122
- if (type == :integer) && col.to_s.ends_with?("_id")
123
- field_error_name = col.to_s.gsub("_id","")
124
- else
125
- field_error_name = col
126
- end
84
+ field_result = show_only.include?(col.to_sym) ?
85
+ columns_map[col].form_show_only_output :
86
+ columns_map[col].form_field_output
87
+
88
+ field_error_name = columns_map[col].field_error_name
127
89
 
128
- end
129
90
  the_label = "\n<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
130
91
  show_only_open = ""
131
92
  show_only_close = ""
93
+
132
94
  if update_show_only.include?(col)
133
95
  show_only_open = "<% if action_name == 'edit' %>" +
134
96
  show_only_result(type: type, col: col, singular: singular) + "<% else %>"
@@ -137,7 +99,7 @@ module HotGlue
137
99
 
138
100
  add_spaces_each_line( "\n <span class='<%= \"alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{'style="display: inherit;"'} >\n" +
139
101
  add_spaces_each_line( (form_labels_position == 'before' ? the_label : "") +
140
- show_only_open + field_result + show_only_close +
102
+ show_only_open + field_result + show_only_close +
141
103
  (form_labels_position == 'after' ? the_label : "") , 4) +
142
104
  "\n </span>\n <br />", 2)
143
105
 
@@ -146,128 +108,6 @@ module HotGlue
146
108
  return result
147
109
  end
148
110
 
149
-
150
- def show_only_result(type:, col: , singular: )
151
- if type == :uuid || (type == :integer && col.ends_with?("_id"))
152
- association_read_only_result(col)
153
- else
154
- "<%= #{singular}.#{col} %>"
155
- end
156
- end
157
-
158
- def integer_result(col)
159
- # look for a belongs_to on this object
160
- if col.to_s.ends_with?("_id")
161
- association_result(col)
162
- else
163
- " <%= f.text_field :#{col}, value: #{@singular}.#{col}, autocomplete: 'off', size: 4, class: 'form-control', type: 'number'" + (@form_placeholder_labels ? ", placeholder: '#{col.to_s.humanize}'" : "") + " %>\n " + "\n"
164
- end
165
- end
166
-
167
- def association_read_only_result(col)
168
- assoc_name = col.to_s.gsub("_id","")
169
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
170
- if assoc.nil?
171
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
172
- exit
173
- end
174
-
175
- is_owner = col == ownership_field
176
- assoc_class_name = assoc.class_name.to_s
177
- display_column = HotGlue.derrive_reference_name(assoc_class_name)
178
-
179
- if @hawk_keys[assoc.foreign_key.to_sym]
180
- hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
181
- hawked_association = hawk_definition.join(".")
182
- else
183
- hawked_association = "#{assoc.class_name}.all"
184
- end
185
- "<%= #{@singular}.#{assoc_name}.#{display_column} %>"
186
- end
187
-
188
- def association_result(col)
189
- assoc_name = col.to_s.gsub("_id","")
190
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
191
-
192
-
193
- if @alt_lookups.keys.include?(col.to_s)
194
- alt = @alt_lookups[col.to_s][:lookup_as]
195
- "<%= f.text_field :__lookup_#{alt}, value: @#{singular}.#{assoc_name}.try(:#{alt}), placeholder: \"search by #{alt}\" %>"
196
- else
197
- if assoc.nil?
198
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
199
- exit
200
- end
201
-
202
- is_owner = col == ownership_field
203
- assoc_class_name = assoc.class_name.to_s
204
- display_column = HotGlue.derrive_reference_name(assoc_class_name)
205
- if @hawk_keys[assoc.foreign_key.to_sym]
206
- hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
207
- hawked_association = hawk_definition[:bind_to].join(".")
208
- else
209
- hawked_association = "#{assoc.class_name}.all"
210
- end
211
-
212
- (is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
213
- " <%= f.collection_select(:#{col}, #{hawked_association}, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
214
- (is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
215
- (is_owner ? "\n<% end %>" : "")
216
- end
217
- end
218
-
219
- def string_result(col, sql_type, limit)
220
- if sql_type == "varchar" || sql_type == "character varying"
221
- field_output(col, nil, limit || 40, col_identifier)
222
- else
223
- text_area_output(col, 65536, col_identifier)
224
- end
225
- end
226
-
227
-
228
- def text_result(col, sql_type, limit)
229
- if sql_type == "varchar"
230
- field_output(col, nil, limit, col_identifier)
231
- else
232
- text_area_output(col, 65536, col_identifier)
233
- end
234
- end
235
-
236
- def field_output(col, type = nil, width, col_identifier )
237
- " <%= f.text_field :#{col}, value: #{@singular}.#{col}, autocomplete: 'off', size: #{width}, class: 'form-control', type: '#{type}'" + (@form_placeholder_labels ? ", placeholder: '#{col.to_s.humanize}'" : "") + " %>\n " + "\n"
238
- end
239
-
240
- def text_area_output(col, field_length, col_identifier )
241
- lines = field_length % 40
242
- if lines > 5
243
- lines = 5
244
- end
245
-
246
- "<%= f.text_area :#{col}, class: 'form-control', autocomplete: 'off', cols: 40, rows: '#{lines}'" + ( @form_placeholder_labels ? ", placeholder: '#{col.to_s.humanize}'" : "") + " %>"
247
- end
248
-
249
- def boolean_result(col)
250
- (form_labels_position == 'before' ? " <br />" : "") +
251
- " <%= f.radio_button(:#{col}, '0', checked: #{singular}.#{col} ? '' : 'checked') %>\n" +
252
- " <%= f.label(:#{col}, value: 'No', for: '#{singular}_#{col}_0') %>\n" +
253
- " <%= f.radio_button(:#{col}, '1', checked: #{singular}.#{col} ? 'checked' : '') %>\n" +
254
- " <%= f.label(:#{col}, value: 'Yes', for: '#{singular}_#{col}_1') %>\n" +
255
- (form_labels_position == 'after' ? " <br />" : "")
256
-
257
- end
258
-
259
- def enum_result(col)
260
- enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
261
-
262
- if eval("defined? #{singular_class}.#{enum_type}_labels") == "method"
263
- enum_definer = "#{singular_class}.#{enum_type}_labels"
264
- else
265
- enum_definer = "#{singular_class}.defined_enums['#{enum_type}']"
266
- end
267
-
268
- "<%= f.collection_select(:#{col}, enum_to_collection_select(#{enum_definer}), :key, :value, {selected: @#{singular}.#{col} }, class: 'form-control') %>"
269
- end
270
-
271
111
  ################################################################
272
112
 
273
113
  def paginate(*args)
@@ -277,10 +117,9 @@ module HotGlue
277
117
  end
278
118
 
279
119
 
280
-
281
-
282
120
  ################################################################
283
-
121
+ # THE SHOW ACTION
122
+ ################################################################
284
123
 
285
124
  def all_line_fields(layout_strategy:,
286
125
  layout_object: ,
@@ -304,115 +143,11 @@ module HotGlue
304
143
  if eval("#{singular_class}.columns_hash['#{col}']").nil? && !attachments.keys.include?(col)
305
144
  raise "Can't find column '#{col}' on #{singular_class}, are you sure that is the column name?"
306
145
  end
146
+ field_output = columns_map[col].line_field_output
147
+
148
+ label = "<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
307
149
 
308
- if attachments.keys.include?(col)
309
- this_attachment = attachments[col]
310
- thumbnail = this_attachment[:thumbnail]
311
-
312
- field_output = (this_attachment[:thumbnail] ? "<%= #{singular}.#{col}.attached? ? image_tag(#{singular}.#{col}.variant(:#{thumbnail})) : '' %>" : "")
313
-
314
- else
315
- type = eval("#{singular_class}.columns_hash['#{col}']").type
316
- limit = eval("#{singular_class}.columns_hash['#{col}']").limit
317
- sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
318
-
319
- field_output =
320
- case type
321
- when :integer
322
- # look for a belongs_to on this object
323
- if col.ends_with?("_id")
324
- assoc_name = col.to_s.gsub("_id","")
325
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
326
-
327
- if assoc.nil?
328
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
329
- puts exit_message
330
- exit
331
- # raise(HotGlue::Error,exit_message)
332
- end
333
- assoc_class_name = assoc.class_name
334
-
335
- display_column = HotGlue.derrive_reference_name(assoc_class_name)
336
- "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
337
-
338
- else
339
- "<%= #{singular}.#{col}%>"
340
- end
341
-
342
- when :uuid
343
- assoc_name = col.to_s.gsub("_id","")
344
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
345
-
346
- if assoc.nil?
347
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
348
- puts exit_message
349
- exit
350
- # raise(HotGlue::Error,exit_message)
351
- end
352
-
353
- display_column = HotGlue.derrive_reference_name(assoc.class_name.to_s)
354
- "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
355
-
356
- when :float
357
- width = (limit && limit < 40) ? limit : (40)
358
- "<%= #{singular}.#{col}%>"
359
- when :string
360
- width = (limit && limit < 40) ? limit : (40)
361
- "<%= #{singular}.#{col} %>"
362
- when :text
363
- "<%= #{singular}.#{col} %>"
364
- when :datetime
365
- "<% unless #{singular}.#{col}.nil? %>
366
- <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
367
- <% else %>
368
- <span class='alert-danger'>MISSING</span>
369
- <% end %>"
370
- when :date
371
- "<% unless #{singular}.#{col}.nil? %>
372
- <%= #{singular}.#{col} %>
373
- <% else %>
374
- <span class='alert-danger'>MISSING</span>
375
- <% end %>"
376
- when :time
377
- "<% unless #{singular}.#{col}.nil? %>
378
- <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
379
- <% else %>
380
- <span class='alert-danger'>MISSING</span>
381
- <% end %>"
382
- when :boolean
383
- "
384
- <% if #{singular}.#{col}.nil? %>
385
- <span class='alert-danger'>MISSING</span>
386
- <% elsif #{singular}.#{col} %>
387
- YES
388
- <% else %>
389
- NO
390
- <% end %>
391
-
392
- "
393
- when :enum
394
- enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
395
-
396
- if eval("defined? #{singular_class}.#{enum_type}_labels") == "method"
397
- enum_definer = "#{singular_class}.#{enum_type}_labels"
398
- else
399
- enum_definer = "#{singular_class}.defined_enums['#{enum_type}']"
400
- end
401
- "
402
- <% if #{singular}.#{col}.nil? %>
403
- <span class='alert-danger'>MISSING</span>
404
- <% else %>
405
- <%= #{enum_definer}[#{singular}.#{col}.to_sym] %>
406
- <% end %>
407
-
408
- "
409
- end #end of switch
410
- end
411
-
412
- label = "<br/><label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
413
-
414
- (inline_list_labels == 'before' ? label : "") + field_output +
415
- (inline_list_labels == 'after' ? label : "")
150
+ "#{inline_list_labels == 'before' ? label + "<br/>" : ''}#{field_output}#{inline_list_labels == 'after' ? "<br/>" + label : ''}"
416
151
  }.join( "<br />") + "</div>"
417
152
  }.join("\n")
418
153
  end
@@ -28,7 +28,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
28
28
  :nest_with,
29
29
  :path, :plural,
30
30
  :sample_file_path, :singular, :singular_class, :smart_layout,
31
- :stacked_downnesting, :update_show_only
31
+ :stacked_downnesting, :update_show_only, :ownership_field,
32
+ :layout_strategy, :form_placeholder_labels, :form_labels_position
32
33
 
33
34
  class_option :singular, type: :string, default: nil
34
35
  class_option :plural, type: :string, default: nil
@@ -402,8 +403,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
402
403
  @columns_map[col] = this_column_object.field
403
404
  end
404
405
 
405
-
406
-
407
406
  # create the template object
408
407
  if @markup == "erb"
409
408
  @template_builder = HotGlue::ErbTemplate.new(
@@ -648,10 +647,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
648
647
  }.join(", ")
649
648
 
650
649
  if @factory_creation == ''
651
- "@#{singular } = #{ class_name }.create(modified_params)"
650
+ "@#{singular } = #{ class_name }.create(modified_params#{'.merge(' + merge_with + ')' if !merge_with.empty?})"
652
651
  else
653
652
  "#{@factory_creation}\n" +
654
- " @#{singular } = #{ class_name }.create(modified_params#{'.merge(' + merge_with + ')' if !merge_with.empty?})"
653
+ " @#{singular } = factory.#{singular}"
655
654
  end
656
655
  end
657
656
 
@@ -668,7 +667,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
668
667
  end
669
668
 
670
669
  def filepath_prefix
671
- 'spec/dummy/' if Rails.env.test?
670
+ 'spec/dummy/' if $INTERNAL_SPECS
672
671
  end
673
672
 
674
673
  def copy_controller_and_spec_files
@@ -707,7 +706,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
707
706
  template "system_spec.rb.erb", dest_file
708
707
  end
709
708
 
710
- template "#{@markup}/_errors.#{@markup}", File.join("#{filepath_prefix}app/views#{namespace_with_dash}", "_errors.#{@markup}")
709
+ if File.exist?("#{filepath_prefix}app/views#{namespace_with_dash}/_errors.#{@markup}")
710
+ File.delete("#{filepath_prefix}app/views#{namespace_with_dash}/_errors.#{@markup}")
711
+ end
711
712
  end
712
713
 
713
714
  def spec_foreign_association_merge_hash
@@ -1050,14 +1051,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1050
1051
  end
1051
1052
 
1052
1053
  def all_views
1053
- res = %w(index _line _list _show _errors)
1054
+ res = %w(index _line _list _show)
1054
1055
 
1055
1056
  unless @no_create
1056
1057
  res += %w(new _new_form _new_button)
1057
1058
  end
1058
1059
 
1059
1060
  unless @no_edit
1060
- res << 'edit'
1061
+ res += %w{edit _edit}
1061
1062
  end
1062
1063
 
1063
1064
  if !( @no_edit && @no_create)
@@ -1257,4 +1258,21 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1257
1258
  def any_datetime_fields?
1258
1259
  (@columns - @attachments.keys.collect(&:to_sym)).collect{|col| eval("#{singular_class}.columns_hash['#{col}']").type}.include?(:datetime)
1259
1260
  end
1261
+
1262
+ def post_action_parental_updates
1263
+ if @nested_set.any?
1264
+ "\n" + @nested_set.collect{ |data|
1265
+ parent = data[:singular]
1266
+ "@#{singular}.#{parent}.reload"
1267
+ }.join("\n")
1268
+ end
1269
+ end
1270
+
1271
+ def turbo_parental_updates
1272
+ @nested_set.collect{| data|
1273
+ "<%= turbo_stream.replace \"#{@namespace + '__' if @namespace}\#{dom_id(@#{data[:singular]})}\" do %>
1274
+ <%= render partial: \"#{@namespace}/#{data[:plural]}/edit\", locals: {#{data[:singular]}: @#{singular}.#{data[:singular]}.reload} %>
1275
+ <% end %>"
1276
+ }.join("\n")
1277
+ end
1260
1278
  end
@@ -57,8 +57,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
57
57
  def load_<%= singular_name %>
58
58
  <% if @nested_set[0] && @nested_set[0][:optional] %>if params.include?(:<%= @nested_set.last[:singular] %>_id)
59
59
  @<%= singular_name %> = <%= object_scope.gsub("@",'') %>.find(params[:id])
60
- else
61
- <% end %>@<%= singular_name %> = <%= object_scope %>.find(params[:id])<% if @nested_set[0] && @nested_set[0][:optional] %>
60
+ else <% end %>@<%= singular_name %> = <%= object_scope %>.find(params[:id])<% if @nested_set[0] && @nested_set[0][:optional] %>
62
61
  end<% end %>
63
62
  end
64
63
  <% else %>
@@ -93,6 +92,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
93
92
 
94
93
  if @<%= singular_name %>.save
95
94
  flash[:notice] = "Successfully created #{@<%= singular %>.<%= display_class %>}"
95
+ <%= post_action_parental_updates %>
96
96
  load_all_<%= plural %>
97
97
  render :create
98
98
  else
@@ -137,9 +137,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
137
137
  <% end %><% if destroy_action %> def destroy
138
138
  begin
139
139
  @<%=singular_name%>.destroy
140
+ flash[:notice] = '<%= singular_name.titlecase %> successfully deleted'
140
141
  rescue StandardError => e
141
- flash[:alert] = '<%= singular_name.titlecase %> could not be deleted.'
142
- end
142
+ flash[:alert] = '<%= singular_name.titlecase %> could not be deleted'
143
+ end <%= post_action_parental_updates %>
143
144
  load_all_<%= plural %>
144
145
  end<% end %>
145
146
 
@@ -0,0 +1,12 @@
1
+ <\%= turbo_frame_tag "<%= @namespace %>__#{dom_id(@<%= singular %>)}" do %>
2
+ <div class="cell editable" style="position: relative;">
3
+ <\% if @<%= singular %>.errors.any? %>
4
+ <\%= render(partial: "<%= namespace_with_trailing_dash %>errors", locals: {resource: @<%= singular %> }) %>
5
+ <\% end %>
6
+
7
+ <h2>Editing <\%= @<%= @singular %>.<%= display_class %> %></h2>
8
+ <\%= form_with model: <%= "@" + singular %>, url: <%= form_path_edit_helper %> do |f| %>
9
+ <\%= render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
10
+ <\% end %>
11
+ </div>
12
+ <\% end %>
@@ -1,12 +1,16 @@
1
1
  <%= turbo_frame_tag "flash_notices" do %>
2
- <% unless notice.nil? %>
3
- <div class="alert alert-notice alert-dismissible">
4
- <%= notice %>
5
- </div>
6
- <% end %>
7
- <% unless alert.nil? %>
8
- <div class="alert alert-danger alert-dismissible">
9
- <%= alert %>
2
+ <% unless notice.nil? && alert.nil? %>
3
+ <div class="alert alert-<%= alert ? 'danger' : 'primary' %> alert-dismissible">
4
+ <div><%= notice %></div>
5
+ <div><%= alert %></div>
6
+ <% if defined?(resource) && resource %>
7
+ <ul>
8
+ <% resource.errors.full_messages.each do |message| %>
9
+ <li><%= message %></li>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
13
+
10
14
  </div>
11
15
  <% end %>
12
16
  <% end %>
@@ -35,6 +35,6 @@
35
35
  <% end %>
36
36
 
37
37
  <% unless @no_edit %>
38
- <\%= 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" %>
38
+ <\%= link_to "Edit <% if @button_icons == 'font-awesome' %><i class='fa fa-1x fa-list-alt'></i><% end %>".html_safe, <%= edit_path_helper %>, <% if @big_edit %>'data-turbo' => 'false', <% end %>disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary btn-sm" %>
39
39
  <% end %>
40
40
  </div>
@@ -3,6 +3,7 @@
3
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
+ <%= turbo_parental_updates %>
6
7
  <\%= turbo_stream.replace "<%= @namespace %>__<%= singular %>__<%= singular %>-new" do %>
7
8
  <\% if @<%= singular %>.errors.none? %>
8
9
  <\%= render partial: "new_button", locals: {}<%= @nested_set.collect{|arg| ".merge(@" + arg[:singular] + " ? {" + arg[:singular] + ": @" + arg[:singular] + "} : {})"}.join() %> %>
@@ -11,8 +12,6 @@
11
12
  <\% end %>
12
13
  <\% end %>
13
14
  <\%= turbo_stream.replace "flash_notices" do %>
14
- <\%= render partial: "layouts/flash_notices" %>
15
- <\% if @<%= singular %>.errors.any? %>
16
- <\%= render partial: "errors", locals: {resource: @<%= singular %>} %>
17
- <\% end %>
15
+ <\%= render partial: "layouts/flash_notices", locals: {resource: @<%= singular %>} %>
16
+
18
17
  <\% end %>
@@ -1,3 +1,9 @@
1
- <\%= turbo_stream.replace "<%= @namespace %>__<%= plural %>-list" + <%= nested_for_turbo_nested_constructor %> do %>
1
+ <%= turbo_parental_updates %>
2
+
3
+ <\%= turbo_stream.update "<%= @namespace %>__<%= plural %>-list" + <%= nested_for_turbo_nested_constructor %> do %>
2
4
  <\%= 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
5
  <\% end %>
6
+
7
+ <\%= turbo_stream.update "flash_notices" do %>
8
+ <\%= render partial: "layouts/flash_notices", locals: {resource: @<%= singular %>} %>
9
+ <\% end %>
@@ -4,18 +4,7 @@
4
4
  <div class="col-md-12">
5
5
  <\%= link_to "<% if @button_icons == 'font-awesome' %><i class='fa fa-arrow-circle-left 2x'></i><% end %> Back to list".html_safe, <%= path_helper_plural %> %>
6
6
  <% end %>
7
- <\%= turbo_frame_tag "<%= @namespace %>__#{dom_id(@<%= singular %>)}" do %>
8
- <div class="cell editable" style="position: relative;">
9
- <\% if @<%= singular %>.errors.any? %>
10
- <\%= render(partial: "<%= namespace_with_trailing_dash %>errors", locals: {resource: @<%= singular %> }) %>
11
- <\% end %>
12
-
13
- <h2>Editing <\%= @<%= @singular %>.<%= display_class %> %></h2>
14
- <\%= form_with model: <%= "@" + singular %>, url: <%= form_path_edit_helper %> do |f| %>
15
- <\%= render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f}<%= @nested_set.collect{|arg| ".merge(@#{arg[:singular]} ? {#{arg[:singular]}: @#{arg[:singular]}} : {})" }.join %> \%>
16
- <\% end %>
17
- </div>
18
- <\% end %>
7
+ <\%= render partial: "edit", locals: {<%= singular %>: @<%= singular %>} %>
19
8
  <% if @big_edit %>
20
9
  </div>
21
10
  </div>
@@ -4,10 +4,7 @@
4
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
-
8
- <\%= turbo_stream.replace "flash_notices" do %>
9
- <\%= render partial: "layouts/flash_notices" %>
10
- <\% if @<%= singular %>.errors.any? %>
11
- <\%= render partial: "errors", locals: {resource: @<%= singular %>} %>
12
- <\% end %>
7
+ <%= turbo_parental_updates %>
8
+ <\%= turbo_stream.update "flash_notices" do %>
9
+ <\%= render partial: "layouts/flash_notices", locals: {resource: @<%= singular %>} %>
13
10
  <\% end %>
@@ -25,7 +25,7 @@ describe 'interaction for <%= controller_class_name %>' do
25
25
  describe "index" do
26
26
  it "should show me the list" do
27
27
  visit <%= path_helper_plural %>
28
- <%= @columns_map.collect{|col, col_object| col_object.spec_list_view_assertion } %>
28
+ <%= @columns_map.collect{|col, col_object| col_object.spec_list_view_assertion }.join("\n ") %>
29
29
  end
30
30
  end
31
31
 
data/lib/hot-glue.rb CHANGED
@@ -27,14 +27,17 @@ module HotGlue
27
27
  top_level: false,
28
28
  put_form: false)
29
29
  instance_sym = top_level ? "@" : ""
30
+
30
31
  if nested_set.nil? || nested_set.empty?
31
32
  return modifier + "#{(namespace + '_') if namespace}#{target}_path" + (("(#{instance_sym}#{target})" if put_form) || "")
32
33
  elsif nested_set[0][:optional] == false
34
+
33
35
  return modifier + ((namespace + "_" if namespace) || "") + nested_set.collect{|x|
34
36
  x[:singular] + "_"
35
37
  }.join() + target + "_path" + (("(#{nested_set.collect{
36
38
  |x| instance_sym + x[:singular] }.join(",")
37
- }#{ put_form ? ',' + instance_sym + target : '' })" if with_params) || "")
39
+ }#{ put_form ? ',' + instance_sym + target : '' })") || "")
40
+
38
41
 
39
42
  else
40
43
  # copy the first item, make a ternery in this cycle, and recursively move to both the
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.5.12'
3
+ CURRENT = '0.5.15'
4
4
  end
5
5
  end