hot-glue 0.5.14 → 0.5.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) 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 +33 -4
  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 +6 -2
  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 +31 -1
  15. data/lib/generators/hot_glue/fields/date_field.rb +13 -0
  16. data/lib/generators/hot_glue/fields/date_time_field.rb +30 -3
  17. data/lib/generators/hot_glue/fields/enum_field.rb +39 -6
  18. data/lib/generators/hot_glue/fields/field.rb +92 -8
  19. data/lib/generators/hot_glue/fields/float_field.rb +11 -0
  20. data/lib/generators/hot_glue/fields/integer_field.rb +4 -0
  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 +1 -1
  25. data/lib/generators/hot_glue/flash_notices_install_generator.rb +1 -1
  26. data/lib/generators/hot_glue/install_generator.rb +15 -9
  27. data/lib/generators/hot_glue/layout/builder.rb +4 -2
  28. data/lib/generators/hot_glue/markup_templates/erb.rb +14 -279
  29. data/lib/generators/hot_glue/scaffold_generator.rb +133 -151
  30. data/lib/generators/hot_glue/templates/erb/_edit.erb +1 -1
  31. data/lib/hotglue/version.rb +1 -1
  32. data/script/test +9 -14
  33. metadata +5 -3
@@ -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