hot-glue 0.0.9 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +21 -18
  3. data/README.md +83 -50
  4. data/app/helpers/hot_glue/controller_helper.rb +1 -1
  5. data/db/migrate/20210306223305_create_ghis.rb +9 -0
  6. data/db/schema.rb +1 -1
  7. data/lib/generators/hot_glue/install_generator.rb +0 -2
  8. data/lib/generators/hot_glue/markup_templates/base.rb +7 -0
  9. data/lib/generators/hot_glue/markup_templates/erb.rb +228 -0
  10. data/lib/generators/hot_glue/markup_templates/haml.rb +223 -0
  11. data/lib/generators/hot_glue/markup_templates/slim.rb +9 -0
  12. data/lib/generators/hot_glue/scaffold_generator.rb +162 -265
  13. data/lib/generators/hot_glue/templates/controller.rb.erb +24 -10
  14. data/lib/generators/hot_glue/templates/erb/_errors.erb +11 -0
  15. data/lib/generators/hot_glue/templates/erb/_flash_notices.erb +12 -0
  16. data/lib/generators/hot_glue/templates/erb/_form.erb +8 -0
  17. data/lib/generators/hot_glue/templates/erb/_line.erb +10 -0
  18. data/lib/generators/hot_glue/templates/erb/_list.erb +19 -0
  19. data/lib/generators/hot_glue/templates/erb/_new_button.erb +3 -0
  20. data/lib/generators/hot_glue/templates/erb/_new_form.erb +8 -0
  21. data/lib/generators/hot_glue/templates/erb/_show.erb +8 -0
  22. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +18 -0
  23. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +3 -0
  24. data/lib/generators/hot_glue/templates/erb/edit.erb +30 -0
  25. data/lib/generators/hot_glue/templates/erb/edit.turbo_stream.erb +3 -0
  26. data/lib/generators/hot_glue/templates/erb/index.erb +10 -0
  27. data/lib/generators/hot_glue/templates/erb/new.erb +1 -0
  28. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +10 -0
  29. data/lib/generators/hot_glue/templates/{_errors.haml → haml/_errors.haml} +0 -0
  30. data/lib/generators/hot_glue/templates/{_flash_notices.haml → haml/_flash_notices.haml} +0 -0
  31. data/lib/generators/hot_glue/templates/{_form.haml → haml/_form.haml} +1 -0
  32. data/lib/generators/hot_glue/templates/{_line.haml → haml/_line.haml} +0 -0
  33. data/lib/generators/hot_glue/templates/{_list.haml → haml/_list.haml} +0 -0
  34. data/lib/generators/hot_glue/templates/{_new_button.haml → haml/_new_button.haml} +0 -0
  35. data/lib/generators/hot_glue/templates/{_new_form.haml → haml/_new_form.haml} +0 -3
  36. data/lib/generators/hot_glue/templates/haml/_show.haml +7 -0
  37. data/lib/generators/hot_glue/templates/{create.turbo_stream.haml → haml/create.turbo_stream.haml} +0 -0
  38. data/lib/generators/hot_glue/templates/{destroy.turbo_stream.haml → haml/destroy.turbo_stream.haml} +0 -0
  39. data/lib/generators/hot_glue/templates/{edit.haml → haml/edit.haml} +0 -0
  40. data/lib/generators/hot_glue/templates/{edit.turbo_stream.haml → haml/edit.turbo_stream.haml} +0 -0
  41. data/lib/generators/hot_glue/templates/{index.haml → haml/index.haml} +0 -0
  42. data/lib/generators/hot_glue/templates/{new.haml → haml/new.haml} +0 -0
  43. data/lib/generators/hot_glue/templates/haml/update.turbo_stream.haml +9 -0
  44. data/lib/generators/hot_glue/templates/system_spec.rb.erb +109 -14
  45. data/lib/hot-glue.rb +6 -20
  46. data/lib/hotglue/version.rb +1 -1
  47. metadata +38 -20
  48. data/db/migrate/20210306223305_create_hgis.rb +0 -9
  49. data/lib/generators/hot_glue/templates/_show.haml +0 -7
  50. data/lib/generators/hot_glue/templates/request_spec.rb.erb +0 -110
  51. data/lib/generators/hot_glue/templates/update.turbo_stream.haml +0 -5
