hot-glue 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -6
  3. data/README.md +10 -2
  4. data/app/helpers/hot_glue/controller_helper.rb +1 -1
  5. data/lib/generators/hot_glue/install_generator.rb +0 -2
  6. data/lib/generators/hot_glue/markup_templates/base.rb +7 -0
  7. data/lib/generators/hot_glue/markup_templates/erb.rb +228 -0
  8. data/lib/generators/hot_glue/markup_templates/haml.rb +223 -0
  9. data/lib/generators/hot_glue/markup_templates/slim.rb +9 -0
  10. data/lib/generators/hot_glue/scaffold_generator.rb +97 -214
  11. data/lib/generators/hot_glue/templates/erb/_errors.erb +11 -0
  12. data/lib/generators/hot_glue/templates/erb/_flash_notices.erb +12 -0
  13. data/lib/generators/hot_glue/templates/erb/_form.erb +8 -0
  14. data/lib/generators/hot_glue/templates/erb/_line.erb +10 -0
  15. data/lib/generators/hot_glue/templates/erb/_list.erb +19 -0
  16. data/lib/generators/hot_glue/templates/erb/_new_button.erb +3 -0
  17. data/lib/generators/hot_glue/templates/erb/_new_form.erb +8 -0
  18. data/lib/generators/hot_glue/templates/erb/_show.erb +8 -0
  19. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +18 -0
  20. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +3 -0
  21. data/lib/generators/hot_glue/templates/erb/edit.erb +30 -0
  22. data/lib/generators/hot_glue/templates/erb/edit.turbo_stream.erb +3 -0
  23. data/lib/generators/hot_glue/templates/erb/index.erb +10 -0
  24. data/lib/generators/hot_glue/templates/erb/new.erb +1 -0
  25. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +10 -0
  26. data/lib/generators/hot_glue/templates/{_errors.haml → haml/_errors.haml} +0 -0
  27. data/lib/generators/hot_glue/templates/{_flash_notices.haml → haml/_flash_notices.haml} +0 -0
  28. data/lib/generators/hot_glue/templates/{_form.haml → haml/_form.haml} +0 -0
  29. data/lib/generators/hot_glue/templates/{_line.haml → haml/_line.haml} +0 -0
  30. data/lib/generators/hot_glue/templates/{_list.haml → haml/_list.haml} +0 -0
  31. data/lib/generators/hot_glue/templates/{_new_button.haml → haml/_new_button.haml} +0 -0
  32. data/lib/generators/hot_glue/templates/{_new_form.haml → haml/_new_form.haml} +0 -0
  33. data/lib/generators/hot_glue/templates/{_show.haml → haml/_show.haml} +0 -0
  34. data/lib/generators/hot_glue/templates/{create.turbo_stream.haml → haml/create.turbo_stream.haml} +0 -0
  35. data/lib/generators/hot_glue/templates/{destroy.turbo_stream.haml → haml/destroy.turbo_stream.haml} +0 -0
  36. data/lib/generators/hot_glue/templates/{edit.haml → haml/edit.haml} +0 -0
  37. data/lib/generators/hot_glue/templates/{edit.turbo_stream.haml → haml/edit.turbo_stream.haml} +0 -0
  38. data/lib/generators/hot_glue/templates/{index.haml → haml/index.haml} +0 -0
  39. data/lib/generators/hot_glue/templates/{new.haml → haml/new.haml} +0 -0
  40. data/lib/generators/hot_glue/templates/{update.turbo_stream.haml → haml/update.turbo_stream.haml} +0 -0
  41. data/lib/hot-glue.rb +6 -20
  42. data/lib/hotglue/version.rb +1 -1
  43. metadata +36 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b265c8c7f5e9fb424122d2d40eec712a7cb4f846f5daf581b75a8e4981790fa
4
- data.tar.gz: 23e8b5857b4e8fa2391a46128a282a952355fe64c9097868b98bf8d462c9a35c
3
+ metadata.gz: 81ca38b1bfb68e173a1665d924729b04afa26ccda900d707508a64e01977f1ad
4
+ data.tar.gz: 8d2b98c07d84ec264600d79f5073139ea717a3b66488b5b269a4466bc5eb04be
5
5
  SHA512:
