hot-glue 0.1.2 → 0.2.3

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