hot-glue 0.5.4 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -5
- data/README.md +50 -9
- data/app/helpers/hot_glue/controller_helper.rb +2 -2
- data/lib/generators/hot_glue/install_generator.rb +13 -13
- data/lib/generators/hot_glue/layout/builder.rb +11 -8
- data/lib/generators/hot_glue/layout_strategy/base.rb +31 -0
- data/lib/generators/hot_glue/layout_strategy/bootstrap.rb +41 -0
- data/lib/generators/hot_glue/layout_strategy/hot_glue.rb +82 -0
- data/lib/generators/hot_glue/layout_strategy/tailwind.rb +28 -0
- data/lib/generators/hot_glue/markup_templates/base.rb +3 -3
- data/lib/generators/hot_glue/markup_templates/erb.rb +88 -80
- data/lib/generators/hot_glue/scaffold_generator.rb +88 -114
- data/lib/generators/hot_glue/templates/controller.rb.erb +3 -0
- data/lib/generators/hot_glue/templates/erb/_form.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_line.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_list.erb +5 -10
- data/lib/generators/hot_glue/templates/erb/_show.erb +3 -3
- data/lib/generators/hot_glue/templates/erb/index.erb +3 -6
- data/lib/hot-glue.rb +0 -4
- data/lib/hotglue/engine.rb +1 -1
- data/lib/hotglue/version.rb +1 -1
- metadata +6 -3
- data/lib/generators/hot_glue/helpers.rb +0 -13
@@ -3,7 +3,7 @@ module HotGlue
|
|
3
3
|
|
4
4
|
attr_accessor :path, :singular, :singular_class,
|
5
5
|
:magic_buttons, :small_buttons,
|
6
|
-
:show_only, :column_width, :
|
6
|
+
:show_only, :column_width, :layout_strategy, :perc_width,
|
7
7
|
:ownership_field, :form_labels_position,
|
8
8
|
:inline_list_labels,
|
9
9
|
:columns, :column_width, :col_identifier, :singular,
|
@@ -16,14 +16,7 @@ module HotGlue
|
|
16
16
|
text.lines.collect{|line| add_spaces + line}.join("")
|
17
17
|
end
|
18
18
|
|
19
|
-
def magic_button_output(
|
20
|
-
path = args[0][:path]
|
21
|
-
# path_helper_singular = args[0][:path_helper_singular]
|
22
|
-
# path_helper_args = args[0][:path_helper_args]
|
23
|
-
singular = args[0][:singular]
|
24
|
-
magic_buttons = args[0][:magic_buttons]
|
25
|
-
small_buttons = args[0][:small_buttons]
|
26
|
-
|
19
|
+
def magic_button_output(path:, singular:, magic_buttons:, small_buttons: )
|
27
20
|
magic_buttons.collect{ |button_name|
|
28
21
|
"<%= form_with model: #{singular}, url: #{path}, html: {style: 'display: inline', data: {\"turbo-confirm\": 'Are you sure you want to #{button_name} this #{singular}?'}} do |f| %>
|
29
22
|
<%= f.hidden_field :#{button_name}, value: \"#{button_name}\" %>
|
@@ -36,13 +29,8 @@ module HotGlue
|
|
36
29
|
@columns = args[0][:columns]
|
37
30
|
@column_width = args[0][:column_width]
|
38
31
|
@col_identifier = args[0][:col_identifier]
|
39
|
-
@layout = args[0][:layout]
|
40
32
|
|
41
|
-
|
42
|
-
col_style = " style='flex-basis: #{column_width}%'"
|
43
|
-
else
|
44
|
-
col_style = ""
|
45
|
-
end
|
33
|
+
col_style = @layout_strategy.column_headings_col_style
|
46
34
|
|
47
35
|
result = columns.map{ |column|
|
48
36
|
"<div class='#{col_identifier}'" + col_style + ">" + column.map(&:to_s).map{|col_name| "#{col_name.humanize}"}.join("<br />") + "</div>"
|
@@ -59,16 +47,17 @@ module HotGlue
|
|
59
47
|
@columns = args[0][:columns]
|
60
48
|
@show_only = args[0][:show_only]
|
61
49
|
@singular_class = args[0][:singular_class]
|
62
|
-
@col_identifier = args[0][:col_identifier]
|
63
50
|
@ownership_field = args[0][:ownership_field]
|
64
51
|
@form_labels_position = args[0][:form_labels_position]
|
65
52
|
@form_placeholder_labels = args[0][:form_placeholder_labels]
|
66
53
|
@hawk_keys = args[0][:hawk_keys]
|
67
|
-
|
68
54
|
@singular = args[0][:singular]
|
55
|
+
|
56
|
+
column_classes = args[0][:col_identifier]
|
57
|
+
|
69
58
|
singular = @singular
|
70
59
|
result = columns.map{ |column|
|
71
|
-
" <div class='#{
|
60
|
+
" <div class='#{column_classes}' >" +
|
72
61
|
column.map { |col|
|
73
62
|
field_result =
|
74
63
|
if show_only.include?(col.to_sym)
|
@@ -81,12 +70,14 @@ module HotGlue
|
|
81
70
|
case type
|
82
71
|
when :integer
|
83
72
|
integer_result(col)
|
73
|
+
when :uuid
|
74
|
+
uuid_result(col)
|
84
75
|
when :string
|
85
76
|
string_result(col, sql_type, limit)
|
86
77
|
when :text
|
87
78
|
text_result(col, sql_type, limit)
|
88
79
|
when :float
|
89
|
-
field_output(col, nil, 5,
|
80
|
+
field_output(col, nil, 5, column_classes)
|
90
81
|
when :datetime
|
91
82
|
"<%= datetime_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
|
92
83
|
when :date
|
@@ -122,36 +113,44 @@ module HotGlue
|
|
122
113
|
def integer_result(col)
|
123
114
|
# look for a belongs_to on this object
|
124
115
|
if col.to_s.ends_with?("_id")
|
125
|
-
|
126
|
-
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
127
|
-
if assoc.nil?
|
128
|
-
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
129
|
-
exit
|
130
|
-
end
|
131
|
-
|
132
|
-
is_owner = col == ownership_field
|
133
|
-
assoc_class_name = assoc.active_record.name
|
134
|
-
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
135
|
-
|
136
|
-
if @hawk_keys[assoc.foreign_key.to_sym]
|
137
|
-
hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
|
138
|
-
hawk_root = hawk_definition[0]
|
139
|
-
hawk_scope = hawk_definition[1]
|
140
|
-
hawked_association = "#{hawk_root}.#{hawk_scope}"
|
141
|
-
else
|
142
|
-
hawked_association = "#{assoc.class_name}.all"
|
143
|
-
end
|
144
|
-
|
145
|
-
(is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
|
146
|
-
" <%= f.collection_select(:#{col}, #{hawked_association}, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
|
147
|
-
(is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
|
148
|
-
(is_owner ? "\n<% end %>" : "")
|
149
|
-
|
116
|
+
association_result(col)
|
150
117
|
else
|
151
118
|
" <%= f.text_field :#{col}, value: #{@singular}.#{col}, autocomplete: 'off', size: 4, class: 'form-control', type: 'number'" + (@form_placeholder_labels ? ", placeholder: '#{col.to_s.humanize}'" : "") + " %>\n " + "\n"
|
152
119
|
end
|
153
120
|
end
|
154
121
|
|
122
|
+
|
123
|
+
def uuid_result(col)
|
124
|
+
association_result(col)
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def association_result(col)
|
129
|
+
assoc_name = col.to_s.gsub("_id","")
|
130
|
+
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
131
|
+
if assoc.nil?
|
132
|
+
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
|
136
|
+
is_owner = col == ownership_field
|
137
|
+
assoc_class_name = assoc.active_record.name
|
138
|
+
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
139
|
+
|
140
|
+
if @hawk_keys[assoc.foreign_key.to_sym]
|
141
|
+
hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
|
142
|
+
hawked_association = hawk_definition.join(".")
|
143
|
+
else
|
144
|
+
hawked_association = "#{assoc.class_name}.all"
|
145
|
+
end
|
146
|
+
|
147
|
+
(is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
|
148
|
+
" <%= f.collection_select(:#{col}, #{hawked_association}, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
|
149
|
+
(is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
|
150
|
+
(is_owner ? "\n<% end %>" : "")
|
151
|
+
|
152
|
+
end
|
153
|
+
|
155
154
|
def string_result(col, sql_type, limit)
|
156
155
|
if sql_type == "varchar" || sql_type == "character varying"
|
157
156
|
field_output(col, nil, limit || 40, col_identifier)
|
@@ -216,18 +215,14 @@ module HotGlue
|
|
216
215
|
@singular_class = args[0][:singular_class]
|
217
216
|
@singular = args[0][:singular]
|
218
217
|
@perc_width = args[0][:perc_width]
|
219
|
-
@
|
220
|
-
|
218
|
+
@col_identifier = @layout_strategy.column_classes_for_line_fields
|
219
|
+
|
221
220
|
@inline_list_labels = args[0][:inline_list_labels] || 'omit'
|
222
221
|
|
223
222
|
columns_count = columns.count + 1
|
224
223
|
perc_width = (@perc_width).floor
|
225
224
|
|
226
|
-
|
227
|
-
style_with_flex_basis = ""
|
228
|
-
else
|
229
|
-
style_with_flex_basis = " style='flex-basis: #{perc_width}%'"
|
230
|
-
end
|
225
|
+
style_with_flex_basis = @layout_strategy.style_with_flex_basis(perc_width)
|
231
226
|
|
232
227
|
result = columns.map{ |column|
|
233
228
|
"<div class='#{col_identifier}'#{style_with_flex_basis}>" +
|
@@ -238,14 +233,30 @@ module HotGlue
|
|
238
233
|
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
239
234
|
sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
|
240
235
|
|
241
|
-
field_output =
|
242
|
-
|
243
|
-
|
244
|
-
|
236
|
+
field_output =
|
237
|
+
case type
|
238
|
+
when :integer
|
239
|
+
# look for a belongs_to on this object
|
240
|
+
if col.ends_with?("_id")
|
241
|
+
assoc_name = col.to_s.gsub("_id","")
|
242
|
+
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
243
|
+
|
244
|
+
if assoc.nil?
|
245
|
+
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
246
|
+
puts exit_message
|
247
|
+
exit
|
248
|
+
# raise(HotGlue::Error,exit_message)
|
249
|
+
end
|
250
|
+
assoc_class_name = assoc.active_record.name
|
251
|
+
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
252
|
+
"<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
|
253
|
+
|
254
|
+
else
|
255
|
+
"<%= #{singular}.#{col}%>"
|
256
|
+
end
|
245
257
|
|
258
|
+
when :uuid
|
246
259
|
assoc_name = col.to_s.gsub("_id","")
|
247
|
-
|
248
|
-
|
249
260
|
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
250
261
|
|
251
262
|
if assoc.nil?
|
@@ -258,37 +269,34 @@ module HotGlue
|
|
258
269
|
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
259
270
|
"<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
|
260
271
|
|
261
|
-
|
272
|
+
when :float
|
273
|
+
width = (limit && limit < 40) ? limit : (40)
|
262
274
|
"<%= #{singular}.#{col}%>"
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
when :text
|
271
|
-
"<%= #{singular}.#{col} %>"
|
272
|
-
when :datetime
|
273
|
-
"<% unless #{singular}.#{col}.nil? %>
|
275
|
+
when :string
|
276
|
+
width = (limit && limit < 40) ? limit : (40)
|
277
|
+
"<%= #{singular}.#{col} %>"
|
278
|
+
when :text
|
279
|
+
"<%= #{singular}.#{col} %>"
|
280
|
+
when :datetime
|
281
|
+
"<% unless #{singular}.#{col}.nil? %>
|
274
282
|
<%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
|
275
283
|
<% else %>
|
276
284
|
<span class='alert-danger'>MISSING</span>
|
277
285
|
<% end %>"
|
278
|
-
|
279
|
-
|
286
|
+
when :date
|
287
|
+
"<% unless #{singular}.#{col}.nil? %>
|
280
288
|
<%= #{singular}.#{col} %>
|
281
289
|
<% else %>
|
282
290
|
<span class='alert-danger'>MISSING</span>
|
283
291
|
<% end %>"
|
284
|
-
|
285
|
-
|
292
|
+
when :time
|
293
|
+
"<% unless #{singular}.#{col}.nil? %>
|
286
294
|
<%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
|
287
295
|
<% else %>
|
288
296
|
<span class='alert-danger'>MISSING</span>
|
289
297
|
<% end %>"
|
290
|
-
|
291
|
-
|
298
|
+
when :boolean
|
299
|
+
"
|
292
300
|
<% if #{singular}.#{col}.nil? %>
|
293
301
|
<span class='alert-danger'>MISSING</span>
|
294
302
|
<% elsif #{singular}.#{col} %>
|
@@ -297,8 +305,9 @@ module HotGlue
|
|
297
305
|
NO
|
298
306
|
<% end %>
|
299
307
|
|
300
|
-
"
|
301
|
-
|
308
|
+
"
|
309
|
+
when :enum
|
310
|
+
enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
|
302
311
|
|
303
312
|
"
|
304
313
|
<% if #{singular}.#{col}.nil? %>
|
@@ -308,8 +317,7 @@ module HotGlue
|
|
308
317
|
<% end %>
|
309
318
|
|
310
319
|
"
|
311
|
-
|
312
|
-
|
320
|
+
end #end of switch
|
313
321
|
|
314
322
|
label = "<br/><label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
|
315
323
|
|
@@ -319,4 +327,4 @@ module HotGlue
|
|
319
327
|
}.join("\n")
|
320
328
|
end
|
321
329
|
end
|
322
|
-
end
|
330
|
+
end
|