6
- metadata.gz: 3a304db4b93d3edf92657178e0057830f224dda0e1b08c5957169d2e6f378ac6cc9137513e18001c38881d7f2594d2d608ba3de07ffa86291089c01cccecc462
7
- data.tar.gz: 884d154c85a9688b66db56498f2f66dbda7356d06d2f5590e80c911f86e46fee5bcefc1809f6d5deb339b79fe95a95d45f823a89128105ec367f0d7b6c67a85d
6
+ metadata.gz: 4525044b21596dd6dc96d7aa397402421459ec483749df04dd08ad3f20de7a6a1998e38b9436d77522c48dedabb78a3b4e9e88ce2225e2c8633b8c32a30fa8a8
7
+ data.tar.gz: 06d16a32919eb23b306add1ca5e1997694f0bbbb21d0bc045992530b2963cf65f6dbb987fb3223b50a1e543598e1f42611f17b80b206fb032d2c00d8ddb72eb9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.1.1)
4
+ hot-glue (0.2.0)
5
5
  ffaker (~> 2.16)
6
6
  haml-rails (~> 2.0)
7
7
  kaminari (~> 1.2)
@@ -84,11 +84,11 @@ GEM
84
84
  warden (~> 1.2.3)
85
85
  erubi (1.10.0)
86
86
  erubis (2.7.0)
87
- ffaker (2.18.0)
88
- ffi (1.15.3)
87
+ ffaker (2.19.0)
88
+ ffi (1.15.4)
89
89
  globalid (0.4.2)
90
90
  activesupport (>= 4.2.0)
91
- haml (5.2.1)
91
+ haml (5.2.2)
92
92
  temple (>= 0.8.0)
93
93
  tilt
94
94
  haml-rails (2.0.1)
@@ -169,7 +169,7 @@ GEM
169
169
  responders (3.0.1)
170
170
  actionpack (>= 5.0)
171
171
  railties (>= 5.0)
172
- ruby_parser (3.16.0)
172
+ ruby_parser (3.17.0)
173
173
  sexp_processor (~> 4.15, >= 4.15.1)
174
174
  sass-rails (6.0.0)
175
175
  sassc-rails (~> 2.1, >= 2.1.1)
@@ -193,7 +193,7 @@ GEM
193
193
  temple (0.8.2)
194
194
  thor (1.1.0)
195
195
  tilt (2.0.10)
196
- turbo-rails (0.5.11)
196
+ turbo-rails (0.7.11)
197
197
  rails (>= 6.0.0)
198
198
  tzinfo (2.0.4)
199
199
  concurrent-ruby (~> 1.0)
@@ -206,6 +206,7 @@ GEM
206
206
 
207
207
  PLATFORMS
208
208
  -darwin-20
209
+ ruby
209
210
 
210
211
  DEPENDENCIES
211
212
  byebug
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
- # Hot Glue
2
1
 
