hot-glue 0.5.18 → 0.5.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +25 -4
- data/config/hot_glue.yml +2 -2
- data/lib/generators/hot_glue/field_factory.rb +3 -1
- data/lib/generators/hot_glue/fields/association_field.rb +3 -1
- data/lib/generators/hot_glue/fields/attachment_field.rb +3 -1
- data/lib/generators/hot_glue/fields/boolean_field.rb +40 -7
- data/lib/generators/hot_glue/fields/field.rb +27 -1
- data/lib/generators/hot_glue/layout/builder.rb +9 -3
- data/lib/generators/hot_glue/layout_strategy/base.rb +3 -0
- data/lib/generators/hot_glue/layout_strategy/bootstrap.rb +12 -0
- data/lib/generators/hot_glue/markup_templates/erb.rb +5 -1
- data/lib/generators/hot_glue/scaffold_generator.rb +19 -1
- data/lib/hotglue/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86497d64d197f64d4df68804b0cfcb02f5541c64d98932cdb723e1b19b4aa76b
|
4
|
+
data.tar.gz: 7e6161cee21f3a4e5968d450cb44ade8fcb4b7c6e15d3c466ffa47527c979ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d0788389d37a0a477793bbce0a57c29141061d35e3d4bb26e56affa15ec446f4eba1e6b545c316118eba231c1c3e9d51d1c68dcc62dea2990cedd4dbcd59ca1
|
7
|
+
data.tar.gz: d2036061122d60696b6cc24bd3085aeee5525f531d950f40ea569e9f54d229a0cca6cdaf573f0da5a73aab3e3743857155d7b54ce83c47aa74e83fd74aa93731
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -672,9 +672,8 @@ here, even though `paid_at` is a datetime field, it will display as-if it is a b
|
|
672
672
|
label or the falsy label depending on if `paid_at` is or is not null in the database.
|
673
673
|
For all fields except booleans, this affects only the viewable output —
|
674
674
|
what you see on the list page and on the edit page for show-only fields.
|
675
|
-
For booleans, it affects those outputs as well as the normal
|
676
|
-
|
677
|
-
|
675
|
+
For booleans shown as radio buttons, it affects those outputs as well as the normal view output.
|
676
|
+
For booleans shown as checkboxes or switches, it affects only the view output as the truthy and falsy labels are not displays in editbale view.
|
678
677
|
|
679
678
|
You will need to separately specify them as show-only if you want them to be non-editable.
|
680
679
|
|
@@ -1299,9 +1298,31 @@ end
|
|
1299
1298
|
|
1300
1299
|
```
|
1301
1300
|
|
1302
|
-
|
1303
1301
|
# VERSION HISTORY
|
1304
1302
|
|
1303
|
+
#### 2023-09-02 - v0.5.19
|
1304
|
+
|
1305
|
+
Given a table generated with this schema:
|
1306
|
+
```
|
1307
|
+
rails generate model Thing abc:boolean dfg:boolean hij:boolean klm_at:datetime
|
1308
|
+
```
|
1309
|
+
|
1310
|
+
• You can now use new flag `--display-as` to determine how the booleans will be displayed: checkbox, radio, or switch
|
1311
|
+
|
1312
|
+
rails generate hot_glue:scaffold Thing --include=abc,dfg,hij,klm_at --god --modify='klm_at{yes|no}' --display-as='abc{checkbox},dfg{radio},hij{switch}'
|
1313
|
+
|
1314
|
+
You may specify a default `default_boolean_display` in `config/hot_glue.yml`, like so:
|
1315
|
+
:default_boolean_display: 'radio'
|
1316
|
+
|
1317
|
+
(The options are checkbox, radio, or switch.)
|
1318
|
+
If none is given and no default is specified, legacy display behavior will be used (radio buttons)
|
1319
|
+
|
1320
|
+
![Screenshot 2023-08-22 at 7 40 44 PM](https://github.com/hot-glue-for-rails/hot-glue/assets/59002/ba076cb0-fa40-4b68-a1a0-cab496670e00)
|
1321
|
+
|
1322
|
+
You still use the `--modify` flag to determine the truthy and falsy labels, which are also used as the truth and false when a boolean is displays as radio button, as shown in the `klm_at` field above. (switches and checkboxes simply display with the field label and do not use the truthy and falsy labels)
|
1323
|
+
|
1324
|
+
|
1325
|
+
|
1305
1326
|
#### 2023-09-01 - v0.5.18
|
1306
1327
|
- there three ways Hot Glue deals with Datetime fields:
|
1307
1328
|
-
|
data/config/hot_glue.yml
CHANGED
@@ -58,6 +58,8 @@ class FieldFactory
|
|
58
58
|
update_show_only: generator.update_show_only,
|
59
59
|
attachment_data: generator.attachments[name.to_sym],
|
60
60
|
sample_file_path: generator.sample_file_path,
|
61
|
-
modify: generator.modify[name.to_sym] || nil
|
61
|
+
modify: generator.modify[name.to_sym] || nil,
|
62
|
+
display_as: generator.display_as[name.to_sym] || nil,
|
63
|
+
default_boolean_display: generator.default_boolean_display)
|
62
64
|
end
|
63
65
|
end
|
@@ -5,7 +5,9 @@ class AssociationField < Field
|
|
5
5
|
|
6
6
|
attr_accessor :assoc_name, :assoc_class, :assoc
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(alt_lookups: , class_name: , default_boolean_display:, display_as: ,
|
9
|
+
name: , singular: ,
|
10
|
+
update_show_only: ,
|
9
11
|
hawk_keys: , auth: , sample_file_path:, ownership_field: ,
|
10
12
|
attachment_data: nil , layout_strategy: , form_placeholder_labels: nil,
|
11
13
|
form_labels_position:, modify: )
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class AttachmentField < Field
|
2
2
|
attr_accessor :attachment_data
|
3
|
-
def initialize(name:, class_name:, alt_lookups:,
|
3
|
+
def initialize(name:, class_name:, alt_lookups:, default_boolean_display: ,
|
4
|
+
display_as:,
|
5
|
+
singular:, update_show_only:, hawk_keys:, auth:,
|
4
6
|
sample_file_path: nil, attachment_data:, ownership_field:, layout_strategy: ,
|
5
7
|
form_placeholder_labels: , form_labels_position:, modify: )
|
6
8
|
super
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
class BooleanField < Field
|
2
3
|
def spec_setup_and_change_act(which_partial = nil)
|
3
4
|
" new_#{name} = 1 \n" +
|
@@ -15,15 +16,43 @@ class BooleanField < Field
|
|
15
16
|
def spec_list_view_assertion
|
16
17
|
["expect(page).to have_content(#{singular}#{1}.#{name} ? 'YES' : 'NO')"].join("\n ")
|
17
18
|
end
|
18
|
-
|
19
|
-
|
19
|
+
|
20
|
+
def label_for
|
21
|
+
"#{singular}_#{name}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def radio_button_display
|
25
|
+
" <%= f.radio_button(:#{name}, '0', checked: #{singular}.#{name} ? '' : 'checked', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
|
26
|
+
" <%= f.label(:#{name}, value: '#{modify_binary? && modify[:binary][:falsy] || 'No'}', for: '#{singular}_#{name}_0') %>\n" +
|
27
|
+
" <br /> <%= f.radio_button(:#{name}, '1', checked: #{singular}.#{name} ? 'checked' : '' , class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" +
|
28
|
+
" <%= f.label(:#{name}, value: '#{modify_binary? && modify[:binary][:truthy] || 'Yes'}', for: '#{singular}_#{name}_1') %>\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
def checkbox_display
|
32
|
+
"<%= f.check_box(:#{name}, class: '#{@layout_strategy.form_checkbox_input_class}', id: '#{singular}_#{name}', checked: #{singular}.#{name}) %>\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
def switch_display
|
36
|
+
"<%= f.check_box(:#{name}, class: '#{@layout_strategy.form_checkbox_input_class}', role: 'switch', id: '#{singular}_#{name}', checked: #{singular}.#{name}) %>\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def form_field_display
|
40
|
+
if display_boolean_as.nil?
|
41
|
+
byebug
|
42
|
+
end
|
43
|
+
"<div class='#{@layout_strategy.form_checkbox_wrapper_class} #{'form-switch' if display_boolean_as == 'switch'}'>\n" +
|
44
|
+
(if display_boolean_as == 'radio'
|
45
|
+
radio_button_display
|
46
|
+
elsif display_boolean_as == 'checkbox'
|
47
|
+
checkbox_display
|
48
|
+
elsif display_boolean_as == 'switch'
|
49
|
+
switch_display
|
50
|
+
end) + "</div> \n"
|
51
|
+
end
|
52
|
+
|
20
53
|
def form_field_output
|
21
54
|
(form_labels_position == 'before' ? " <br />" : "") +
|
22
|
-
|
23
|
-
" <%= f.label(:#{name}, value: '#{modify_binary? && modify[:binary][:falsy] || 'No'}', for: '#{singular}_#{name}_0') %>\n" +
|
24
|
-
" <br /> <%= f.radio_button(:#{name}, '1', checked: #{singular}.#{name} ? 'checked' : '') %>\n" +
|
25
|
-
" <%= f.label(:#{name}, value: '#{modify_binary? && modify[:binary][:truthy] || 'Yes'}', for: '#{singular}_#{name}_1') %>\n" +
|
26
|
-
(form_labels_position == 'after' ? " <br />" : "")
|
55
|
+
form_field_display + (form_labels_position == 'after' ? " <br />" : "")
|
27
56
|
end
|
28
57
|
|
29
58
|
def line_field_output
|
@@ -45,4 +74,8 @@ class BooleanField < Field
|
|
45
74
|
<% end %>"
|
46
75
|
end
|
47
76
|
end
|
77
|
+
|
78
|
+
def label_class
|
79
|
+
super + " form-check-label"
|
80
|
+
end
|
48
81
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Field
|
2
2
|
attr_accessor :assoc_model, :assoc_name, :assoc_class, :associations, :alt_lookups, :auth,
|
3
|
-
:assoc_label, :class_name,
|
3
|
+
:assoc_label, :class_name, :default_boolean_display, :display_as, :form_placeholder_labels, :form_labels_position,
|
4
4
|
:hawk_keys, :layout_strategy, :limit, :modify, :name, :object, :sample_file_path,
|
5
5
|
:singular_class, :singular, :sql_type, :ownership_field,
|
6
6
|
:update_show_only
|
@@ -10,6 +10,8 @@ class Field
|
|
10
10
|
alt_lookups: ,
|
11
11
|
attachment_data: nil,
|
12
12
|
class_name: ,
|
13
|
+
default_boolean_display: ,
|
14
|
+
display_as: ,
|
13
15
|
form_labels_position:,
|
14
16
|
form_placeholder_labels: ,
|
15
17
|
hawk_keys: nil,
|
@@ -34,6 +36,9 @@ class Field
|
|
34
36
|
@ownership_field = ownership_field
|
35
37
|
@form_labels_position = form_labels_position
|
36
38
|
@modify = modify
|
39
|
+
@display_as = display_as
|
40
|
+
|
41
|
+
@default_boolean_display = default_boolean_display
|
37
42
|
|
38
43
|
# TODO: remove knowledge of subclasses from Field
|
39
44
|
unless self.class == AttachmentField
|
@@ -132,4 +137,25 @@ class Field
|
|
132
137
|
def modify_binary? # safe
|
133
138
|
!!(modify && modify[:binary])
|
134
139
|
end
|
140
|
+
|
141
|
+
def display_boolean_as
|
142
|
+
|
143
|
+
if ! @default_boolean_display
|
144
|
+
@default_boolean_display = "radio"
|
145
|
+
end
|
146
|
+
|
147
|
+
if display_as
|
148
|
+
return display_as[:boolean] || "radio"
|
149
|
+
else
|
150
|
+
return @default_boolean_display
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def label_class
|
155
|
+
"text-muted small form-text"
|
156
|
+
end
|
157
|
+
|
158
|
+
def label_for
|
159
|
+
|
160
|
+
end
|
135
161
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module HotGlue
|
4
4
|
module Layout
|
5
5
|
class Builder
|
6
|
+
include DefaultConfigLoader
|
6
7
|
attr_reader :include_setting,
|
7
8
|
:downnest_object,
|
8
9
|
:buttons_width, :columns,
|
@@ -11,12 +12,13 @@ module HotGlue
|
|
11
12
|
|
12
13
|
def initialize(generator: ,
|
13
14
|
include_setting: ,
|
14
|
-
buttons_width:
|
15
|
+
buttons_width: )
|
15
16
|
|
16
17
|
|
17
18
|
@generator = generator
|
18
19
|
|
19
20
|
@modify = generator.modify
|
21
|
+
@display_as = generator.display_as
|
20
22
|
@columns = generator.columns
|
21
23
|
@smart_layout = generator.smart_layout
|
22
24
|
@stacked_downnesting = generator.stacked_downnesting || false
|
@@ -27,8 +29,11 @@ module HotGlue
|
|
27
29
|
|
28
30
|
@no_buttons = @buttons_width == 0
|
29
31
|
@specified_grouping_mode = include_setting.include?(":")
|
30
|
-
@bootstrap_column_width = generator.bootstrap_column_width
|
32
|
+
@bootstrap_column_width = generator.bootstrap_column_width.to_i
|
31
33
|
@big_edit = generator.big_edit
|
34
|
+
|
35
|
+
@default_boolean_display = get_default_from_config(key: :default_boolean_display)
|
36
|
+
|
32
37
|
end
|
33
38
|
|
34
39
|
def construct
|
@@ -41,7 +46,8 @@ module HotGlue
|
|
41
46
|
|
42
47
|
},
|
43
48
|
buttons: { size: @buttons_width},
|
44
|
-
modify: @modify
|
49
|
+
modify: @modify,
|
50
|
+
display_as: @display_as
|
45
51
|
}
|
46
52
|
|
47
53
|
# downnest_object.each do |child, size|
|
@@ -30,5 +30,8 @@ module LayoutStrategy
|
|
30
30
|
def page_begin; '<div> '; end
|
31
31
|
def page_end ; '</div> '; end
|
32
32
|
def style_with_flex_basis(x); "" ; end
|
33
|
+
def form_checkbox_input_class; ""; end
|
34
|
+
def form_checkbox_label_class; ""; end
|
35
|
+
def form_checkbox_wrapper_class; ""; end
|
33
36
|
end
|
34
37
|
end
|
@@ -56,4 +56,16 @@ class LayoutStrategy::Bootstrap < LayoutStrategy::Base
|
|
56
56
|
def page_end
|
57
57
|
'</div> </div>'
|
58
58
|
end
|
59
|
+
|
60
|
+
def form_checkbox_input_class
|
61
|
+
"form-check-input"
|
62
|
+
end
|
63
|
+
|
64
|
+
def form_checkbox_wrapper_class
|
65
|
+
"form-check"
|
66
|
+
end
|
67
|
+
|
68
|
+
def form_checkbox_label_class
|
69
|
+
"form-check-label"
|
70
|
+
end
|
59
71
|
end
|
@@ -87,7 +87,11 @@ module HotGlue
|
|
87
87
|
|
88
88
|
field_error_name = columns_map[col].field_error_name
|
89
89
|
|
90
|
-
|
90
|
+
|
91
|
+
label_class = columns_map[col].label_class
|
92
|
+
label_for = columns_map[col].label_for
|
93
|
+
|
94
|
+
the_label = "\n<label class='#{label_class}' for='#{label_for}'>#{col.to_s.humanize}</label>"
|
91
95
|
show_only_open = ""
|
92
96
|
show_only_close = ""
|
93
97
|
|
@@ -17,7 +17,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
17
17
|
|
18
18
|
source_root File.expand_path('templates', __dir__)
|
19
19
|
attr_accessor :alt_lookups, :attachments, :auth, :big_edit, :button_icons, :bootstrap_column_width, :columns,
|
20
|
-
:
|
20
|
+
:default_boolean_display,
|
21
|
+
:display_as, :downnest_children, :downnest_object, :hawk_keys, :layout_object, :modify,
|
21
22
|
:nest_with, :path, :plural, :sample_file_path, :show_only_data, :singular,
|
22
23
|
:singular_class, :smart_layout, :stacked_downnesting, :update_show_only, :ownership_field,
|
23
24
|
:layout_strategy, :form_placeholder_labels, :form_labels_position
|
@@ -79,6 +80,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
79
80
|
class_option :bootstrap_column_width, default: nil # must be nil to detect if user has not passed
|
80
81
|
class_option :button_icons, default: nil
|
81
82
|
class_option :modify, default: {}
|
83
|
+
class_option :display_as, default: {}
|
82
84
|
|
83
85
|
def initialize(*meta_args)
|
84
86
|
super
|
@@ -118,6 +120,9 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
118
120
|
@bootstrap_column_width ||= options['bootstrap_column_width'] ||
|
119
121
|
get_default_from_config(key: :bootstrap_column_width) || 2
|
120
122
|
|
123
|
+
|
124
|
+
|
125
|
+
@default_boolean_display = get_default_from_config(key: :default_boolean_display)
|
121
126
|
if options['layout']
|
122
127
|
layout = options['layout']
|
123
128
|
else
|
@@ -211,6 +216,19 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
|
211
216
|
end
|
212
217
|
end
|
213
218
|
end
|
219
|
+
|
220
|
+
@display_as = {}
|
221
|
+
if !options['display_as'].empty?
|
222
|
+
display_input = options['display_as'].split(",")
|
223
|
+
|
224
|
+
display_input.each do |setting|
|
225
|
+
setting =~ /(.*){(.*)}/
|
226
|
+
key, lookup_as = $1, $2
|
227
|
+
@display_as[key.to_sym] = {boolean: $2}
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
|
214
232
|
@update_show_only = []
|
215
233
|
if !options['update_show_only'].empty?
|
216
234
|
@update_show_only += options['update_show_only'].split(",").collect(&:to_sym)
|
data/lib/hotglue/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hot-glue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.19.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|