@@ -0,0 +1,223 @@
1
+ module HotGlue
2
+ class HamlTemplate < TemplateBase
3
+
4
+ attr_accessor :singular
5
+
6
+ def field_output(col, type = nil, width, col_identifier )
7
+
8
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
9
+ = f.text_field :#{col.to_s}, value: @#{@singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}'
10
+ %label.form-text
11
+ #{col.to_s.humanize}\n"
12
+ end
13
+
14
+
15
+ def all_form_fields(*args)
16
+
17
+ columns = args[0][:columns]
18
+ show_only = args[0][:show_only]
19
+ singular_class = args[0][:singular_class]
20
+
21
+ # TODO: CLEAN ME
22
+ @singular = args[0][:singular]
23
+ singular = @singular
24
+
25
+
26
+ col_identifier = " .col"
27
+ col_spaces_prepend = " "
28
+
29
+ res = columns.map { |col|
30
+
31
+ if show_only.include?(col)
32
+
33
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
34
+ = @#{singular}.#{col.to_s}
35
+ %label.form-text
36
+ #{col.to_s.humanize}\n"
37
+ else
38
+
39
+
40
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
41
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
42
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
43
+
44
+ case type
45
+ when :integer
46
+ # look for a belongs_to on this object
47
+ if col.to_s.ends_with?("_id")
48
+ assoc_name = col.to_s.gsub("_id","")
49
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
50
+ if assoc.nil?
51
+ exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
52
+ exit
53
+ end
54
+ display_column = derrive_reference_name(assoc.class_name)
55
+
56
+
57
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
58
+ #{col_spaces_prepend}= f.collection_select(:#{col.to_s}, #{assoc.class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
59
+ #{col_spaces_prepend}%label.small.form-text.text-muted
60
+ #{col_spaces_prepend} #{col.to_s.humanize}"
61
+
62
+ else
63
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
64
+ #{col_spaces_prepend}= f.text_field :#{col.to_s}, value: #{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number'
65
+ #{col_spaces_prepend}%label.form-text
66
+ #{col_spaces_prepend} #{col.to_s.humanize}\n"
67
+ end
68
+ when :string
69
+ limit ||= 256
70
+ if limit <= 256
71
+ field_output(col, nil, limit, col_identifier)
72
+ else
73
+ text_area_output(col, limit, col_identifier)
74
+ end
75
+
76
+ when :text
77
+ limit ||= 256
78
+ if limit <= 256
79
+ field_output(col, nil, limit, col_identifier)
80
+ else
81
+ text_area_output(col, limit, col_identifier)
82
+ end
83
+ when :float
84
+ limit ||= 256
85
+ field_output(col, nil, limit, col_identifier)
86
+
87
+
88
+ when :datetime
89
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
90
+ #{col_spaces_prepend}= datetime_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
91
+ when :date
92
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
93
+ #{col_spaces_prepend}= date_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
94
+ when :time
95
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
96
+ #{col_spaces_prepend}= time_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
97
+ when :boolean
98
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
99
+ #{col_spaces_prepend}%span
100
+ #{col_spaces_prepend} #{col.to_s.humanize}
101
+ #{col_spaces_prepend}= f.radio_button(:#{col.to_s}, '0', checked: #{singular}.#{col.to_s} ? '' : 'checked')
102
+ #{col_spaces_prepend}= f.label(:#{col.to_s}, value: 'No', for: '#{singular}_#{col.to_s}_0')
103
+
104
+ #{col_spaces_prepend}= f.radio_button(:#{col.to_s}, '1', checked: #{singular}.#{col.to_s} ? 'checked' : '')
105
+ #{col_spaces_prepend}= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1')
106
+ "
107
+ end
108
+ end
109
+ }.join("\n")
110
+ return res
111
+ end
112
+
113
+
114
+
115
+ def paginate(*args)
116
+ plural = args[0][:plural]
117
+
118
+ "- if #{plural}.respond_to?(:total_pages)
119
+ = paginate #{plural}"
120
+ end
121
+
122
+ def all_line_fields(*args)
123
+ columns = args[0][:columns]
124
+ show_only = args[0][:show_only]
125
+ singular_class = args[0][:singular_class]
126
+ singular = args[0][:singular]
127
+
128
+ columns_count = columns.count + 1
129
+ perc_width = (100/columns_count).floor
130
+
131
+ col_identifer = ".col"
132
+ columns.map { |col|
133
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
134
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
135
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
136
+
137
+ case type
138
+ when :integer
139
+ # look for a belongs_to on this object
140
+ if col.to_s.ends_with?("_id")
141
+
142
+ assoc_name = col.to_s.gsub("_id","")
143
+
144
+
145
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
146
+
147
+ if assoc.nil?
148
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
149
+ raise(HotGlue::Error,exit_message)
150
+ end
151
+
152
+ display_column = derrive_reference_name(assoc.class_name)
153
+
154
+
155
+ "#{col_identifer}
156
+ = #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe"
157
+
158
+ else
159
+ "#{col_identifer}
160
+ = #{singular}.#{col}"
161
+ end
162
+ when :float
163
+ width = (limit && limit < 40) ? limit : (40)
164
+ "#{col_identifer}
165
+ = #{singular}.#{col}"
166
+
167
+ when :string
168
+ width = (limit && limit < 40) ? limit : (40)
169
+ "#{col_identifer}
170
+ = #{singular}.#{col}"
171
+ when :text
172
+ "#{col_identifer}
173
+ = #{singular}.#{col}"
174
+ when :datetime
175
+ "#{col_identifer}
176
+ - unless #{singular}.#{col}.nil?
177
+ = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone)
178
+ - else
179
+ %span.alert-danger
180
+ MISSING
181
+ "
182
+ when :date
183
+ "#{col_identifer}
184
+ - unless #{singular}.#{col}.nil?
185
+ = #{singular}.#{col}
186
+ - else
187
+ %span.alert-danger
188
+ MISSING
189
+ "
190
+ when :time
191
+ "#{col_identifer}
192
+ - unless #{singular}.#{col}.nil?
193
+ = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone)
194
+ - else
195
+ %span.alert-danger
196
+ MISSING
197
+ "
198
+ when :boolean
199
+ "#{col_identifer}
200
+ - if #{singular}.#{col}.nil?
201
+ %span.alert-danger
202
+ MISSING
203
+ - elsif #{singular}.#{col}
204
+ YES
205
+ - else
206
+ NO
207
+ "
208
+ end #end of switch
209
+ }.join("\n")
210
+ end
211
+
212
+ def list_column_headings(*args)
213
+ columns = args[0][:columns]
214
+
215
+ columns.map(&:to_s).map{|col_name| ' .col ' + col_name.humanize}.join("\n")
216
+ end
217
+
218
+ end
219
+
220
+
221
+
222
+
223
+ end
@@ -0,0 +1,9 @@
1
+
2
+
3
+ module HotGlue
4
+ class Slim < TemplateBase
5
+
6
+
7
+
8
+ end
9
+ end