3
2
  Hot Glue is a Rails scaffold builder for the Turbo era. It is an evolution of the admin-interface style scaffolding systems of the 2010s ([activeadmin](https://github.com/activeadmin/activeadmin), [rails_admin](https://github.com/sferik/rails_admin), and [active_scaffold](https://github.com/activescaffold/active_scaffold)).
4
3
 
@@ -318,6 +317,12 @@ end
318
317
 
319
318
  ```
320
319
 
320
+
321
+ ### `--markup` (default: 'erb')
322
+
323
+ ERB is default. For HAML, `--markup=haml`.
324
+
325
+
321
326
  ## FLAGS (Options with no values)
322
327
  These options (flags) also uses `--` syntax but do not take any values. Everything is assumed (default) to be false unless specified.
323
328
 
@@ -354,8 +359,11 @@ If you do not want inline editing of your list items but instead to fall back to
354
359
 
355
360
  # VERSION HISTORY
356
361
 
357
- #### - v0.1.1 -
362
+ #### 2021-09-06 - v0.2.0 - SLIM and ERB ; use the option --markup=erb or --markup=haml (default is now erb)
363
+
364
+ #### 2021-06-28 - v0.1.2 - fixes problem with namespaces on path helpers
358
365
 
366
+ #### 2021-05-09 (yanked) - v0.1.1 - add cancellation buttons
359
367
 
360
368
  #### 2021-04-28 - v0.1.0 - Very pleased to introduce full behavior specs, found in specs/system/, generated by default on all build code; also many fixes involving nesting and authentication"
361
369
 
@@ -43,7 +43,7 @@ module HotGlue
43
43
  type: 'time',
44
44
  value: date_to_current_timezone(value, timezone))
45
45
 
46
- res << timezonize(tz)
46
+ res << timezonize(timezone)
47
47
  res
48
48
  end
49
49
 
@@ -10,8 +10,6 @@ module HotGlue
10
10
 
11
11
  def initialize(*args) #:nodoc:
12
12
  super
13
- # copy_file "hot_glue.js", "#{'spec/dummy/' if Rails.env.test?}app/javascript/hot_glue.js"
14
- # copy_file "hot_glue.scss", "#{'spec/dummy/' if Rails.env.test?}app/assets/stylesheets/hot_glue.scss"
15
13
  copy_file "_flash_notices.haml", "#{'spec/dummy/' if Rails.env.test?}app/views/layouts/_flash_notices.haml"
16
14
  end
17
15
  end
@@ -0,0 +1,7 @@
1
+ module HotGlue
2
+ class TemplateBase
3
+ def initialize()
4
+ end
5
+
6
+ end
7
+ end
@@ -0,0 +1,228 @@
1
+ module HotGlue
2
+ class ErbTemplate < TemplateBase
3
+
4
+ attr_accessor :singular
5
+
6
+ def field_output(col, type = nil, width, col_identifier )
7
+ "<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
8
+ " <%= f.text_field :#{col.to_s}, value: @#{@singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}' %>\n "+
9
+ " <label class='form-text' >#{col.to_s.humanize}</label>\n" +
10
+ "</div>"
11
+ end
12
+
13
+ def list_column_headings(*args)
14
+ columns = args[0][:columns]
15
+
16
+ columns.map(&:to_s).map{|col_name| "<div class='col'>#{col_name.humanize}</div>"}.join("\n")
17
+ end
18
+
19
+
20
+ def all_form_fields(*args)
21
+
22
+ columns = args[0][:columns]
23
+ show_only = args[0][:show_only]
24
+ singular_class = args[0][:singular_class]
25
+
26
+ # TODO: CLEAN ME
27
+ @singular = args[0][:singular]
28
+ singular = @singular
29
+
30
+
31
+ col_identifier = "col"
32
+ col_spaces_prepend = " "
33
+
34
+ res = columns.map { |col|
35
+
36
+ if show_only.include?(col)
37
+
38
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
39
+ = @#{singular}.#{col.to_s}
40
+ %label.form-text
41
+ #{col.to_s.humanize}\n"
42
+ else
43
+
44
+
45
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
46
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
47
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
48
+
49
+ case type
50
+ when :integer
51
+ # look for a belongs_to on this object
52
+ if col.to_s.ends_with?("_id")
53
+ assoc_name = col.to_s.gsub("_id","")
54
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
55
+ if assoc.nil?
56
+ exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
57
+ exit
58
+ end
59
+ display_column = derrive_reference_name(assoc.class_name)
60
+
61
+
62
+ "<div class='#{col_identifier} form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}>
63
+ <%= f.collection_select(:#{col.to_s}, #{assoc.class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
64
+ <label class='small form-text text-muted'>#{col.to_s.humanize}</label></div>"
65
+
66
+ else
67
+ "<div class=\"#{col_identifier} form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col})}\" >
68
+ <%= f.text_field :#{col.to_s}, value: #{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number' %>
69
+ <label class='small form-text text-muted'>#{col.to_s.humanize}</label></div>"
70
+
71
+ end
72
+ when :string
73
+ limit ||= 256
74
+ if limit <= 256
75
+ field_output(col, nil, limit, col_identifier)
76
+ else
77
+ text_area_output(col, limit, col_identifier)
78
+ end
79
+
80
+ when :text
81
+ limit ||= 256
82
+ if limit <= 256
83
+ field_output(col, nil, limit, col_identifier)
84
+ else
85
+ text_area_output(col, limit, col_identifier)
86
+ end
87
+ when :float
88
+ limit ||= 256
89
+ field_output(col, nil, limit, col_identifier)
90
+
91
+
92
+ when :datetime
93
+
94
+
95
+ "<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
96
+ "<%= datetime_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>" +
97
+ "</div>"
98
+ when :date
99
+ "<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
100
+ "<%= date_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>" +
101
+ "</div>"
102
+ when :time
103
+ "<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
104
+ "<%= time_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>" +
105
+ "</div>"
106
+
107
+ when :boolean
108
+ "<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
109
+ " <span>#{col.to_s.humanize}</span>" +
110
+ " <%= f.radio_button(:#{col.to_s}, '0', checked: #{singular}.#{col.to_s} ? '' : 'checked') %>\n" +
111
+ " <%= f.label(:#{col.to_s}, value: 'No', for: '#{singular}_#{col.to_s}_0') %>\n" +
112
+ " <%= f.radio_button(:#{col.to_s}, '1', checked: #{singular}.#{col.to_s} ? 'checked' : '') %>\n" +
113
+ " <%= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1') %>\n" +
114
+ "</div>"
115
+ end
116
+ end
117
+ }.join("\n")
118
+ return res
119
+ end
120
+
121
+
122
+
123
+ def paginate(*args)
124
+ plural = args[0][:plural]
125
+
126
+ "<% if #{plural}.respond_to?(:total_pages) %><%= paginate(#{plural}) %> <% end %>"
127
+ end
128
+
129
+ def all_line_fields(*args)
130
+ columns = args[0][:columns]
131
+ show_only = args[0][:show_only]
132
+ singular_class = args[0][:singular_class]
133
+ singular = args[0][:singular]
134
+
135
+ columns_count = columns.count + 1
136
+ perc_width = (100/columns_count).floor
137
+
138
+ col_identifer = "col"
139
+ columns.map { |col|
140
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
141
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
142
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
143
+
144
+ case type
145
+ when :integer
146
+ # look for a belongs_to on this object
147
+ if col.to_s.ends_with?("_id")
148
+
149
+ assoc_name = col.to_s.gsub("_id","")
150
+
151
+
152
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
153
+
154
+ if assoc.nil?
155
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
156
+ raise(HotGlue::Error,exit_message)
157
+ end
158
+
159
+ display_column = derrive_reference_name(assoc.class_name)
160
+
161
+
162
+ "<div class='#{col_identifer}'>
163
+ <%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>
164
+ </div>"
165
+
166
+ else
167
+ "<div class='#{col_identifer}'>
168
+ <%= #{singular}.#{col}%></div>"
169
+ end
170
+ when :float
171
+ width = (limit && limit < 40) ? limit : (40)
172
+ "#{col_identifer}
173
+ = #{singular}.#{col}"
174
+
175
+ when :string
176
+ width = (limit && limit < 40) ? limit : (40)
177
+ "<div class='#{col_identifer}'>
178
+ <%= #{singular}.#{col} %>
179
+ </div>"
180
+ when :text
181
+ "<div class='#{col_identifer}'>
182
+ <%= #{singular}.#{col} %>
183
+ </div>"
184
+ when :datetime
185
+
186
+ "<div class='#{col_identifer}'>
187
+ <% unless #{singular}.#{col}.nil? %>
188
+ <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
189
+ <% else %>
190
+ <span class='alert-danger'>MISSING</span>
191
+ <% end %>
192
+ </div>"
193
+ when :date
194
+ "<div class='#{col_identifer}'>
195
+ <% unless #{singular}.#{col}.nil? %>
196
+ <%= #{singular}.#{col} %>
197
+ <% else %>
198
+ <span class='alert-danger'>MISSING</span>
199
+ <% end %>
200
+ </div>"
201
+ when :time
202
+ "<div class='#{col_identifer}'>
203
+ <% unless #{singular}.#{col}.nil? %>
204
+ <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
205
+ <% else %>
206
+ <span class='alert-danger'>MISSING</span>
207
+ <% end %>
208
+ </div>
209
+ "
210
+ when :boolean
211
+ "<div class='#{col_identifer}'>
212
+ <% if #{singular}.#{col}.nil? %>
213
+ <span class='alert-danger'>MISSING</span>
214
+ <% elsif #{singular}.#{col} %>
215
+ YES
216
+ <% else %>
217
+ NO
218
+ <% end %>
219
+ </div>
220
+ "
221
+ end #end of switch
222
+ }.join("\n")
223
+ end
224
+ end
225
+
226
+
227
+
228
+ end
@@ -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