hot-glue 0.5.8 → 0.5.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -2
  3. data/Gemfile +1 -1
  4. data/README.md +267 -149
  5. data/app/helpers/hot_glue/controller_helper.rb +9 -6
  6. data/config/hot_glue.yml +2 -0
  7. data/lib/generators/hot_glue/direct_upload_install_generator.rb +48 -0
  8. data/lib/generators/hot_glue/dropzone_install_generator.rb +42 -0
  9. data/lib/generators/hot_glue/field_factory.rb +57 -0
  10. data/lib/generators/hot_glue/fields/association_field.rb +76 -0
  11. data/lib/generators/hot_glue/fields/attachment_field.rb +9 -0
  12. data/lib/generators/hot_glue/fields/boolean_field.rb +18 -0
  13. data/lib/generators/hot_glue/fields/date_field.rb +10 -0
  14. data/lib/generators/hot_glue/fields/date_time_field.rb +23 -0
  15. data/lib/generators/hot_glue/fields/enum_field.rb +27 -0
  16. data/lib/generators/hot_glue/fields/field.rb +51 -0
  17. data/lib/generators/hot_glue/fields/float_field.rb +11 -0
  18. data/lib/generators/hot_glue/fields/integer_field.rb +26 -0
  19. data/lib/generators/hot_glue/fields/string_field.rb +33 -0
  20. data/lib/generators/hot_glue/fields/text_field.rb +14 -0
  21. data/lib/generators/hot_glue/fields/time_field.rb +6 -0
  22. data/lib/generators/hot_glue/fields/uuid_field.rb +12 -0
  23. data/lib/generators/hot_glue/layout/builder.rb +15 -6
  24. data/lib/generators/hot_glue/layout_strategy/base.rb +2 -0
  25. data/lib/generators/hot_glue/layout_strategy/bootstrap.rb +4 -0
  26. data/lib/generators/hot_glue/markup_templates/erb.rb +158 -117
  27. data/lib/generators/hot_glue/scaffold_generator.rb +296 -306
  28. data/lib/generators/hot_glue/templates/computer_code.jpg +0 -0
  29. data/lib/generators/hot_glue/templates/controller.rb.erb +15 -9
  30. data/lib/generators/hot_glue/templates/erb/_list.erb +19 -6
  31. data/lib/generators/hot_glue/templates/erb/_show.erb +6 -4
  32. data/lib/generators/hot_glue/templates/javascript/dropzone_controller.js +191 -0
  33. data/lib/generators/hot_glue/templates/system_spec.rb.erb +32 -111
  34. data/lib/hotglue/version.rb +1 -1
  35. data/script/clean_generated_code +1 -1
  36. metadata +22 -4
@@ -3,13 +3,41 @@ module HotGlue
3
3
 
4
4
  attr_accessor :path, :singular, :singular_class,
5
5
  :magic_buttons, :small_buttons,
6
- :show_only, :column_width, :layout_strategy, :perc_width,
6
+ :show_only, :layout_strategy, :perc_width,
7
7
  :ownership_field, :form_labels_position,
8
- :inline_list_labels,
9
- :columns, :column_width, :col_identifier, :singular,
10
- :form_placeholder_labels, :hawk_keys
11
-
12
-
8
+ :inline_list_labels, :layout_object,
9
+ :columns, :col_identifier, :singular,
10
+ :form_placeholder_labels, :hawk_keys, :update_show_only,
11
+ :alt_lookups, :attachments, :show_only
12
+
13
+
14
+ def initialize(singular:, singular_class: ,
15
+ layout_strategy: , magic_buttons: ,
16
+ small_buttons: , show_only: ,
17
+ ownership_field: , form_labels_position: ,
18
+ inline_list_labels: ,
19
+ form_placeholder_labels:, hawk_keys:,
20
+ update_show_only:, alt_lookups: , attachments: )
21
+
22
+ @singular = singular
23
+ @singular_class = singular_class
24
+
25
+ @magic_buttons = magic_buttons
26
+ @small_buttons = small_buttons
27
+ @layout_strategy = layout_strategy
28
+ @show_only = show_only
29
+ @ownership_field = ownership_field
30
+
31
+ @form_labels_position = form_labels_position
32
+
33
+ @inline_list_labels = inline_list_labels
34
+ @singular = singular
35
+ @form_placeholder_labels = form_placeholder_labels
36
+ @hawk_keys = hawk_keys
37
+ @update_show_only = update_show_only
38
+ @alt_lookups = alt_lookups
39
+ @attachments = attachments
40
+ end
13
41
 
