hot-glue 0.4.4 → 0.4.8.1

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