14
42
  def add_spaces_each_line(text, num_spaces)
15
43
  add_spaces = " " * num_spaces
@@ -25,9 +53,12 @@ module HotGlue
25
53
  }.join("\n")
26
54
  end
27
55
 
28
- def list_column_headings(col_identifier: , columns: , column_width:, singular: )
56
+ def list_column_headings(layout_object: ,
57
+ col_identifier: ,
58
+ column_width:, singular: )
29
59
  col_style = @layout_strategy.column_headings_col_style
30
60
 
61
+ columns = layout_object[:columns][:container]
31
62
  result = columns.map{ |column|
32
63
  "<div class='#{col_identifier}' heading--#{singular}--#{column.join("-")} " + col_style + ">" +
33
64
  column.map(&:to_s).map{|col_name| "#{col_name.humanize}"}.join("<br />") + "</div>"
@@ -40,64 +71,68 @@ module HotGlue
40
71
  # THE FORM
41
72
  ################################################################
42
73
 
43
- def all_form_fields(*args)
44
-
45
- @columns = args[0][:columns]
46
- @show_only = args[0][:show_only]
47
-
48
- @singular_class = args[0][:singular_class]
49
- @ownership_field = args[0][:ownership_field]
50
- @form_labels_position = args[0][:form_labels_position]
51
- @form_placeholder_labels = args[0][:form_placeholder_labels]
52
- @hawk_keys = args[0][:hawk_keys]
53
- @singular = args[0][:singular]
54
-
55
- @alt_lookups = args[0][:alt_lookups]
56
74
 
57
- column_classes = args[0][:col_identifier]
58
- update_show_only = args[0][:update_show_only] || []
59
- singular = @singular
75
+ def all_form_fields(layout_strategy:, layout_object: )
76
+ column_classes = layout_strategy.column_classes_for_form_fields
77
+ columns = layout_object[:columns][:container]
60
78
 
61
79
  result = columns.map{ |column|
62
80
  " <div class='#{column_classes} cell--#{singular}--#{column.join("-")}' >" +
63
81
  column.map { |col|
64
- type = eval("#{singular_class}.columns_hash['#{col}']").type
65
- limit = eval("#{singular_class}.columns_hash['#{col}']").limit
66
- sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
82
+ if attachments.keys.include?(col)
83
+ this_attachment = attachments[col]
84
+ thumbnail = this_attachment[:thumbnail]
85
+ direct = this_attachment[:direct_upload]
86
+ dropzone = this_attachment[:dropzone]
87
+ field_result = (this_attachment[:thumbnail] ? "<%= #{singular}.#{col}.attached? ? image_tag(#{singular}.#{col}.variant(:#{thumbnail})) : '' %>" : "") +
88
+ "<br />\n" + (update_show_only.include?(col) ? "" : "<%= f.file_field :#{col} #{', direct_upload: true ' if direct}#{', "data-dropzone-target": "input"' if dropzone}%>")
89
+
90
+ if dropzone
91
+ field_result = "<div class=\"dropzone dropzone-default dz-clickable\" data-controller=\"dropzone\" data-dropzone-max-file-size=\"2\" data-dropzone-max-files=\"1\">\n "+ field_result + "\n</div>"
92
+ end
93
+ field_error_name = col
94
+ else
67
95
 
68
- field_result =
69
- if show_only.include?(col.to_sym)
70
- show_only_result(type: type, col: col, singular: singular)
71
- else
72
- case type
73
- when :integer
74
- integer_result(col)
75
- when :uuid
76
- association_result(col)
77
- when :string
78
- string_result(col, sql_type, limit)
79
- when :text
80
- text_result(col, sql_type, limit)
81
- when :float
82
- field_output(col, nil, 5, column_classes)
83
- when :datetime
84
- "<%= datetime_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
85
- when :date
86
- "<%= date_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
87
- when :time
88
- "<%= time_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
89
- when :boolean
90
- boolean_result(col)
91
- when :enum
92
- enum_result(col)
96
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
97
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
98
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
99
+
100
+ field_result =
101
+ if show_only.include?(col.to_sym)
102
+ show_only_result(type: type, col: col, singular: singular)
103
+ else
104
+ case type
105
+ when :integer
106
+ integer_result(col)
107
+ when :uuid
108
+ association_result(col)
109
+ when :string
110
+ string_result(col, sql_type, limit)
111
+ when :text
112
+ text_result(col, sql_type, limit)
113
+ when :float
114
+ field_output(col, nil, 5, column_classes)
115
+ when :datetime
116
+ "<%= datetime_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
117
+ when :date
118
+ "<%= date_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
119
+ when :time
120
+ "<%= time_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
121
+ when :boolean
122
+ boolean_result(col)
123
+ when :enum
124
+ enum_result(col)
125
+ end
93
126
  end
127
+
128
+ if (type == :integer) && col.to_s.ends_with?("_id")
129
+ field_error_name = col.to_s.gsub("_id","")
130
+ else
131
+ field_error_name = col
94
132
  end
95
133
 
96
- if (type == :integer) && col.to_s.ends_with?("_id")
97
- field_error_name = col.to_s.gsub("_id","")
98
- else
99
- field_error_name = col
100
134
  end
135
+ the_label = "\n<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
101
136
  show_only_open = ""
102
137
  show_only_close = ""
103
138
  if update_show_only.include?(col)
@@ -105,14 +140,13 @@ module HotGlue
105
140
  show_only_result(type: type, col: col, singular: singular) + "<% else %>"
106
141
  show_only_close = "<% end %>"
107
142
  end
108
- the_label = "\n<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
143
+
109
144
  add_spaces_each_line( "\n <span class='<%= \"alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{'style="display: inherit;"'} >\n" +
110
- add_spaces_each_line( (@form_labels_position == 'before' ? the_label : "") +
111
- show_only_open + field_result + show_only_close +
112
- (@form_labels_position == 'after' ? the_label : "") , 4) +
145
+ add_spaces_each_line( (form_labels_position == 'before' ? the_label : "") +
146
+ show_only_open + field_result + show_only_close +
147
+ (form_labels_position == 'after' ? the_label : "") , 4) +
113
148
  "\n </span>\n <br />", 2)
114
149
 
115
-
116
150
  }.join("") + "\n </div>"
117
151
  }.join("\n")
118
152
  return result
@@ -174,10 +208,9 @@ module HotGlue
174
208
  is_owner = col == ownership_field
175
209
  assoc_class_name = assoc.class_name.to_s
176
210
  display_column = HotGlue.derrive_reference_name(assoc_class_name)
177
-
178
211
  if @hawk_keys[assoc.foreign_key.to_sym]
179
212
  hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
180
- hawked_association = hawk_definition.join(".")
213
+ hawked_association = hawk_definition[:bind_to].join(".")
181
214
  else
182
215
  hawked_association = "#{assoc.class_name}.all"
183
216
  end
@@ -255,35 +288,42 @@ module HotGlue
255
288
  ################################################################
256
289
 
257
290
 
258
- def all_line_fields(*args)
259
- @columns = args[0][:columns]
260
- @show_only = args[0][:show_only]
261
- @singular_class = args[0][:singular_class]
262
- @singular = args[0][:singular]
263
- @perc_width = args[0][:perc_width]
264
- @col_identifier = @layout_strategy.column_classes_for_line_fields
291
+ def all_line_fields(layout_strategy:,
292
+ layout_object: ,
293
+ perc_width:,
294
+ col_identifier: nil)
295
+
296
+ @col_identifier = layout_strategy.column_classes_for_line_fields
265
297
 
266
- @inline_list_labels = args[0][:inline_list_labels] || 'omit'
298
+ inline_list_labels = @inline_list_labels || 'omit'
299
+ columns = layout_object[:columns][:container]
267
300
 
268
301
  columns_count = columns.count + 1
269
- perc_width = (@perc_width).floor
302
+ perc_width = (perc_width).floor
270
303
 
271
- style_with_flex_basis = @layout_strategy.style_with_flex_basis(perc_width)
304
+ style_with_flex_basis = layout_strategy.style_with_flex_basis(perc_width)
272
305
 
273
306
  result = columns.map{ |column|
274
- "<div class='#{col_identifier} #{singular}--#{column.join("-")}'#{style_with_flex_basis}> " +
275
-
276
307
 
308
+ "<div class='#{col_identifier} #{singular}--#{column.join("-")}'#{style_with_flex_basis}> " +
277
309
  column.map { |col|
278
- if eval("#{singular_class}.columns_hash['#{col}']").nil?
310
+ if eval("#{singular_class}.columns_hash['#{col}']").nil? && !attachments.keys.include?(col)
279
311
  raise "Can't find column '#{col}' on #{singular_class}, are you sure that is the column name?"
280
312
  end
281
- type = eval("#{singular_class}.columns_hash['#{col}']").type
282
- limit = eval("#{singular_class}.columns_hash['#{col}']").limit
283
- sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
284
313
 
285
- field_output =
286
- case type
314
+ if attachments.keys.include?(col)
315
+ this_attachment = attachments[col]
316
+ thumbnail = this_attachment[:thumbnail]
317
+
318
+ field_output = (this_attachment[:thumbnail] ? "<%= #{singular}.#{col}.attached? ? image_tag(#{singular}.#{col}.variant(:#{thumbnail})) : '' %>" : "")
319
+
320
+ else
321
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
322
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
323
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
324
+
325
+ field_output =
326
+ case type
287
327
  when :integer
288
328
  # look for a belongs_to on this object
289
329
  if col.ends_with?("_id")
@@ -305,48 +345,48 @@ module HotGlue
305
345
  "<%= #{singular}.#{col}%>"
306
346
  end
307
347
 
308
- when :uuid
309
- assoc_name = col.to_s.gsub("_id","")
310
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
348
+ when :uuid
349
+ assoc_name = col.to_s.gsub("_id","")
350
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
311
351
 
312
- if assoc.nil?
313
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
314
- puts exit_message
315
- exit
316
- # raise(HotGlue::Error,exit_message)
317
- end
352
+ if assoc.nil?
353
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
354
+ puts exit_message
355
+ exit
356
+ # raise(HotGlue::Error,exit_message)
357
+ end
318
358
 
319
- display_column = HotGlue.derrive_reference_name(assoc.class_name.to_s)
320
- "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
321
-
322
- when :float
323
- width = (limit && limit < 40) ? limit : (40)
324
- "<%= #{singular}.#{col}%>"
325
- when :string
326
- width = (limit && limit < 40) ? limit : (40)
327
- "<%= #{singular}.#{col} %>"
328
- when :text
329
- "<%= #{singular}.#{col} %>"
330
- when :datetime
331
- "<% unless #{singular}.#{col}.nil? %>
359
+ display_column = HotGlue.derrive_reference_name(assoc.class_name.to_s)
360
+ "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
361
+
362
+ when :float
363
+ width = (limit && limit < 40) ? limit : (40)
364
+ "<%= #{singular}.#{col}%>"
365
+ when :string
366
+ width = (limit && limit < 40) ? limit : (40)
367
+ "<%= #{singular}.#{col} %>"
368
+ when :text
369
+ "<%= #{singular}.#{col} %>"
370
+ when :datetime
371
+ "<% unless #{singular}.#{col}.nil? %>
332
372
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
333
373
  <% else %>
334
374
  <span class='alert-danger'>MISSING</span>
335
375
  <% end %>"
336
- when :date
337
- "<% unless #{singular}.#{col}.nil? %>
376
+ when :date
377
+ "<% unless #{singular}.#{col}.nil? %>
338
378
  <%= #{singular}.#{col} %>
339
379
  <% else %>
340
380
  <span class='alert-danger'>MISSING</span>
341
381
  <% end %>"
342
- when :time
343
- "<% unless #{singular}.#{col}.nil? %>
382
+ when :time
383
+ "<% unless #{singular}.#{col}.nil? %>
344
384
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
345
385
  <% else %>
346
386
  <span class='alert-danger'>MISSING</span>
347
387
  <% end %>"
348
- when :boolean
349
- "
388
+ when :boolean
389
+ "
350
390
  <% if #{singular}.#{col}.nil? %>
351
391
  <span class='alert-danger'>MISSING</span>
352
392
  <% elsif #{singular}.#{col} %>
@@ -356,15 +396,15 @@ module HotGlue
356
396
  <% end %>
357
397
 
358
398
  "
359
- when :enum
360
- enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
399
+ when :enum
400
+ enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
361
401
 
362
- if eval("defined? #{singular_class}.#{enum_type}_labels") == "method"
363
- enum_definer = "#{singular_class}.#{enum_type}_labels"
364
- else
365
- enum_definer = "#{singular_class}.defined_enums['#{enum_type}']"
366
- end
367
- "
402
+ if eval("defined? #{singular_class}.#{enum_type}_labels") == "method"
403
+ enum_definer = "#{singular_class}.#{enum_type}_labels"
404
+ else
405
+ enum_definer = "#{singular_class}.defined_enums['#{enum_type}']"
406
+ end
407
+ "
368
408
  <% if #{singular}.#{col}.nil? %>
369
409
  <span class='alert-danger'>MISSING</span>
370
410
  <% else %>
@@ -372,7 +412,8 @@ module HotGlue
372
412
  <% end %>
373
413
 
374
414
  "
375
- end #end of switch
415
+ end #end of switch
416
+ end
376
417
 
377
418
  label = "<br/><label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
378
419